from rest_framework import serializers import machines.models as machines import users.models as users from api.serializers import NamespacedHMSerializer from rest_framework.serializers import Serializer class InterfaceSerializer(Serializer): mac_address = serializers.CharField() ipv4 = serializers.CharField(source="ipv4.ipv4") active = serializers.BooleanField(source="is_active") user_pk = serializers.CharField(source="machine.user.pk") # machine_type_pk = serializers.CharField(source="machine_type.pk") # switch_stack = serializers.CharField(source="machine.switch.stack") machine_short_name = serializers.CharField(source="machine.short_name") is_ban = serializers.BooleanField(source="machine.user.is_ban") vlan_id = serializers.IntegerField( source="machine_type.ip_type.vlan.vlan_id") class NasSerializer(Serializer): port_access_mode = serializers.CharField() autocapture_mac = serializers.BooleanField() class UserSerializer(Serializer): access = serializers.BooleanField(source="has_access") pk = serializers.CharField() pwd_ntlm = serializers.CharField() state = serializers.CharField() email_state = serializers.IntegerField() is_ban = serializers.BooleanField() is_connected = serializers.BooleanField() is_whitelisted = serializers.BooleanField() class PortSerializer(Serializer): state = serializers.BooleanField() room = serializers.CharField() class VlanSerializer(Serializer): vlan_id = serializers.IntegerField() class PortProfileSerializer(Serializer): vlan_untagged = VlanSerializer() radius_type = serializers.CharField() class SwitchSerializer(Serializer): name = serializers.CharField(source="short_name") ipv4 = serializers.CharField() class RadiusAttributeSerializer(Serializer): attribute = serializers.CharField() value = serializers.CharField() class RadiusOptionSerializer(Serializer): radius_general_policy = serializers.CharField() unknown_machine = serializers.CharField() unknown_machine_vlan = VlanSerializer() unknown_machine_attributes = RadiusAttributeSerializer(many=True) unknown_port = serializers.CharField() unknown_port_vlan = VlanSerializer() unknown_port_attributes = RadiusAttributeSerializer(many=True) unknown_room = serializers.CharField() unknown_room_vlan = VlanSerializer() unknown_room_attributes = RadiusAttributeSerializer(many=True) non_member = serializers.CharField() non_member_vlan = VlanSerializer() non_member_attributes = RadiusAttributeSerializer(many=True) banned = serializers.CharField() banned_vlan = VlanSerializer() banned_attributes = RadiusAttributeSerializer(many=True) vlan_decision_ok = VlanSerializer() ok_attributes = RadiusAttributeSerializer(many=True) class AuthorizeResponseSerializer(Serializer): nas = NasSerializer(read_only=True) user = UserSerializer(read_only=True) user_interface = InterfaceSerializer(read_only=True) class PostAuthResponseSerializer(Serializer): nas = NasSerializer(read_only=True) room_users = UserSerializer(many=True) port = PortSerializer() port_profile = PortProfileSerializer(partial=True) switch = SwitchSerializer() user_interface = InterfaceSerializer() radius_option = RadiusOptionSerializer() EMAIL_STATE_UNVERIFIED = serializers.IntegerField() RADIUS_OPTION_REJECT = serializers.CharField()