Skip to content

Commit

Permalink
Added Rate Limiting for One Admin API VIew
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-naman-sf committed Nov 20, 2023
1 parent bc54d71 commit 4e24392
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ def safe_key() -> str:
],
'DEFAULT_THROTTLE_RATES': {
'anon': '4/second',
'user': '4/second'
'user': '4/second',
'admin':'100/minute'
}

}
Expand Down
7 changes: 7 additions & 0 deletions metadeploy/adminapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django_filters import rest_framework as filters
from rest_framework import serializers, status, viewsets
from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle
from sfdo_template_helpers.admin.permissions import IsAPIUser
from sfdo_template_helpers.admin.serializers import AdminAPISerializer
from sfdo_template_helpers.admin.views import AdminAPIViewSet
Expand All @@ -12,6 +13,10 @@
from metadeploy.api.models import SUPPORTED_ORG_TYPES, Plan
from metadeploy.api.serializers import get_from_data_or_instance

class AdminThrottle(UserRateThrottle):
scope = 'admin'



class ProductSerializer(AdminAPISerializer):
title = serializers.CharField()
Expand Down Expand Up @@ -138,6 +143,7 @@ class Meta:
class PlanTemplateViewSet(AdminAPIViewSet):
model_name = "PlanTemplate"
serializer_base = PlanTemplateSerializer
throttle_classes = [AdminThrottle]


class PlanFilter(filters.FilterSet):
Expand All @@ -152,6 +158,7 @@ class PlanViewSet(AdminAPIViewSet):
filterset_class = PlanFilter



class PlanSlugViewSet(AdminAPIViewSet):
model_name = "PlanSlug"

Expand Down

0 comments on commit 4e24392

Please sign in to comment.