Skip to content

Commit

Permalink
fix: modify list api_key filter (#73)
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Dec 8, 2023
1 parent 7821c63 commit 79f9684
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
24 changes: 17 additions & 7 deletions src/spaceone/identity/service/api_key_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def create(self, params: APIKeyCreateRequest) -> Union[APIKeyResponse, dict]:
APIKeyResponse:
"""

params.expired_at = params.expired_at or datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"
)
params.expired_at = self._get_expired_at(params.expired_at)
self._check_expired_at(params.expired_at)

user_mgr = UserManager()
Expand Down Expand Up @@ -175,9 +173,7 @@ def get(self, params: APIKeyGetRequest) -> Union[APIKeyResponse, dict]:
return APIKeyResponse(**api_key_vo.to_dict())

@transaction(scope="user:read")
@append_query_filter(
["api_key_id", "name", "owner_type", "user_id", "state", "domain_id"]
)
@append_query_filter(["api_key_id", "name", "user_id", "state", "domain_id"])
@append_keyword_filter(["api_key_id", "name"])
@convert_model
def list(self, params: APIKeySearchQueryRequest) -> Union[APIKeysResponse, dict]:
Expand All @@ -196,7 +192,9 @@ def list(self, params: APIKeySearchQueryRequest) -> Union[APIKeysResponse, dict]
APIKeysResponse:
"""

query = params.query or {}
query = params.query
query = self._append_owner_type_filter(query)

api_key_vos, total_count = self.api_key_mgr.list_api_keys(query)
api_keys_info = [api_key_vo.to_dict() for api_key_vo in api_key_vos]
return APIKeysResponse(results=api_keys_info, total_count=total_count)
Expand All @@ -223,6 +221,18 @@ def stat(self, params: APIKeyStatQueryRequest) -> dict:
query = params.query or {}
return self.api_key_mgr.stat_api_keys(query)

@staticmethod
def _append_owner_type_filter(query: dict):
query.get("filter", []).append({"k": "owner_type", "v": "USER", "o": "eq"})
return query

@staticmethod
def _get_expired_at(expired_at: str) -> str:
if expired_at:
return expired_at
else:
return (datetime.now() + timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S")

@staticmethod
def _check_expired_at(expired_at: str) -> None:
one_year_later = datetime.now() + timedelta(days=365)
Expand Down
14 changes: 9 additions & 5 deletions src/spaceone/identity/service/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from spaceone.identity.error.error_api_key import *
from spaceone.identity.manager.app_manager import AppManager
from spaceone.identity.manager.api_key_manager import APIKeyManager
from spaceone.identity.manager.role_manager import RoleManager
from spaceone.identity.manager.workspace_manager import WorkspaceManager
from spaceone.identity.model.app.request import *
from spaceone.identity.model.app.response import *

Expand Down Expand Up @@ -37,12 +37,9 @@ def create(self, params: AppCreateRequest) -> Union[AppResponse, dict]:
Return:
AppResponse:
"""
params.expired_at = params.expired_at or datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"
)
params.expired_at = self._get_expired_at(params.expired_at)
self._check_expired_at(params.expired_at)

# 퍼미션 그룹에 따라 롤 타입 체크
# Check workspace
if params.permission_group == "WORKSPACE":
workspace_mgr = WorkspaceManager()
Expand Down Expand Up @@ -256,6 +253,13 @@ def stat(self, params: AppStatQueryRequest) -> dict:
query = params.query or {}
return self.app_mgr.stat_apps(query)

@staticmethod
def _get_expired_at(expired_at: str) -> str:
if expired_at:
return expired_at
else:
return (datetime.now() + timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S")

@staticmethod
def _check_expired_at(expired_at: str) -> None:
one_year_later = datetime.now() + timedelta(days=365)
Expand Down

0 comments on commit 79f9684

Please sign in to comment.