File tree 1 file changed +15
-6
lines changed
1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,8 @@ class HasBuildAPIKey(BaseHasAPIKey):
85
85
"""
86
86
Custom permission to inject the build API key into the request.
87
87
88
- This avoids having to parse the key again on each view.
88
+ We completely override the ``has_permission`` method
89
+ to avoid having to parse and validate the key again on each view.
89
90
The key is injected in the ``request.build_api_key`` attribute
90
91
only if it's valid, otherwise it's set to ``None``.
91
92
"""
@@ -94,10 +95,18 @@ class HasBuildAPIKey(BaseHasAPIKey):
94
95
key_parser = TokenKeyParser ()
95
96
96
97
def has_permission (self , request , view ):
97
- build_api_key = None
98
- has_permission = super ().has_permission (request , view )
99
- if has_permission :
100
- key = self .get_key (request )
98
+ request .build_api_key = None
99
+ key = self .get_key (request )
100
+ if not key :
101
+ return False
102
+
103
+ try :
101
104
build_api_key = self .model .objects .get_from_key (key )
105
+ except self .model .DoesNotExist :
106
+ return False
107
+
108
+ if build_api_key .has_expired :
109
+ return False
110
+
102
111
request .build_api_key = build_api_key
103
- return has_permission
112
+ return True
You can’t perform that action at this time.
0 commit comments