Skip to content

Commit

Permalink
feat: modify field 'reference_id' -> 'references' at WorkspaceInfo
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Apr 22, 2024
1 parent b447236 commit 70ba12d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/spaceone/identity/model/workspace/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Workspace(MongoModel):
)
tags = DictField(default=None)
created_by = StringField(max_length=255)
reference_id = StringField(max_length=255, default=None, null=True)
references = ListField(StringField(max_length=255), default=None, null=True)
is_managed = BooleanField(default=False)
trusted_account_id = StringField(max_length=40, default=None, null=True)
domain_id = StringField(max_length=40)
Expand All @@ -28,6 +28,7 @@ class Workspace(MongoModel):
"tags",
"is_managed",
"trusted_account_id",
"references",
"deleted_at",
"last_synced_at",
],
Expand All @@ -37,6 +38,9 @@ class Workspace(MongoModel):
"state",
"is_managed",
],
"change_query_keys": {
"reference_id": "references",
},
"ordering": ["name"],
"indexes": ["name", "domain_id"],
}
Expand Down
2 changes: 1 addition & 1 deletion src/spaceone/identity/model/workspace/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WorkspaceResponse(BaseModel):
state: Union[State, None] = None
tags: Union[dict, None] = None
created_by: Union[str, None] = None
reference_id: Union[str, None] = None
references: Union[list, None] = None
is_managed: Union[bool, None] = None
trusted_account_id: Union[str, None] = None
domain_id: Union[str, None] = None
Expand Down
20 changes: 20 additions & 0 deletions src/spaceone/identity/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,26 @@ def _create_workspace(
params = {"trusted_account_id": trusted_account_id, "is_managed": True}
if workspace_vos:
workspace_vo = workspace_vos[0]

if workspace_vo.name != name:
params.update({"name": name})
if workspace_vo.references not in reference_id:
params.update({"references": workspace_vo.references + [reference_id]})

params.update({"last_synced_at": datetime.utcnow()})
workspace_vo = self.workspace_mgr.update_workspace_by_vo(
params, workspace_vo
)

self._remove_old_reference_id_from_workspace(domain_id, reference_id)
else:
params.update(
{
"name": name,
"tags": self._set_workspace_theme(),
"domain_id": domain_id,
"last_synced_at": datetime.utcnow(),
"references": [reference_id],
}
)
workspace_vo = self.workspace_mgr.create_workspace(params)
Expand Down Expand Up @@ -713,6 +720,19 @@ def _create_service_account(
)
return service_account_vo

def _remove_old_reference_id_from_workspace(
self, domain_id: str, reference_id: str
) -> None:
workspace_vos = self.workspace_mgr.filter_workspaces(
domain_id=domain_id, references=[reference_id]
)
for workspace_vo in workspace_vos:
references = workspace_vo.references
references.remove(reference_id)
self.workspace_mgr.update_workspace_by_vo(
{"references": references}, workspace_vo
)

@staticmethod
def _get_location(result: dict, resource_group: str, sync_options: dict) -> list:
location = result.get("location", [])
Expand Down

0 comments on commit 70ba12d

Please sign in to comment.