diff --git a/.github/configuration.testing.py b/.github/configuration.testing.py index fcbfee2..b7a0e41 100644 --- a/.github/configuration.testing.py +++ b/.github/configuration.testing.py @@ -15,6 +15,7 @@ } PLUGINS = [ + 'netbox_plugin_extensions', 'netbox_secretstore', ] diff --git a/README.md b/README.md index e2b9201..278d881 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,14 @@ This is the continuation of the secrets app. Installation ---- -To install, add to your local_requirements.txt and pip install -r local_requirements.txt \ No newline at end of file +* Install NetBox as per NetBox documentation +* Add to local_requirements.txt: + * `netbox-plugin-extensions` + * `netbox-secretstore` +* Install requirements: `./venv/bin/pip install -r local_requirements.txt` +* Add to PLUGINS in NetBox configuration: + * `'netbox_plugin_extensions',` + * `'netbox_secretstore',` +* Run migration: `./venv/bin/python netbox/manage.py migrate` +* Run collectstatic: `./venv/bin/python netbox/manage.py collectstatic --no-input` + diff --git a/netbox_secretstore/api/views.py b/netbox_secretstore/api/views.py index 4bba206..1f02490 100644 --- a/netbox_secretstore/api/views.py +++ b/netbox_secretstore/api/views.py @@ -13,7 +13,7 @@ from extras.api.views import CustomFieldModelViewSet from netbox.api.views import ModelViewSet -from netbox_secretstore import filters +from netbox_secretstore import filtersets from netbox_secretstore.exceptions import InvalidKey from netbox_secretstore.models import Secret, SecretRole, SessionKey, UserKey from utilities.utils import count_related @@ -42,7 +42,7 @@ class SecretRoleViewSet(CustomFieldModelViewSet): secret_count=count_related(Secret, 'role') ) serializer_class = serializers.SecretRoleSerializer - filterset_class = filters.SecretRoleFilterSet + filterset_class = filtersets.SecretRoleFilterSet # @@ -52,7 +52,7 @@ class SecretRoleViewSet(CustomFieldModelViewSet): class SecretViewSet(ModelViewSet): queryset = Secret.objects.prefetch_related('role', 'tags') serializer_class = serializers.SecretSerializer - filterset_class = filters.SecretFilterSet + filterset_class = filtersets.SecretFilterSet master_key = None diff --git a/netbox_secretstore/filters.py b/netbox_secretstore/filtersets.py similarity index 86% rename from netbox_secretstore/filters.py rename to netbox_secretstore/filtersets.py index 74e80ca..2a40cb9 100644 --- a/netbox_secretstore/filters.py +++ b/netbox_secretstore/filtersets.py @@ -16,11 +16,24 @@ class SecretRoleFilterSet(ChangeLoggedModelFilterSet): + q = django_filters.CharFilter( + method='search', + label='Search', + ) + tag = TagFilter() class Meta: model = SecretRole fields = ['id', 'name', 'slug'] + def search(self, queryset, name, value): + if not value.strip(): + return queryset + return queryset.filter( + Q(name__icontains=value) | + Q(slug__icontains=value) + ) + class SecretFilterSet(BaseFilterSet): q = django_filters.CharFilter( diff --git a/netbox_secretstore/forms/secrets.py b/netbox_secretstore/forms/secrets.py index 66416c0..447e6ab 100644 --- a/netbox_secretstore/forms/secrets.py +++ b/netbox_secretstore/forms/secrets.py @@ -75,6 +75,15 @@ class Meta: nullable_fields = ['description'] +class SecretRoleFilterForm(CustomFieldModelFilterForm): + model = Secret + q = forms.CharField( + required=False, + label=_('Search') + ) + tag = TagFilterField(model) + + # # Secrets # diff --git a/netbox_secretstore/graphql/__init__.py b/netbox_secretstore/graphql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netbox_secretstore/graphql/schema.py b/netbox_secretstore/graphql/schema.py new file mode 100644 index 0000000..0ad2abc --- /dev/null +++ b/netbox_secretstore/graphql/schema.py @@ -0,0 +1,12 @@ +import graphene + +from netbox.graphql.fields import ObjectField, ObjectListField +from .types import * + + +class SecretStoreQuery(graphene.ObjectType): + secret = ObjectField(SecretType) + secret_list = ObjectListField(SecretType) + + secretrole = ObjectField(SecretRoleType) + secretrole_list = ObjectListField(SecretRoleType) diff --git a/netbox_secretstore/graphql/types.py b/netbox_secretstore/graphql/types.py new file mode 100644 index 0000000..50f17f2 --- /dev/null +++ b/netbox_secretstore/graphql/types.py @@ -0,0 +1,23 @@ +from netbox_secretstore import filtersets, models +from netbox.graphql.types import ObjectType, OrganizationalObjectType, PrimaryObjectType + +__all__ = ( + 'SecretRoleType', + 'SecretType', +) + + +class SecretRoleType(ObjectType): + + class Meta: + model = models.SecretRole + fields = '__all__' + filterset_class = filtersets.SecretRoleFilterSet + + +class SecretType(PrimaryObjectType): + + class Meta: + model = models.Secret + fields = '__all__' + filterset_class = filtersets.SecretFilterSet diff --git a/netbox_secretstore/migrations/0004_secretrole_tags.py b/netbox_secretstore/migrations/0004_secretrole_tags.py new file mode 100644 index 0000000..ee9b1cc --- /dev/null +++ b/netbox_secretstore/migrations/0004_secretrole_tags.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.9 on 2021-12-21 15:27 + +from django.db import migrations +import taggit.managers + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0066_customfield_name_validation'), + ('netbox_secretstore', '0003_modify_objectchange_records'), + ] + + operations = [ + migrations.AddField( + model_name='secretrole', + name='tags', + field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'), + ), + ] diff --git a/netbox_secretstore/templates/netbox_secretstore/secret.html b/netbox_secretstore/templates/netbox_secretstore/secret.html index 572e0e9..2989698 100644 --- a/netbox_secretstore/templates/netbox_secretstore/secret.html +++ b/netbox_secretstore/templates/netbox_secretstore/secret.html @@ -68,7 +68,7 @@