77.. moduleauthor:: Eric Coan <[email protected] > 88
99"""
10+
1011from datetime import datetime
1112
1213from flask import Blueprint , g
3334
3435
3536class ApiKeyList (AuthenticatedResource ):
36- """ Defines the 'api_keys' endpoint """
37+ """Defines the 'api_keys' endpoint"""
3738
3839 def __init__ (self ):
3940 super ().__init__ ()
@@ -148,13 +149,11 @@ def post(self, data=None):
148149 revoked = False ,
149150 issued_at = int (datetime .utcnow ().timestamp ()),
150151 )
151- return dict (
152- jwt = create_token (access_token .user_id , access_token .id , access_token .ttl )
153- )
152+ return dict (jwt = create_token (access_token .user_id , access_token .id , access_token .ttl ))
154153
155154
156155class ApiKeyUserList (AuthenticatedResource ):
157- """ Defines the 'keys' endpoint on the 'users' endpoint. """
156+ """Defines the 'keys' endpoint on the 'users' endpoint."""
158157
159158 def __init__ (self ):
160159 super ().__init__ ()
@@ -253,11 +252,7 @@ def post(self, user_id, data=None):
253252 if not ApiKeyCreatorPermission ().can ():
254253 if user_id != g .current_user .id :
255254 return (
256- dict (
257- message = "You are not authorized to create tokens for: {}" .format (
258- user_id
259- )
260- ),
255+ dict (message = "You are not authorized to create tokens for: {}" .format (user_id )),
261256 403 ,
262257 )
263258
@@ -268,9 +263,7 @@ def post(self, user_id, data=None):
268263 revoked = False ,
269264 issued_at = int (datetime .utcnow ().timestamp ()),
270265 )
271- return dict (
272- jwt = create_token (access_token .user_id , access_token .id , access_token .ttl )
273- )
266+ return dict (jwt = create_token (access_token .user_id , access_token .id , access_token .ttl ))
274267
275268
276269class ApiKeys (AuthenticatedResource ):
@@ -366,9 +359,7 @@ def put(self, aid, data=None):
366359 if not ApiKeyCreatorPermission ().can ():
367360 return dict (message = "You are not authorized to update this token!" ), 403
368361
369- service .update (
370- access_key , name = data ["name" ], revoked = data ["revoked" ], ttl = data ["ttl" ]
371- )
362+ service .update (access_key , name = data ["name" ], revoked = data ["revoked" ], ttl = data ["ttl" ])
372363 return dict (jwt = create_token (access_key .user_id , access_key .id , access_key .ttl ))
373364
374365 def delete (self , aid ):
@@ -512,9 +503,7 @@ def put(self, uid, aid, data=None):
512503 if access_key .user_id != uid :
513504 return dict (message = "You are not authorized to update this token!" ), 403
514505
515- service .update (
516- access_key , name = data ["name" ], revoked = data ["revoked" ], ttl = data ["ttl" ]
517- )
506+ service .update (access_key , name = data ["name" ], revoked = data ["revoked" ], ttl = data ["ttl" ])
518507 return dict (jwt = create_token (access_key .user_id , access_key .id , access_key .ttl ))
519508
520509 def delete (self , uid , aid ):
@@ -616,10 +605,6 @@ def get(self, aid):
616605
617606api .add_resource (ApiKeyList , "/keys" , endpoint = "api_keys" )
618607api .add_resource (ApiKeys , "/keys/<int:aid>" , endpoint = "api_key" )
619- api .add_resource (
620- ApiKeysDescribed , "/keys/<int:aid>/described" , endpoint = "api_key_described"
621- )
608+ api .add_resource (ApiKeysDescribed , "/keys/<int:aid>/described" , endpoint = "api_key_described" )
622609api .add_resource (ApiKeyUserList , "/users/<int:user_id>/keys" , endpoint = "user_api_keys" )
623- api .add_resource (
624- UserApiKeys , "/users/<int:uid>/keys/<int:aid>" , endpoint = "user_api_key"
625- )
610+ api .add_resource (UserApiKeys , "/users/<int:uid>/keys/<int:aid>" , endpoint = "user_api_key" )
0 commit comments