File tree 4 files changed +16
-5
lines changed
src/cloudforet/console_api_v2
4 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 1
1
spaceone-api
2
2
typing-inspect
3
3
python-multipart
4
+ PyJWT
Original file line number Diff line number Diff line change
1
+ from cloudforet .console_api_v2 .handler .authentication_handler import (
2
+ ConsoleAPIAuthenticationHandler ,
3
+ )
Original file line number Diff line number Diff line change 1
1
import jwt
2
+ from typing import Union
3
+
2
4
from spaceone .core import cache
3
5
from spaceone .core .error import ERROR_PERMISSION_DENIED
4
6
from spaceone .core .handler .authentication_handler import SpaceONEAuthenticationHandler
7
+ from spaceone .core .transaction import get_transaction
5
8
6
9
7
10
class ConsoleAPIAuthenticationHandler (SpaceONEAuthenticationHandler ):
8
11
def verify (self , params : dict ) -> None :
9
- token = self ._get_token ()
10
- token_info = self ._extract_token_info (token )
12
+ if token := self ._get_token ():
13
+ token_info = self ._extract_token_info (token )
14
+ self ._update_meta (token_info )
11
15
12
- self ._update_meta (token_info )
16
+ @staticmethod
17
+ def _get_token () -> Union [str , None ]:
18
+ transaction = get_transaction ()
19
+ token = transaction .meta .get ("token" )
20
+ return token
13
21
14
22
@staticmethod
15
23
@cache .cacheable (key = "console-api-v2:authentication:{token}" , expire = 300 )
Original file line number Diff line number Diff line change @@ -33,8 +33,7 @@ def _add_paths_from_openapi_json():
33
33
openapi_json_dirs = config .get_global ("OPENAPI_JSON_DIRS" )
34
34
35
35
for openapi_json_dir in openapi_json_dirs :
36
- openapi_json_files = glob .glob (os .path .join (openapi_json_dir ))
37
- if openapi_json_files :
36
+ if openapi_json_files := glob .glob (os .path .join (openapi_json_dir )):
38
37
with open (openapi_json_files [0 ], "r" ) as f :
39
38
openapi_json = json .loads (f .read ())
40
39
for path , value in openapi_json .get ("paths" ).items ():
You can’t perform that action at this time.
0 commit comments