forked from makeplane/plane
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: rest framework throttling (makeplane#4534)
- Loading branch information
1 parent
4feec35
commit 410f04c
Showing
7 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Third party imports | ||
from rest_framework.throttling import AnonRateThrottle | ||
from rest_framework import status | ||
from rest_framework.response import Response | ||
|
||
# Module imports | ||
from plane.authentication.adapter.error import ( | ||
AuthenticationException, | ||
AUTHENTICATION_ERROR_CODES, | ||
) | ||
|
||
|
||
class AuthenticationThrottle(AnonRateThrottle): | ||
rate = "30/minute" | ||
scope = "authentication" | ||
|
||
def throttle_failure_view(self, request, *args, **kwargs): | ||
try: | ||
raise AuthenticationException( | ||
error_code=AUTHENTICATION_ERROR_CODES["RATE_LIMIT_EXCEEDED"], | ||
error_message="RATE_LIMIT_EXCEEDED", | ||
) | ||
except AuthenticationException as e: | ||
return Response( | ||
e.get_error_dict(), status=status.HTTP_429_TOO_MANY_REQUESTS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters