Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyJwt package #112

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/pip_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spaceone-api
typing-inspect
python-multipart
PyJWT
3 changes: 3 additions & 0 deletions src/cloudforet/console_api_v2/handler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cloudforet.console_api_v2.handler.authentication_handler import (
ConsoleAPIAuthenticationHandler,
)
14 changes: 11 additions & 3 deletions src/cloudforet/console_api_v2/handler/authentication_handler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import jwt
from typing import Union

from spaceone.core import cache
from spaceone.core.error import ERROR_PERMISSION_DENIED
from spaceone.core.handler.authentication_handler import SpaceONEAuthenticationHandler
from spaceone.core.transaction import get_transaction


class ConsoleAPIAuthenticationHandler(SpaceONEAuthenticationHandler):
def verify(self, params: dict) -> None:
token = self._get_token()
token_info = self._extract_token_info(token)
if token := self._get_token():
token_info = self._extract_token_info(token)
self._update_meta(token_info)

self._update_meta(token_info)
@staticmethod
def _get_token() -> Union[str, None]:
transaction = get_transaction()
token = transaction.meta.get("token")
return token

@staticmethod
@cache.cacheable(key="console-api-v2:authentication:{token}", expire=300)
Expand Down
3 changes: 1 addition & 2 deletions src/cloudforet/console_api_v2/interface/rest/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def _add_paths_from_openapi_json():
openapi_json_dirs = config.get_global("OPENAPI_JSON_DIRS")

for openapi_json_dir in openapi_json_dirs:
openapi_json_files = glob.glob(os.path.join(openapi_json_dir))
if openapi_json_files:
if openapi_json_files := glob.glob(os.path.join(openapi_json_dir)):
with open(openapi_json_files[0], "r") as f:
openapi_json = json.loads(f.read())
for path, value in openapi_json.get("paths").items():
Expand Down
Loading