Skip to content

Commit

Permalink
fix: fix create unified cost when workspace is None and has v-workspa…
Browse files Browse the repository at this point in the history
…ce-id

Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Oct 16, 2024
1 parent d283e26 commit 1cbd185
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/spaceone/cost_analysis/service/unified_cost_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,28 +329,30 @@ def create_unified_cost_with_workspace(

identity_mgr = IdentityManager(token=config.get_global("TOKEN"))
workspace_ids = [workspace_id]
workspace_name = None
project_name_map = {}
service_account_name_map = {}

if workspace_id:
workspace_name = identity_mgr.get_workspace(workspace_id, domain_id)
else:
workspace_name = None
v_workspace_ids = self._get_virtual_workspace_ids_from_ds_account(
domain_id, workspace_id
)
if v_workspace_ids:
workspace_ids.extend(v_workspace_ids)

v_workspace_ids = self._get_virtual_workspace_ids_from_ds_account(
domain_id, workspace_id
)
if v_workspace_ids:
workspace_ids.extend(v_workspace_ids)
project_name_map = identity_mgr.get_project_name_map(
domain_id, workspace_id
)

service_account_name_map = identity_mgr.get_service_account_name_map(
domain_id, workspace_id
)

data_source_currency_map, data_source_name_map, data_source_ids = (
self._get_data_source_currency_map(domain_id, workspace_id)
)

project_name_map = identity_mgr.get_project_name_map(domain_id, workspace_id)

service_account_name_map = identity_mgr.get_service_account_name_map(
domain_id, workspace_id
)

unified_cost_billed_year = aggregation_month.split("-")[0]

query = {
Expand Down Expand Up @@ -423,21 +425,22 @@ def create_unified_cost_with_workspace(
aggregated_unified_cost_data["domain_id"] = domain_id

# set workspace name
aggregated_unified_cost_data["workspace_id"] = workspace_id
if workspace_id:
aggregated_unified_cost_data["workspace_id"] = workspace_id
aggregated_unified_cost_data["workspace_name"] = workspace_name
# set project name
project_id = aggregated_unified_cost_data.get("project_id", None)
aggregated_unified_cost_data["project_name"] = project_name_map.get(
project_id, project_id
)

# set project name
project_id = aggregated_unified_cost_data.get("project_id", None)
aggregated_unified_cost_data["project_name"] = project_name_map.get(
project_id, project_id
)

# set service account name
service_account_id = aggregated_unified_cost_data.get("service_account_id")
aggregated_unified_cost_data["service_account_name"] = (
service_account_name_map.get(service_account_id)
)
# set service account name
service_account_id = aggregated_unified_cost_data.get(
"service_account_id"
)
aggregated_unified_cost_data["service_account_name"] = (
service_account_name_map.get(service_account_id)
)

aggregated_unified_cost_data["exchange_date"] = exchange_date_str
aggregated_unified_cost_data["exchange_source"] = exchange_source
Expand Down

0 comments on commit 1cbd185

Please sign in to comment.