mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Move GRAPHQL_ENABLED to dynamic configuration
This commit is contained in:
@ -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
|
||||
|
@ -140,14 +140,6 @@ EXEMPT_VIEW_PERMISSIONS = ['*']
|
||||
|
||||
---
|
||||
|
||||
## GRAPHQL_ENABLED
|
||||
|
||||
Default: True
|
||||
|
||||
Setting this to False will disable the GraphQL API.
|
||||
|
||||
---
|
||||
|
||||
## HTTP_PROXIES
|
||||
|
||||
Default: None
|
||||
|
@ -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',),
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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', {})
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user