Skip to content

Commit

Permalink
initial removal of M2M tables
Browse files Browse the repository at this point in the history
  • Loading branch information
whitej6 committed Sep 18, 2023
1 parent 40b3e34 commit aa8e4db
Show file tree
Hide file tree
Showing 11 changed files with 593 additions and 458 deletions.
220 changes: 0 additions & 220 deletions nautobot_firewall_models/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
from nautobot_firewall_models import models


# TODO: This is a complete hack, M2M fields are not being picked up correctly.
class ThroughNautobotHyperlinkedRelatedField(NautobotHyperlinkedRelatedField):
"""Overload to account for nested through fields."""

def to_representation(self, value):
"""Convert URL representation to a brief nested representation."""
return {
"id": value.pk,
"object_type": value._meta.label_lower,
"url": super().to_representation(value)["url"],
"composite_key": value.composite_key,
}


class IPRangeSerializer(NautobotModelSerializer):
"""IPRange Serializer."""

Expand Down Expand Up @@ -59,10 +45,6 @@ class Meta:
class AddressObjectGroupSerializer(NautobotModelSerializer):
"""AddressObjectGroup Serializer."""

address_objects = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(), many=True, required=False
)

class Meta:
"""Meta attributes."""

Expand All @@ -83,12 +65,6 @@ class Meta:
class ApplicationObjectGroupSerializer(NautobotModelSerializer):
"""ApplicationObjectGroup Serializer."""

application_objects = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ApplicationObject.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -109,12 +85,6 @@ class Meta:
class ServiceObjectGroupSerializer(NautobotModelSerializer):
"""ServiceObjectGroup Serializer."""

service_objects = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -135,12 +105,6 @@ class Meta:
class UserObjectGroupSerializer(NautobotModelSerializer):
"""UserObjectGroup Serializer."""

user_objects = ThroughNautobotHyperlinkedRelatedField(
queryset=models.UserObject.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -163,70 +127,6 @@ class PolicyRuleSerializer(NautobotModelSerializer):

index = serializers.IntegerField(required=False, default=None)

# source
source_users = ThroughNautobotHyperlinkedRelatedField(
queryset=models.UserObject.objects.all(),
many=True,
required=False,
)
source_user_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.UserObjectGroup.objects.all(),
many=True,
required=False,
)
source_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
source_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
source_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
source_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

# destination
applications = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ApplicationObject.objects.all(),
many=True,
required=False,
)
application_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ApplicationObjectGroup.objects.all(),
many=True,
required=False,
)
destination_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
destination_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
destination_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
destination_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -237,22 +137,6 @@ class Meta:
class PolicySerializer(NautobotModelSerializer):
"""Policy Serializer."""

policy_rules = ThroughNautobotHyperlinkedRelatedField(
queryset=models.PolicyRule.objects.all(),
many=True,
required=False,
)
assigned_devices = ThroughNautobotHyperlinkedRelatedField(
queryset=Device.objects.all(),
many=True,
required=False,
)
assigned_dynamic_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=DynamicGroup.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand Down Expand Up @@ -324,94 +208,6 @@ def validate(self, data):
class NATPolicyRuleSerializer(NautobotModelSerializer):
"""PolicyRule Serializer."""

# original source
original_source_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
original_source_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
original_source_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
original_source_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

# translated source
translated_source_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
translated_source_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
translated_source_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
translated_source_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

# original destination
original_destination_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
original_destination_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
original_destination_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
original_destination_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

# translated destination
translated_destination_addresses = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObject.objects.all(),
many=True,
required=False,
)
translated_destination_address_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.AddressObjectGroup.objects.all(),
many=True,
required=False,
)
translated_destination_services = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObject.objects.all(),
many=True,
required=False,
)
translated_destination_service_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=models.ServiceObjectGroup.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -422,22 +218,6 @@ class Meta:
class NATPolicySerializer(NautobotModelSerializer):
"""NATPolicy Serializer."""

nat_policy_rules = ThroughNautobotHyperlinkedRelatedField(
queryset=models.NATPolicyRule.objects.all(),
many=True,
required=False,
)
assigned_devices = ThroughNautobotHyperlinkedRelatedField(
queryset=Device.objects.all(),
many=True,
required=False,
)
assigned_dynamic_groups = ThroughNautobotHyperlinkedRelatedField(
queryset=DynamicGroup.objects.all(),
many=True,
required=False,
)

class Meta:
"""Meta attributes."""

Expand Down
Loading

0 comments on commit aa8e4db

Please sign in to comment.