From d2391b9c63ecdac04121e18f2f072f7c62193d2a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 8 Nov 2021 15:31:09 -0500 Subject: [PATCH] Move GRAPHQL_ENABLED to dynamic configuration --- docs/configuration/dynamic-settings.md | 8 ++++++++ docs/configuration/optional-settings.md | 8 -------- netbox/extras/admin.py | 2 +- netbox/netbox/config/parameters.py | 7 +++++++ netbox/netbox/configuration.example.py | 3 --- netbox/netbox/graphql/views.py | 4 +++- netbox/netbox/settings.py | 1 - netbox/templates/base/layout.html | 2 +- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/configuration/dynamic-settings.md b/docs/configuration/dynamic-settings.md index a98143045..a222272c2 100644 --- a/docs/configuration/dynamic-settings.md +++ b/docs/configuration/dynamic-settings.md @@ -74,6 +74,14 @@ By default, NetBox will permit users to create duplicate prefixes and IP address --- +## GRAPHQL_ENABLED + +Default: True + +Setting this to False will disable the GraphQL API. + +--- + ## MAINTENANCE_MODE Default: False diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index e49968130..d8d79b6ec 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -140,14 +140,6 @@ EXEMPT_VIEW_PERMISSIONS = ['*'] --- -## GRAPHQL_ENABLED - -Default: True - -Setting this to False will disable the GraphQL API. - ---- - ## HTTP_PROXIES Default: None diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index 73ffb40fc..b6ee01db9 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -34,7 +34,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin): 'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'), }), ('Miscellaneous', { - 'fields': ('MAINTENANCE_MODE', 'CHANGELOG_RETENTION', 'MAPS_URL'), + 'fields': ('MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'MAPS_URL'), }), ('Config Revision', { 'fields': ('comment',), diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py index 1be664b28..b4f16bf28 100644 --- a/netbox/netbox/config/parameters.py +++ b/netbox/netbox/config/parameters.py @@ -139,6 +139,13 @@ PARAMS = ( description="Enable maintenance mode", field=forms.BooleanField ), + ConfigParam( + name='GRAPHQL_ENABLED', + label='GraphQL enabled', + default=True, + description="Enable the GraphQL API", + field=forms.BooleanField + ), ConfigParam( name='CHANGELOG_RETENTION', label='Changelog retention', diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index 48885f844..8130acb2e 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -112,9 +112,6 @@ EXEMPT_VIEW_PERMISSIONS = [ # 'ipam.prefix', ] -# Enable the GraphQL API -GRAPHQL_ENABLED = True - # HTTP proxies NetBox should use when sending outbound HTTP requests (e.g. for webhooks). # HTTP_PROXIES = { # 'http': 'http://10.10.1.10:3128', diff --git a/netbox/netbox/graphql/views.py b/netbox/netbox/graphql/views.py index c2c0269fa..e1573dba6 100644 --- a/netbox/netbox/graphql/views.py +++ b/netbox/netbox/graphql/views.py @@ -6,6 +6,7 @@ from graphene_django.views import GraphQLView as GraphQLView_ from rest_framework.exceptions import AuthenticationFailed from netbox.api.authentication import TokenAuthentication +from netbox.config import get_config class GraphQLView(GraphQLView_): @@ -15,9 +16,10 @@ class GraphQLView(GraphQLView_): graphiql_template = 'graphiql.html' def dispatch(self, request, *args, **kwargs): + config = get_config() # Enforce GRAPHQL_ENABLED - if not settings.GRAPHQL_ENABLED: + if not config.GRAPHQL_ENABLED: return HttpResponseNotFound("The GraphQL API is not enabled.") # Attempt to authenticate the user using a DRF token, if provided diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 529da77dc..5e5718559 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -90,7 +90,6 @@ DEVELOPER = getattr(configuration, 'DEVELOPER', False) DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs')) EMAIL = getattr(configuration, 'EMAIL', {}) EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', []) -GRAPHQL_ENABLED = getattr(configuration, 'GRAPHQL_ENABLED', True) HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None) INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1')) LOGGING = getattr(configuration, 'LOGGING', {}) diff --git a/netbox/templates/base/layout.html b/netbox/templates/base/layout.html index 2770a6dc6..d45dc62f6 100644 --- a/netbox/templates/base/layout.html +++ b/netbox/templates/base/layout.html @@ -127,7 +127,7 @@ {# GraphQL API #} - {% if settings.GRAPHQL_ENABLED %} + {% if config.GRAPHQL_ENABLED %}