Răsfoiți Sursa

Move GRAPHQL_ENABLED to dynamic configuration

jeremystretch 4 ani în urmă
părinte
comite
d2391b9c63

+ 8 - 0
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

+ 0 - 8
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

+ 1 - 1
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',),

+ 7 - 0
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',

+ 0 - 3
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',

+ 3 - 1
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

+ 0 - 1
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', {})

+ 1 - 1
netbox/templates/base/layout.html

@@ -127,7 +127,7 @@
                 </a>
 
                 {# GraphQL API #}
-                {% if settings.GRAPHQL_ENABLED %}
+                {% if config.GRAPHQL_ENABLED %}
                   <a type="button" class="nav-link" href="{% url 'graphql' %}" target="_blank">
                     <i title="GraphQL API" class="mdi mdi-graphql text-primary" data-bs-placement="top" data-bs-toggle="tooltip"></i>
                   </a>