diff --git a/openwisp_ipam/api/views.py b/openwisp_ipam/api/views.py index 19487ca..8d0a188 100644 --- a/openwisp_ipam/api/views.py +++ b/openwisp_ipam/api/views.py @@ -164,6 +164,7 @@ class SubnetListCreateView(ListCreateAPIView): serializer_class = SubnetSerializer authentication_classes = (BearerAuthentication, SessionAuthentication) permission_classes = (DjangoModelPermissions,) + throttle_scope = 'ipam' pagination_class = ListViewPagination queryset = Subnet.objects.all() diff --git a/openwisp_ipam/apps.py b/openwisp_ipam/apps.py index 7c1b38f..9265bba 100644 --- a/openwisp_ipam/apps.py +++ b/openwisp_ipam/apps.py @@ -1,11 +1,19 @@ -from django.apps import AppConfig +from django.conf import settings +from openwisp_utils.api.apps import ApiAppConfig +from openwisp_utils.utils import default_or_test from .compat import patch_ipaddress_lib -class OpenWispIpamConfig(AppConfig): +class OpenWispIpamConfig(ApiAppConfig): name = 'openwisp_ipam' verbose_name = 'IPAM' - def ready(self): + API_ENABLED = getattr(settings, 'OPENWISP_IPAM_API', True) + REST_FRAMEWORK_SETTINGS = { + 'DEFAULT_THROTTLE_RATES': {'ipam': default_or_test('400/hour', None)}, + } + + def ready(self, *args, **kwargs): + super().ready(*args, **kwargs) patch_ipaddress_lib() diff --git a/tests/openwisp2/settings.py b/tests/openwisp2/settings.py index b1ce768..dab79cf 100644 --- a/tests/openwisp2/settings.py +++ b/tests/openwisp2/settings.py @@ -84,6 +84,7 @@ STATIC_URL = '/static/' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' OPENWISP_USERS_AUTH_API = True +OPENWISP_IPAM_API = True if TESTING: OPENWISP_ORGANIZATION_USER_ADMIN = True