Skip to content

Commit

Permalink
clean up fields
Browse files Browse the repository at this point in the history
  • Loading branch information
whitej6 committed Sep 28, 2023
1 parent 9a8381c commit 44b9fe0
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 29 deletions.
111 changes: 111 additions & 0 deletions nautobot_firewall_models/migrations/0020_field_cleanups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Generated by Django 3.2.21 on 2023-09-28 17:07

from django.db import migrations, models
import nautobot_firewall_models.validators


class Migration(migrations.Migration):
dependencies = [
("nautobot_firewall_models", "0019_resolve_issues_through_tables_part3"),
]

operations = [
migrations.AlterField(
model_name="applicationobject",
name="category",
field=models.CharField(blank=True, default="", max_length=48),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobject",
name="default_ip_protocol",
field=models.CharField(blank=True, default="", max_length=48),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobject",
name="default_type",
field=models.CharField(blank=True, default="", max_length=48),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobject",
name="description",
field=models.CharField(blank=True, default="", max_length=200),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobject",
name="subcategory",
field=models.CharField(blank=True, default="", max_length=48),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobject",
name="technology",
field=models.CharField(blank=True, default="", max_length=48),
preserve_default=False,
),
migrations.AlterField(
model_name="applicationobjectgroup",
name="description",
field=models.CharField(blank=True, default="", max_length=200),
preserve_default=False,
),
migrations.AlterField(
model_name="capircapolicy",
name="cfg",
field=models.TextField(blank=True, default=""),
preserve_default=False,
),
migrations.AlterField(
model_name="capircapolicy",
name="net",
field=models.TextField(blank=True, default=""),
preserve_default=False,
),
migrations.AlterField(
model_name="capircapolicy",
name="pol",
field=models.TextField(blank=True, default=""),
preserve_default=False,
),
migrations.AlterField(
model_name="capircapolicy",
name="svc",
field=models.TextField(blank=True, default=""),
preserve_default=False,
),
migrations.AlterField(
model_name="natpolicyrule",
name="description",
field=models.CharField(blank=True, default="", max_length=200),
preserve_default=False,
),
migrations.AlterField(
model_name="natpolicyrule",
name="request_id",
field=models.CharField(blank=True, default="", max_length=100),
preserve_default=False,
),
migrations.AlterField(
model_name="policyrule",
name="description",
field=models.CharField(blank=True, default="", max_length=200),
preserve_default=False,
),
migrations.AlterField(
model_name="policyrule",
name="request_id",
field=models.CharField(blank=True, default="", max_length=100),
preserve_default=False,
),
migrations.AlterField(
model_name="serviceobject",
name="port",
field=models.CharField(
blank=True, default="", max_length=20, validators=[nautobot_firewall_models.validators.validate_port]
),
preserve_default=False,
),
]
8 changes: 4 additions & 4 deletions nautobot_firewall_models/models/capirca_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class CapircaPolicy(PrimaryModel):
device = models.OneToOneField(
to="dcim.Device", blank=True, null=True, on_delete=models.CASCADE, related_name="capirca_policy"
)
pol = models.TextField(blank=True, null=True)
net = models.TextField(blank=True, null=True)
svc = models.TextField(blank=True, null=True)
cfg = models.TextField(blank=True, null=True)
pol = models.TextField(blank=True)
net = models.TextField(blank=True)
svc = models.TextField(blank=True)
cfg = models.TextField(blank=True)

csv_headers = ["device"]

Expand Down
4 changes: 2 additions & 2 deletions nautobot_firewall_models/models/nat_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class NATPolicyRule(PrimaryModel):
related_name="%(app_label)s_%(class)s_related", # e.g. dcim_device_related
default=get_default_status,
)
request_id = models.CharField(max_length=100, null=True, blank=True)
description = models.CharField(max_length=200, null=True, blank=True)
request_id = models.CharField(max_length=100, blank=True)
description = models.CharField(max_length=200, blank=True)
index = models.PositiveSmallIntegerField(null=True, blank=True)

# Data that can not undergo a translation
Expand Down
4 changes: 2 additions & 2 deletions nautobot_firewall_models/models/security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class PolicyRule(PrimaryModel):
application_groups = models.ManyToManyField(
blank=True, to="nautobot_firewall_models.ApplicationObjectGroup", related_name="policy_rules"
)
request_id = models.CharField(max_length=100, null=True, blank=True)
description = models.CharField(max_length=200, null=True, blank=True)
request_id = models.CharField(max_length=100, blank=True)
description = models.CharField(max_length=200, blank=True)
index = models.PositiveSmallIntegerField(null=True, blank=True)

clone_fields = [
Expand Down
16 changes: 6 additions & 10 deletions nautobot_firewall_models/models/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ class ApplicationObject(PrimaryModel):
description = models.CharField(
max_length=200,
blank=True,
null=True,
)
category = models.CharField(max_length=48, blank=True, null=True, help_text="Category of application.")
subcategory = models.CharField(max_length=48, blank=True, null=True, help_text="Sub-category of application.")
technology = models.CharField(max_length=48, blank=True, null=True, help_text="Type of application technology.")
category = models.CharField(max_length=48, blank=True, help_text="Category of application.")
subcategory = models.CharField(max_length=48, blank=True, help_text="Sub-category of application.")
technology = models.CharField(max_length=48, blank=True, help_text="Type of application technology.")
risk = models.PositiveIntegerField(blank=True, null=True, help_text="Assessed risk of the application.")
default_type = models.CharField(
max_length=48, blank=True, null=True, help_text="Default type, i.e. port or app-id."
)
default_type = models.CharField(max_length=48, blank=True, help_text="Default type, i.e. port or app-id.")
name = models.CharField(max_length=100, unique=True, help_text="Name descriptor for an application object type.")
default_ip_protocol = models.CharField(
max_length=48, blank=True, null=True, help_text="Name descriptor for an application object type."
max_length=48, blank=True, help_text="Name descriptor for an application object type."
)
status = StatusField(
on_delete=models.PROTECT,
Expand Down Expand Up @@ -89,7 +86,7 @@ def application(self): # pylint: disable=inconsistent-return-statements
class ApplicationObjectGroup(PrimaryModel):
"""Groups together ApplicationObjects to better mimic grouping sets of application objects that have a some commonality."""

description = models.CharField(max_length=200, blank=True, null=True)
description = models.CharField(max_length=200, blank=True)
name = models.CharField(max_length=100, unique=True, help_text="Name descriptor for a group application objects.")
application_objects = models.ManyToManyField(
to="nautobot_firewall_models.ApplicationObject",
Expand Down Expand Up @@ -132,7 +129,6 @@ class ServiceObject(PrimaryModel):
)
name = models.CharField(max_length=100, help_text="Name of the service (e.g. HTTP)")
port = models.CharField(
null=True,
blank=True,
validators=[validators.validate_port],
max_length=20,
Expand Down
10 changes: 5 additions & 5 deletions nautobot_firewall_models/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def assign_policies(): # pylint: disable=too-many-locals
pol1, pol2, pol3 = create_policy()
# Mapping policies to devices
loc_type, _ = LocationType.objects.get_or_create(name="site")
site1, _ = Location.objects.get_or_create(name="DFW", location_type=loc_type, status=status)
site2, _ = Location.objects.get_or_create(name="HOU", location_type=loc_type, status=status)
site1, _ = Location.objects.get_or_create(name="DFW02", location_type=loc_type, status=status)
site2, _ = Location.objects.get_or_create(name="HOU02", location_type=loc_type, status=status)
jun_manufacturer, _ = Manufacturer.objects.get_or_create(name="Juniper")
jun_platform, _ = Platform.objects.get_or_create(name="Juniper", network_driver="srx")
jun_dev_type, _ = DeviceType.objects.get_or_create(manufacturer=jun_manufacturer, model="SRX300")
Expand All @@ -358,15 +358,15 @@ def assign_policies(): # pylint: disable=too-many-locals
dev_role, _ = Role.objects.get_or_create(name="WAN")
dev_role.content_types.add(ContentType.objects.get_for_model(Device))
dev1, _ = Device.objects.get_or_create(
name="DFW-WAN00",
name="DFW02-WAN00",
role=dev_role,
device_type=jun_dev_type,
location=site1,
status=status,
platform=jun_platform,
)
dev2, _ = Device.objects.get_or_create(
name="HOU-WAN00",
name="HOU02-WAN00",
role=dev_role,
device_type=palo_dev_type,
location=site2,
Expand All @@ -376,7 +376,7 @@ def assign_policies(): # pylint: disable=too-many-locals
dynamic_group, _ = DynamicGroup.objects.get_or_create(
name="North Texas", content_type=ContentType.objects.get_for_model(Device)
)
dynamic_group.filter = {"location": ["DFW"]}
dynamic_group.filter = {"location": ["DFW02"]}
dynamic_group.validated_save()
PolicyDeviceM2M.objects.get_or_create(policy=pol1, device=dev1, weight=150)
PolicyDeviceM2M.objects.get_or_create(policy=pol2, device=dev1, weight=200)
Expand Down
6 changes: 3 additions & 3 deletions nautobot_firewall_models/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def test_service_port_empty(self):

self.assertEqual(svc.port, "")

def test_service_port_null(self):
"""Test port null."""
def test_service_port_omitted_equals_blank(self):
"""Test port blank."""
svc = ServiceObject.objects.create(name="HTTP", ip_protocol="TCP", status=Status.objects.get(name="Active"))

self.assertEqual(svc.port, None)
self.assertEqual(svc.port, "")

def test_service_port_range_invalid(self):
"""Test port range."""
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nautobot-firewall-models"
version = "2.0.0rc1"
version = "2.0.0rc2"
description = "Nautobot plugin to model firewall objects."
authors = ["Network to Code, LLC <[email protected]>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -97,8 +97,7 @@ min-similarity-lines = 6
disable = """,
line-too-long,
too-few-public-methods,
too-many-ancestors,
nb-string-field-blank-null
too-many-ancestors
"""

[tool.pylint.miscellaneous]
Expand Down

0 comments on commit 44b9fe0

Please sign in to comment.