mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Add configuration parameter to toggle GraphQL API
This commit is contained in:
parent
05ba54b6d3
commit
8d2f79cf24
@ -201,6 +201,14 @@ EXEMPT_VIEW_PERMISSIONS = ['*']
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## GRAPHQL_ENABLED
|
||||||
|
|
||||||
|
Default: True
|
||||||
|
|
||||||
|
Setting this to False will disable the GraphQL API.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## HTTP_PROXIES
|
## HTTP_PROXIES
|
||||||
|
|
||||||
Default: None
|
Default: None
|
||||||
|
@ -149,6 +149,9 @@ EXEMPT_VIEW_PERMISSIONS = [
|
|||||||
# 'ipam.prefix',
|
# '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 NetBox should use when sending outbound HTTP requests (e.g. for webhooks).
|
||||||
# HTTP_PROXIES = {
|
# HTTP_PROXIES = {
|
||||||
# 'http': 'http://10.10.1.10:3128',
|
# 'http': 'http://10.10.1.10:3128',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.views import redirect_to_login
|
from django.contrib.auth.views import redirect_to_login
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseNotFound, HttpResponseForbidden
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from graphene_django.views import GraphQLView as GraphQLView_
|
from graphene_django.views import GraphQLView as GraphQLView_
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
@ -14,6 +14,10 @@ class GraphQLView(GraphQLView_):
|
|||||||
"""
|
"""
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
# Enforce GRAPHQL_ENABLED
|
||||||
|
if not settings.GRAPHQL_ENABLED:
|
||||||
|
return HttpResponseNotFound("The GraphQL API is not enabled.")
|
||||||
|
|
||||||
# Attempt to authenticate the user using a DRF token, if provided
|
# Attempt to authenticate the user using a DRF token, if provided
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
authenticator = TokenAuthentication()
|
authenticator = TokenAuthentication()
|
||||||
|
@ -83,6 +83,7 @@ DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BAS
|
|||||||
EMAIL = getattr(configuration, 'EMAIL', {})
|
EMAIL = getattr(configuration, 'EMAIL', {})
|
||||||
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
|
ENFORCE_GLOBAL_UNIQUE = getattr(configuration, 'ENFORCE_GLOBAL_UNIQUE', False)
|
||||||
EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
|
EXEMPT_VIEW_PERMISSIONS = getattr(configuration, 'EXEMPT_VIEW_PERMISSIONS', [])
|
||||||
|
GRAPHQL_ENABLED = getattr(configuration, 'GRAPHQL_ENABLED', True)
|
||||||
HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None)
|
HTTP_PROXIES = getattr(configuration, 'HTTP_PROXIES', None)
|
||||||
INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1'))
|
INTERNAL_IPS = getattr(configuration, 'INTERNAL_IPS', ('127.0.0.1', '::1'))
|
||||||
LOGGING = getattr(configuration, 'LOGGING', {})
|
LOGGING = getattr(configuration, 'LOGGING', {})
|
||||||
|
@ -6,6 +6,15 @@ from utilities.testing import disable_warnings, TestCase
|
|||||||
|
|
||||||
class GraphQLTestCase(TestCase):
|
class GraphQLTestCase(TestCase):
|
||||||
|
|
||||||
|
@override_settings(GRAPHQL_ENABLED=False)
|
||||||
|
def test_graphql_enabled(self):
|
||||||
|
"""
|
||||||
|
The /graphql URL should return a 404 when GRAPHQL_ENABLED=False
|
||||||
|
"""
|
||||||
|
url = reverse('graphql')
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertHttpStatus(response, 404)
|
||||||
|
|
||||||
@override_settings(LOGIN_REQUIRED=True)
|
@override_settings(LOGIN_REQUIRED=True)
|
||||||
def test_graphiql_interface(self):
|
def test_graphiql_interface(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user