From ab1d8bdfe832e61005436b7e69516410a99988bd Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Fri, 26 Jan 2024 07:48:55 +0900 Subject: [PATCH] feat: modify send cost report link temporay use pat --- .../cost_analysis/manager/identity_manager.py | 12 +++++++++++- .../cost_analysis/service/cost_report_serivce.py | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/spaceone/cost_analysis/manager/identity_manager.py b/src/spaceone/cost_analysis/manager/identity_manager.py index 9dd4b826..ef568d9a 100644 --- a/src/spaceone/cost_analysis/manager/identity_manager.py +++ b/src/spaceone/cost_analysis/manager/identity_manager.py @@ -21,9 +21,10 @@ def __init__(self, *args, **kwargs): def get_domain_name(self, domain_id: str) -> str: system_token = config.get_global("TOKEN") - self.identity_conn.dispatch( + domain_info = self.identity_conn.dispatch( "Domain.get", {"domain_id": domain_id}, token=system_token ) + return domain_info["name"] def check_workspace(self, workspace_id: str, domain_id: str) -> None: system_token = config.get_global("TOKEN") @@ -136,3 +137,12 @@ def list_role_bindings(self, params: dict, domain_id: str) -> dict: ) else: return self.identity_conn.dispatch("RoleBinding.list", params) + + def grant_token( + self, + params: dict, + ) -> str: + if self.token_type == "SYSTEM_TOKEN": + return "system_token" + else: + return self.transaction.get_meta("token") diff --git a/src/spaceone/cost_analysis/service/cost_report_serivce.py b/src/spaceone/cost_analysis/service/cost_report_serivce.py index 873bfc15..7cd2f3a6 100644 --- a/src/spaceone/cost_analysis/service/cost_report_serivce.py +++ b/src/spaceone/cost_analysis/service/cost_report_serivce.py @@ -350,9 +350,9 @@ def send_cost_report(self, cost_report_vo: CostReport) -> None: params={"workspace_id": workspace_id, "state": "ENABLED"}, domain_id=domain_id, ) - # sso_access_token = self._get_temporary_sso_access_token(domain_id) + sso_access_token = self._get_temporary_sso_access_token(domain_id) cost_report_link = self._get_console_cost_report_url( - domain_id, cost_report_vo.cost_report_id, "token" + domain_id, cost_report_vo.cost_report_id, sso_access_token ) for user_info in users_info.get("results", []): user_id = user_info["user_id"] @@ -473,7 +473,8 @@ def _get_temporary_sso_access_token(self, domain_id: str) -> str: params = { "grant_type": "SYSTEM_TOKEN", "scope": "SYSTEM", + "token": system_token, } # todo : make temporary token - token_info = identity_mgr.grant_token({"token_type"}, token=system_token) - return token_info["access_token"] + token = identity_mgr.grant_token(params) + return token