Skip to content

Commit ecd41db

Browse files
committed
feat: add PyJwt package
Signed-off-by: ImMin5 <[email protected]>
1 parent 415a725 commit ecd41db

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

pkg/pip_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
spaceone-api
22
typing-inspect
33
python-multipart
4+
PyJWT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from cloudforet.console_api_v2.handler.authentication_handler import (
2+
ConsoleAPIAuthenticationHandler,
3+
)

src/cloudforet/console_api_v2/handler/authentication_handler.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import jwt
2+
from typing import Union
3+
24
from spaceone.core import cache
35
from spaceone.core.error import ERROR_PERMISSION_DENIED
46
from spaceone.core.handler.authentication_handler import SpaceONEAuthenticationHandler
7+
from spaceone.core.transaction import get_transaction
58

69

710
class ConsoleAPIAuthenticationHandler(SpaceONEAuthenticationHandler):
811
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)
1115

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
1321

1422
@staticmethod
1523
@cache.cacheable(key="console-api-v2:authentication:{token}", expire=300)

src/cloudforet/console_api_v2/interface/rest/proxy.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def _add_paths_from_openapi_json():
3333
openapi_json_dirs = config.get_global("OPENAPI_JSON_DIRS")
3434

3535
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)):
3837
with open(openapi_json_files[0], "r") as f:
3938
openapi_json = json.loads(f.read())
4039
for path, value in openapi_json.get("paths").items():

0 commit comments

Comments
 (0)