Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d3327f
Bump pypa/gh-action-pypi-publish from 1.8.14 to 1.9.0
dependabot[bot] Jun 17, 2024
c214bcb
Merge pull request #204 from netbox-community/dependabot/github_actio…
cruse1977 Aug 27, 2024
4d91c8c
Bump pypa/gh-action-pypi-publish from 1.9.0 to 1.10.0
dependabot[bot] Sep 2, 2024
1f8f1bc
Bump github/super-linter from 6 to 7
dependabot[bot] Sep 2, 2024
d200a1d
Merge pull request #205 from netbox-community/dependabot/github_actio…
cruse1977 Sep 9, 2024
e027368
Merge pull request #206 from netbox-community/dependabot/github_actio…
cruse1977 Sep 9, 2024
38e8f98
Update README.md
cruse1977 Sep 9, 2024
ebc4a8a
Bump pypa/gh-action-pypi-publish from 1.10.0 to 1.10.1
dependabot[bot] Sep 9, 2024
79b7756
Closes #212 and Fixes #210
cruse1977 Sep 19, 2024
522b2b3
Merge pull request #213 from netbox-community/bug/212-graphql
cruse1977 Sep 19, 2024
a2604d8
Merge branch 'dev' into dependabot/github_actions/pypa/gh-action-pypi…
cruse1977 Sep 19, 2024
be53a66
Merge pull request #209 from netbox-community/dependabot/github_actio…
cruse1977 Sep 19, 2024
25c8eeb
Update __init__.py min, max versions
cruse1977 Sep 19, 2024
7c27db6
Update Docker to v4.1
cruse1977 Sep 19, 2024
e157c8b
Bump Python version in Docker
cruse1977 Sep 19, 2024
87fcb93
Change Serializers to nested
cruse1977 Sep 19, 2024
4af0917
Filterset fixes
cruse1977 Sep 19, 2024
f950858
move filtersets to models not meta
cruse1977 Sep 19, 2024
d2f8335
Bump pypa/gh-action-pypi-publish from 1.10.1 to 1.10.2
dependabot[bot] Sep 23, 2024
4fd0cfe
Merge pull request #215 from netbox-community/dependabot/github_actio…
cruse1977 Sep 23, 2024
359299c
Bump pypa/gh-action-pypi-publish from 1.10.2 to 1.10.3
dependabot[bot] Oct 7, 2024
f68baf4
Merge branch 'dev' into feat/netbox-4-1
cruse1977 Oct 7, 2024
026c591
Merge pull request #216 from netbox-community/dependabot/github_actio…
cruse1977 Oct 10, 2024
02f428a
bump version to 1.7.0
cruse1977 Oct 10, 2024
e262ba8
Merge pull request #214 from netbox-community/feat/netbox-4-1
cruse1977 Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter/slim@v6
uses: github/super-linter/slim@v7
env:
DEFAULT_BRANCH: dev
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450
uses: pypa/gh-action-pypi-publish@f7600683efdcb7656dec5b29656edb7bc586e597
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG NETBOX_VARIANT=v4.0
ARG NETBOX_VARIANT=v4.1

FROM netboxcommunity/netbox:${NETBOX_VARIANT}

RUN mkdir -pv /plugins/netbox-acls
COPY . /plugins/netbox-acls

RUN /opt/netbox/venv/bin/python3 /plugins/netbox-acls/setup.py develop && \
cp -rf /plugins/netbox-acls/netbox_acls/ /opt/netbox/venv/lib/python3.11/site-packages/netbox_acls
cp -rf /plugins/netbox-acls/netbox_acls/ /opt/netbox/venv/lib/python3.12/site-packages/netbox_acls
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ See the [CONTRIBUTING](CONTRIBUTING.md) for more information.

Each Plugin Version listed below has been tested with its corresponding NetBox Version.

| NetBox Version | Plugin Version |
|:--------------:|:--------------:|
| >= 4.0.2 | 1.6.1 |
| 3.7 | 1.5.0 |
| 3.6 | 1.4.0 |
| 3.5 | 1.3.0 |
| 3.4 | 1.2.2 |
| 3.3 | 1.1.0 |
| 3.2 | 1.0.1 |
| NetBox Version | Plugin Version |
|:-------------------:|:--------------:|
| 4.1.x | 1.7.0 |
| >= 4.0.2 < 4.1.0 | 1.6.1 |
| 3.7.x | 1.5.0 |
| 3.6.x | 1.4.0 |
| 3.5.x | 1.3.0 |
| 3.4.x | 1.2.2 |
| 3.3.x | 1.1.0 |
| 3.2.x | 1.0.1 |

## Installing

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: '3.4'

services:
netbox:
Expand Down
4 changes: 2 additions & 2 deletions netbox_acls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class NetBoxACLsConfig(PluginConfig):
version = __version__
description = "Manage simple ACLs in NetBox"
base_url = "access-lists"
min_version = "4.0.2"
max_version = "4.0.99"
min_version = "4.1.0"
max_version = "4.1.99"


config = NetBoxACLsConfig
20 changes: 10 additions & 10 deletions netbox_acls/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

from django.contrib.contenttypes.models import ContentType
from drf_spectacular.utils import extend_schema_field
from ipam.api.serializers import NestedPrefixSerializer
from ipam.api.serializers import PrefixSerializer
from netbox.api.fields import ContentTypeField
from netbox.api.serializers import NetBoxModelSerializer
from netbox.constants import NESTED_SERIALIZER_PREFIX
from rest_framework import serializers
from utilities.api import get_serializer_for_model

Expand Down Expand Up @@ -81,10 +80,9 @@ class Meta:
def get_assigned_object(self, obj):
serializer = get_serializer_for_model(
obj.assigned_object,
prefix=NESTED_SERIALIZER_PREFIX,
)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, context=context).data
return serializer(obj.assigned_object, nested=True, context=context).data

def validate(self, data):
"""
Expand Down Expand Up @@ -145,11 +143,10 @@ class Meta:
@extend_schema_field(serializers.DictField())
def get_assigned_object(self, obj):
serializer = get_serializer_for_model(
obj.assigned_object,
prefix=NESTED_SERIALIZER_PREFIX,
obj.assigned_object
)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, context=context).data
return serializer(obj.assigned_object, nested=True, context=context).data

def validate(self, data):
"""
Expand Down Expand Up @@ -187,10 +184,11 @@ class ACLStandardRuleSerializer(NetBoxModelSerializer):
view_name="plugins-api:netbox_acls-api:aclstandardrule-detail",
)
access_list = NestedAccessListSerializer()
source_prefix = NestedPrefixSerializer(
source_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)

class Meta:
Expand Down Expand Up @@ -251,15 +249,17 @@ class ACLExtendedRuleSerializer(NetBoxModelSerializer):
view_name="plugins-api:netbox_acls-api:aclextendedrule-detail",
)
access_list = NestedAccessListSerializer()
source_prefix = NestedPrefixSerializer(
source_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)
destination_prefix = NestedPrefixSerializer(
destination_prefix = PrefixSerializer(
required=False,
allow_null=True,
default=None,
nested=True
)

class Meta:
Expand Down
40 changes: 10 additions & 30 deletions netbox_acls/forms/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Defines each django model's GUI filter/search options.
"""

from django.utils.translation import gettext_lazy as _
from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis
from django import forms
from django.utils.translation import gettext as _
from ipam.models import Prefix
from netbox.forms import NetBoxModelFilterSetForm
from utilities.forms.rendering import FieldSet
from utilities.forms.fields import (
DynamicModelChoiceField,
DynamicModelMultipleChoiceField,
Expand Down Expand Up @@ -90,22 +91,11 @@ class AccessListFilterForm(NetBoxModelFilterSetForm):
tag = TagFilterField(model)

fieldsets = (
(None, ("q", "tag")),
(
"Host Details",
(
"region",
"site_group",
"site",
"device_id",
"virtual_chassis_id",
"virtual_machine_id",
),
),
("ACL Details", ("type", "default_action")),
FieldSet("region", "site_group", "site", "device_id", "virtual_chassis_id", "virtual_machine_id", name=_("Host Details")),
FieldSet("type", "default_action", name=_('ACL Details')),
FieldSet("q", "tag",name=None)
)


class ACLInterfaceAssignmentFilterForm(NetBoxModelFilterSetForm):
"""
GUI filter form to search the django AccessList model.
Expand Down Expand Up @@ -195,12 +185,11 @@ class ACLStandardRuleFilterForm(NetBoxModelFilterSetForm):
choices=add_blank_choice(ACLRuleActionChoices),
required=False,
)

fieldsets = (
(None, ("q", "tag")),
("Rule Details", ("access_list", "action", "source_prefix")),
FieldSet("access_list", "action", "source_prefix", name=_('Rule Details')),
FieldSet("q", "tag",name=None)
)


class ACLExtendedRuleFilterForm(NetBoxModelFilterSetForm):
"""
GUI filter form to search the django ACLExtendedRule model.
Expand Down Expand Up @@ -235,15 +224,6 @@ class ACLExtendedRuleFilterForm(NetBoxModelFilterSetForm):
)

fieldsets = (
(None, ("q", "tag")),
(
"Rule Details",
(
"access_list",
"action",
"source_prefix",
"desintation_prefix",
"protocol",
),
),
FieldSet("access_list", "action", "source_prefix", "desintation_prefix", "protocol", name=_('Rule Details')),
FieldSet("q", "tag",name=None)
)
44 changes: 24 additions & 20 deletions netbox_acls/forms/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Defines each django model's GUI form to add or edit objects for each django model.
"""

from django.utils.translation import gettext_lazy as _
from dcim.models import Device, Interface, Region, Site, SiteGroup, VirtualChassis
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.utils.safestring import mark_safe
from ipam.models import Prefix
from netbox.forms import NetBoxModelForm
from utilities.forms.rendering import FieldSet
from utilities.forms.fields import CommentField, DynamicModelChoiceField
from virtualization.models import (
Cluster,
Expand Down Expand Up @@ -118,7 +119,12 @@ class AccessListForm(NetBoxModelForm):
)

comments = CommentField()

fieldsets = (
FieldSet('region', 'site_group', 'site', 'virtual_machine', 'virtual_chassis', 'device', name=_('Assignment')),
FieldSet('name', 'type', 'default_action', name=_('Access List')),
FieldSet('comments', 'tags', name=_('')),
)

class Meta:
model = AccessList
fields = (
Expand All @@ -134,6 +140,7 @@ class Meta:
"comments",
"tags",
)

help_texts = {
"default_action": "The default behavior of the ACL.",
"name": "The name uniqueness per device is case insensitive.",
Expand Down Expand Up @@ -285,6 +292,11 @@ class ACLInterfaceAssignmentForm(NetBoxModelForm):
),
)
comments = CommentField()
fieldsets = (
FieldSet('device', 'interface', 'virtual_machine', 'vminterface', name=_('Assignment')),
FieldSet('access_list', 'direction', name=_('Access List Details')),
FieldSet('comments', 'tags', name=_('')),
)

def __init__(self, *args, **kwargs):
# Initialize helper selectors
Expand Down Expand Up @@ -313,6 +325,7 @@ class Meta:
"comments",
"tags",
)

help_texts = {
"direction": mark_safe(
"<b>*Note:</b> CANNOT assign 2 ACLs to the same interface & direction.",
Expand Down Expand Up @@ -440,10 +453,9 @@ class ACLStandardRuleForm(NetBoxModelForm):
)

fieldsets = (
("Access List Details", ("access_list", "description", "tags")),
("Rule Definition", ("index", "action", "remark", "source_prefix")),
FieldSet("access_list", "description", "tags", name=_('Access List Details')),
FieldSet("index", "action", "remark", "source_prefix", name=_('Rule Definition'))
)

class Meta:
model = ACLStandardRule
fields = (
Expand All @@ -455,6 +467,10 @@ class Meta:
"tags",
"description",
)




help_texts = {
"index": help_text_acl_rule_index,
"action": help_text_acl_action,
Expand Down Expand Up @@ -524,22 +540,9 @@ class ACLExtendedRuleForm(NetBoxModelForm):
label="Destination Prefix",
)
fieldsets = (
("Access List Details", ("access_list", "description", "tags")),
(
"Rule Definition",
(
"index",
"action",
"remark",
"source_prefix",
"source_ports",
"destination_prefix",
"destination_ports",
"protocol",
),
),
FieldSet("access_list", "description", "tags", name=_('Access List Details')),
FieldSet("index", "action", "remark", "source_prefix", "source_ports", "destination_prefix", "destination_ports", "protocol", name=_('Rule Definition'))
)

class Meta:
model = ACLExtendedRule
fields = (
Expand All @@ -555,6 +558,7 @@ class Meta:
"tags",
"description",
)

help_texts = {
"action": help_text_acl_action,
"destination_ports": help_text_acl_rule_logic,
Expand Down
4 changes: 1 addition & 3 deletions netbox_acls/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from .types import *

schema = [
schema.NetBoxACLSAccessListQuery,
schema.NetBoxACLSStandardRuleQuery,
schema.NetBoxACLSACLExtendedRuleQuery
schema.NetBoxACLSQuery
]

30 changes: 9 additions & 21 deletions netbox_acls/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@
import strawberry_django
from .types import *
from ..models import *
from typing import List

@strawberry.type
class NetBoxACLSAccessListQuery:
@strawberry.type(name="Query")
class NetBoxACLSQuery:
"""
Defines the queries available to this plugin via the graphql api.
"""
@strawberry.field
def access_list(self, id: int) -> AccessListType:
return AccessList.objects.get(pk=id)
access_list_list: list[AccessListType] = strawberry_django.field()
access_list: AccessListType = strawberry_django.field()
access_list_list: List[AccessListType] = strawberry_django.field()

@strawberry.type
class NetBoxACLSACLExtendedRuleQuery:
@strawberry.field
def acl_extended_rule(self, id: int) -> ACLExtendedRuleType:
return ACLExtendedRule.objects.get(pk=id)
acl_extended_rule_list: list[ACLExtendedRuleType] = strawberry_django.field()



@strawberry.type
class NetBoxACLSStandardRuleQuery:
@strawberry.field
def acl_standard_rule(self, id: int) -> ACLStandardRuleType:
return ACLStandardRule.objects.get(pk=id)
acl_standard_rule_list: list[ACLStandardRuleType] = strawberry_django.field()
acl_extended_rule: ACLExtendedRuleType = strawberry_django.field()
acl_extended_rule_list: List[ACLExtendedRuleType] = strawberry_django.field()

acl_standard_rule: ACLStandardRuleType = strawberry_django.field()
acl_standard_rule_list: List[ACLStandardRuleType] = strawberry_django.field()

2 changes: 1 addition & 1 deletion netbox_acls/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.6.1"
__version__ = "1.7.0"
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_version(relative_path):
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Intended Audience :: System Administrators",
"Intended Audience :: Telecommunications Industry",
"Framework :: Django",
Expand Down
Loading