Skip to content

Commit b6f5d00

Browse files
author
Youngjin Jo
committed
2 parents 49c205b + 31ec8b4 commit b6f5d00

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/spaceone/identity/service/job_service.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def sync_service_accounts(self, params: dict) -> None:
263263
if trusted_account_vo.resource_group == "DOMAIN":
264264
if not sync_options.get("single_workspace_id"):
265265
workspace_vo = self._create_workspace(
266-
domain_id, location.pop(0)
266+
domain_id, trusted_account_id, location.pop(0)
267267
)
268268
else:
269269
workspace_vo = self.workspace_mgr.get_workspace(
@@ -479,28 +479,36 @@ def _close_job(
479479
elif job_vo.status == "FAILURE":
480480
self.job_mgr.update_job_by_vo({"finished_at": datetime.utcnow()}, job_vo)
481481

482-
def _create_workspace(self, domain_id: str, location_info: dict) -> Workspace:
482+
def _create_workspace(
483+
self, domain_id: str, trusted_account_id: str, location_info: dict
484+
) -> Workspace:
483485
name = location_info.get("name")
484486
reference_id = location_info.get("resource_id")
485487
workspace_vos = self.workspace_mgr.filter_workspaces(
486-
domain_id=domain_id, name=name
488+
domain_id=domain_id, reference_id=reference_id, is_managed=True
487489
)
490+
491+
params = {"trusted_account_id": trusted_account_id}
488492
if workspace_vos:
489493
workspace_vo = workspace_vos[0]
494+
if workspace_vo.name != name:
495+
params.update({"name": name})
496+
params.update({"last_synced_at": datetime.utcnow()})
490497
workspace_vo = self.workspace_mgr.update_workspace_by_vo(
491-
{"last_synced_at": datetime.utcnow()}, workspace_vo
498+
params, workspace_vo
492499
)
493500
else:
494-
workspace_vo = self.workspace_mgr.create_workspace(
501+
params.update(
495502
{
496-
"domain_id": domain_id,
497503
"name": name,
498504
"is_managed": True,
505+
"tags": self._set_workspace_theme(),
499506
"reference_id": reference_id,
507+
"domain_id": domain_id,
500508
"last_synced_at": datetime.utcnow(),
501-
"tags": self._set_workspace_theme(),
502509
}
503510
)
511+
workspace_vo = self.workspace_mgr.create_workspace(params)
504512
return workspace_vo
505513

506514
def _create_project_group(
@@ -514,20 +522,16 @@ def _create_project_group(
514522
name = location_info["name"]
515523
reference_id = location_info["resource_id"]
516524

517-
query_filter = {
518-
"filter": [
519-
{"k": "is_managed", "v": True, "o": "eq"},
520-
{"k": "reference_id", "v": reference_id, "o": "eq"},
521-
{"k": "domain_id", "v": domain_id, "o": "eq"},
522-
{"k": "workspace_id", "v": workspace_id, "o": "eq"},
523-
]
525+
conditions = {
526+
"is_managed": True,
527+
"reference_id": reference_id,
528+
"domain_id": domain_id,
529+
"workspace_id": workspace_id,
524530
}
525531
if parent_group_id:
526-
query_filter["filter"].append(
527-
{"k": "parent_group_id", "v": parent_group_id, "o": "eq"}
528-
)
532+
conditions["parent_group_id"] = parent_group_id
529533

530-
project_group_vos, _ = self.project_group_mgr.list_project_groups(query_filter)
534+
project_group_vos = self.project_group_mgr.filter_project_groups(**conditions)
531535

532536
params = {
533537
"trusted_account_id": trusted_account_id,

0 commit comments

Comments
 (0)