Skip to content

Commit

Permalink
[api] Added ScopedThrottling #34
Browse files Browse the repository at this point in the history
closes #34
  • Loading branch information
ManishShah120 committed Dec 26, 2020
1 parent 921be06 commit 4cc0d13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions openwisp_ipam/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 11 additions & 3 deletions openwisp_ipam/apps.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4cc0d13

Please sign in to comment.