Skip to content

Commit 1cbd185

Browse files
committed
fix: fix create unified cost when workspace is None and has v-workspace-id
Signed-off-by: ImMin5 <[email protected]>
1 parent d283e26 commit 1cbd185

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/spaceone/cost_analysis/service/unified_cost_service.py

+28-25
Original file line numberDiff line numberDiff line change
@@ -329,28 +329,30 @@ def create_unified_cost_with_workspace(
329329

330330
identity_mgr = IdentityManager(token=config.get_global("TOKEN"))
331331
workspace_ids = [workspace_id]
332+
workspace_name = None
333+
project_name_map = {}
334+
service_account_name_map = {}
332335

333336
if workspace_id:
334337
workspace_name = identity_mgr.get_workspace(workspace_id, domain_id)
335-
else:
336-
workspace_name = None
338+
v_workspace_ids = self._get_virtual_workspace_ids_from_ds_account(
339+
domain_id, workspace_id
340+
)
341+
if v_workspace_ids:
342+
workspace_ids.extend(v_workspace_ids)
337343

338-
v_workspace_ids = self._get_virtual_workspace_ids_from_ds_account(
339-
domain_id, workspace_id
340-
)
341-
if v_workspace_ids:
342-
workspace_ids.extend(v_workspace_ids)
344+
project_name_map = identity_mgr.get_project_name_map(
345+
domain_id, workspace_id
346+
)
347+
348+
service_account_name_map = identity_mgr.get_service_account_name_map(
349+
domain_id, workspace_id
350+
)
343351

344352
data_source_currency_map, data_source_name_map, data_source_ids = (
345353
self._get_data_source_currency_map(domain_id, workspace_id)
346354
)
347355

348-
project_name_map = identity_mgr.get_project_name_map(domain_id, workspace_id)
349-
350-
service_account_name_map = identity_mgr.get_service_account_name_map(
351-
domain_id, workspace_id
352-
)
353-
354356
unified_cost_billed_year = aggregation_month.split("-")[0]
355357

356358
query = {
@@ -423,21 +425,22 @@ def create_unified_cost_with_workspace(
423425
aggregated_unified_cost_data["domain_id"] = domain_id
424426

425427
# set workspace name
428+
aggregated_unified_cost_data["workspace_id"] = workspace_id
426429
if workspace_id:
427-
aggregated_unified_cost_data["workspace_id"] = workspace_id
428430
aggregated_unified_cost_data["workspace_name"] = workspace_name
431+
# set project name
432+
project_id = aggregated_unified_cost_data.get("project_id", None)
433+
aggregated_unified_cost_data["project_name"] = project_name_map.get(
434+
project_id, project_id
435+
)
429436

430-
# set project name
431-
project_id = aggregated_unified_cost_data.get("project_id", None)
432-
aggregated_unified_cost_data["project_name"] = project_name_map.get(
433-
project_id, project_id
434-
)
435-
436-
# set service account name
437-
service_account_id = aggregated_unified_cost_data.get("service_account_id")
438-
aggregated_unified_cost_data["service_account_name"] = (
439-
service_account_name_map.get(service_account_id)
440-
)
437+
# set service account name
438+
service_account_id = aggregated_unified_cost_data.get(
439+
"service_account_id"
440+
)
441+
aggregated_unified_cost_data["service_account_name"] = (
442+
service_account_name_map.get(service_account_id)
443+
)
441444

442445
aggregated_unified_cost_data["exchange_date"] = exchange_date_str
443446
aggregated_unified_cost_data["exchange_source"] = exchange_source

0 commit comments

Comments
 (0)