diff --git a/src/spaceone/identity/service/api_key_service.py b/src/spaceone/identity/service/api_key_service.py index cba07ba7..cb209d94 100644 --- a/src/spaceone/identity/service/api_key_service.py +++ b/src/spaceone/identity/service/api_key_service.py @@ -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() @@ -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]: @@ -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) @@ -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) diff --git a/src/spaceone/identity/service/app_service.py b/src/spaceone/identity/service/app_service.py index a790e583..4d8ac9f5 100644 --- a/src/spaceone/identity/service/app_service.py +++ b/src/spaceone/identity/service/app_service.py @@ -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 * @@ -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() @@ -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)