Skip to content

Commit 4586ceb

Browse files
authored
Merge pull request #200 from netbox-community/dev
Prepare 4.0 #197
2 parents da0fffc + 79be0d6 commit 4586ceb

File tree

16 files changed

+227
-101
lines changed

16 files changed

+227
-101
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Thank you for sharing your work and for opening a PR.
55
66
(!) IMPORTANT (!):
7-
First make sure that you point your PR to the `devel` branch!
7+
First make sure that you point your PR to the `dev` branch!
88
99
Now please read the comments carefully and try to provide information
1010
on all relevant titles.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fetch-depth: 0
2323

2424
- name: Lint Code Base
25-
uses: github/super-linter/slim@v5
25+
uses: github/super-linter/slim@v6
2626
env:
2727
DEFAULT_BRANCH: dev
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG NETBOX_VARIANT=v3.7
1+
ARG NETBOX_VARIANT=v4.0
22

33
FROM netboxcommunity/netbox:${NETBOX_VARIANT}
44

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Each Plugin Version listed below has been tested with its corresponding NetBox V
3838

3939
| NetBox Version | Plugin Version |
4040
|:--------------:|:--------------:|
41+
| >= 4.0.2 | 1.6.0 |
4142
| 3.7 | 1.5.0 |
4243
| 3.6 | 1.4.0 |
4344
| 3.5 | 1.3.0 |
@@ -79,6 +80,12 @@ PLUGINS_CONFIG = {
7980
}
8081
```
8182

83+
To add the required `netbox-acls` tables to your NetBox database, run the `migrate` manager subcommand in the NetBox virtual environment:
84+
```
85+
cd /opt/netbox
86+
sudo ./venv/bin/python3 netbox/manage.py migrate
87+
```
88+
8289
## Developing
8390

8491
### VSCode + Docker + Dev Containers

netbox_acls/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ryanmerolle @abhi1693 @cruse1977 @natm

netbox_acls/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Define the NetBox Plugin
33
"""
44

5-
from extras.plugins import PluginConfig
5+
from netbox.plugins import PluginConfig
66

77
from .version import __version__
88

@@ -17,8 +17,8 @@ class NetBoxACLsConfig(PluginConfig):
1717
version = __version__
1818
description = "Manage simple ACLs in NetBox"
1919
base_url = "access-lists"
20-
min_version = "3.7.0"
21-
max_version = "3.7.99"
20+
min_version = "4.0.2"
21+
max_version = "4.0.99"
2222

2323

2424
config = NetBoxACLsConfig

netbox_acls/api/serializers.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Meta:
7575
"last_updated",
7676
"rule_count",
7777
)
78+
brief_fields = ("id", "url", "name", "display")
7879

7980
@extend_schema_field(serializers.DictField())
8081
def get_assigned_object(self, obj):
@@ -139,6 +140,7 @@ class Meta:
139140
"created",
140141
"last_updated",
141142
)
143+
brief_fields = ("id", "url", "access_list")
142144

143145
@extend_schema_field(serializers.DictField())
144146
def get_assigned_object(self, obj):
@@ -212,6 +214,7 @@ class Meta:
212214
"last_updated",
213215
"source_prefix",
214216
)
217+
brief_fields = ("id", "url", "display")
215218

216219
def validate(self, data):
217220
"""
@@ -221,14 +224,17 @@ def validate(self, data):
221224
"""
222225
error_message = {}
223226

224-
# Check if action set to remark, but no remark set.
225-
if data.get("action") == "remark" and data.get("remark") is None:
226-
error_message["remark"] = [error_message_no_remark]
227-
# Check if action set to remark, but source_prefix set.
228-
if data.get("source_prefix"):
229-
error_message["source_prefix"] = [
230-
error_message_action_remark_source_prefix_set,
231-
]
227+
if data.get("action") == "remark":
228+
# Check if action set to remark, but no remark set.
229+
if data.get("remark") is None:
230+
error_message["remark"] = [
231+
error_message_no_remark,
232+
]
233+
# Check if action set to remark, but source_prefix set.
234+
if data.get("source_prefix"):
235+
error_message["source_prefix"] = [
236+
error_message_action_remark_source_prefix_set,
237+
]
232238

233239
if error_message:
234240
raise serializers.ValidationError(error_message)
@@ -281,7 +287,7 @@ class Meta:
281287
"protocol",
282288
"remark",
283289
)
284-
290+
brief_fields = ("id", "url", "display")
285291
def validate(self, data):
286292
"""
287293
Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
@@ -295,34 +301,37 @@ def validate(self, data):
295301
"""
296302
error_message = {}
297303

298-
# Check if action set to remark, but no remark set.
299-
if data.get("action") == "remark" and data.get("remark") is None:
300-
error_message["remark"] = [error_message_no_remark]
301-
# Check if action set to remark, but source_prefix set.
302-
if data.get("source_prefix"):
303-
error_message["source_prefix"] = [
304-
error_message_action_remark_source_prefix_set,
305-
]
306-
# Check if action set to remark, but source_ports set.
307-
if data.get("source_ports"):
308-
error_message["source_ports"] = [
309-
"Action is set to remark, Source Ports CANNOT be set.",
310-
]
311-
# Check if action set to remark, but destination_prefix set.
312-
if data.get("destination_prefix"):
313-
error_message["destination_prefix"] = [
314-
"Action is set to remark, Destination Prefix CANNOT be set.",
315-
]
316-
# Check if action set to remark, but destination_ports set.
317-
if data.get("destination_ports"):
318-
error_message["destination_ports"] = [
319-
"Action is set to remark, Destination Ports CANNOT be set.",
320-
]
321-
# Check if action set to remark, but protocol set.
322-
if data.get("protocol"):
323-
error_message["protocol"] = [
324-
"Action is set to remark, Protocol CANNOT be set.",
325-
]
304+
if data.get("action") == "remark":
305+
# Check if action set to remark, but no remark set.
306+
if data.get("remark") is None:
307+
error_message["remark"] = [
308+
error_message_no_remark,
309+
]
310+
# Check if action set to remark, but source_prefix set.
311+
if data.get("source_prefix"):
312+
error_message["source_prefix"] = [
313+
error_message_action_remark_source_prefix_set,
314+
]
315+
# Check if action set to remark, but source_ports set.
316+
if data.get("source_ports"):
317+
error_message["source_ports"] = [
318+
"Action is set to remark, Source Ports CANNOT be set.",
319+
]
320+
# Check if action set to remark, but destination_prefix set.
321+
if data.get("destination_prefix"):
322+
error_message["destination_prefix"] = [
323+
"Action is set to remark, Destination Prefix CANNOT be set.",
324+
]
325+
# Check if action set to remark, but destination_ports set.
326+
if data.get("destination_ports"):
327+
error_message["destination_ports"] = [
328+
"Action is set to remark, Destination Ports CANNOT be set.",
329+
]
330+
# Check if action set to remark, but protocol set.
331+
if data.get("protocol"):
332+
error_message["protocol"] = [
333+
"Action is set to remark, Protocol CANNOT be set.",
334+
]
326335

327336
if error_message:
328337
raise serializers.ValidationError(error_message)

netbox_acls/filtersets.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import django_filters
66
from dcim.models import Device, Interface, VirtualChassis
7+
from django.db.models import Q
78
from netbox.filtersets import NetBoxModelFilterSet
89
from virtualization.models import VirtualMachine, VMInterface
910

@@ -80,7 +81,16 @@ def search(self, queryset, name, value):
8081
"""
8182
Override the default search behavior for the django model.
8283
"""
83-
return queryset.filter(description__icontains=value)
84+
query = (
85+
Q(name__icontains=value)
86+
| Q(device__name__icontains=value)
87+
| Q(virtual_chassis__name__icontains=value)
88+
| Q(virtual_machine__name__icontains=value)
89+
| Q(type__icontains=value)
90+
| Q(default_action__icontains=value)
91+
| Q(comments__icontains=value)
92+
)
93+
return queryset.filter(query)
8494

8595

8696
class ACLInterfaceAssignmentFilterSet(NetBoxModelFilterSet):
@@ -131,7 +141,13 @@ def search(self, queryset, name, value):
131141
"""
132142
Override the default search behavior for the django model.
133143
"""
134-
return queryset.filter(description__icontains=value)
144+
query = (
145+
Q(access_list__name__icontains=value)
146+
| Q(direction__icontains=value)
147+
| Q(interface__name__icontains=value)
148+
| Q(vminterface__name__icontains=value)
149+
)
150+
return queryset.filter(query)
135151

136152

137153
class ACLStandardRuleFilterSet(NetBoxModelFilterSet):
@@ -151,7 +167,12 @@ def search(self, queryset, name, value):
151167
"""
152168
Override the default search behavior for the django model.
153169
"""
154-
return queryset.filter(description__icontains=value)
170+
query = (
171+
Q(access_list__name__icontains=value)
172+
| Q(index__icontains=value)
173+
| Q(action__icontains=value)
174+
)
175+
return queryset.filter(query)
155176

156177

157178
class ACLExtendedRuleFilterSet(NetBoxModelFilterSet):
@@ -171,4 +192,10 @@ def search(self, queryset, name, value):
171192
"""
172193
Override the default search behavior for the django model.
173194
"""
174-
return queryset.filter(description__icontains=value)
195+
query = (
196+
Q(access_list__name__icontains=value)
197+
| Q(index__icontains=value)
198+
| Q(action__icontains=value)
199+
| Q(protocol__icontains=value)
200+
)
201+
return queryset.filter(query)

netbox_acls/graphql/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
from .schema import *
22
from .types import *
3+
4+
schema = [
5+
schema.NetBoxACLSAccessListQuery,
6+
schema.NetBoxACLSStandardRuleQuery,
7+
schema.NetBoxACLSACLExtendedRuleQuery
8+
]
9+

netbox_acls/graphql/filters.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import strawberry_django
2+
from .. import filtersets, models
3+
from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin
4+
5+
__all__ = (
6+
'AccessListFilter',
7+
'ACLInterfaceAssignmentFilter',
8+
'ACLExtendedRuleFilter',
9+
'ACLStandardRuleFilter',
10+
)
11+
12+
@strawberry_django.filter(models.AccessList, lookups=True)
13+
@autotype_decorator(filtersets.AccessListFilterSet)
14+
class AccessListFilter(BaseFilterMixin):
15+
pass
16+
17+
@strawberry_django.filter(models.ACLStandardRule, lookups=True)
18+
@autotype_decorator(filtersets.ACLStandardRuleFilterSet)
19+
class ACLStandardRuleFilter(BaseFilterMixin):
20+
pass
21+
22+
@strawberry_django.filter(models.ACLExtendedRule, lookups=True)
23+
@autotype_decorator(filtersets.ACLExtendedRuleFilterSet)
24+
class ACLExtendedRuleFilter(BaseFilterMixin):
25+
pass
26+
27+
@strawberry_django.filter(models.ACLInterfaceAssignment, lookups=True)
28+
@autotype_decorator(filtersets.ACLInterfaceAssignmentFilterSet)
29+
class ACLInterfaceAssignmentFilter(BaseFilterMixin):
30+
pass

0 commit comments

Comments
 (0)