Skip to content

Commit

Permalink
Merge pull request #160 from ImMin5/feature-cost-report
Browse files Browse the repository at this point in the history
Modify send cost report link temporay use pat
  • Loading branch information
ImMin5 authored Jan 25, 2024
2 parents ca4d69e + ab1d8bd commit 2ad0b7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/spaceone/cost_analysis/manager/identity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
9 changes: 5 additions & 4 deletions src/spaceone/cost_analysis/service/cost_report_serivce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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

0 comments on commit 2ad0b7c

Please sign in to comment.