Skip to content

Fix update service_account_mgr_id error #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/spaceone/identity/model/service_account/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ServiceAccount(MongoModel):
"tags",
"is_managed",
"cost_info",
"service_account_mgr_id",
"secret_schema_id",
"secret_id",
"trusted_account_id",
Expand Down
48 changes: 34 additions & 14 deletions src/spaceone/identity/service/service_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,23 @@ def update(
)

# check service_account_mgr_id is valid in changed project
if (
params.project_id
and service_account_vo.service_account_mgr_id
and service_account_vo.project_id != params.project_id
):
if params.service_account_mgr_id:
self._check_service_account_mgr_exist(
params.service_account_mgr_id, params.domain_id, params.workspace_id
)

project_vo = self.project_mgr.get_project(
project_id=params.project_id,
domain_id=params.domain_id,
workspace_id=params.workspace_id,
user_projects=params.user_projects,
service_account_vo.project_id,
params.domain_id,
params.workspace_id,
params.user_projects,
)

if (
project_vo.project_type == "PRIVATE"
and service_account_vo.service_account_mgr_id not in project_vo.users
):
params.service_account_mgr_id = None
if project_vo.project_type == "PRIVATE":
project_users = project_vo.users or []
users = list(set(project_users + [params.service_account_mgr_id]))
add_member_params = {"users": users}
self.project_mgr.update_project_by_vo(add_member_params, project_vo)

# change secret's project_id
if (
Expand Down Expand Up @@ -627,3 +627,23 @@ def _create_service_account_app_client_secret(
@staticmethod
def _get_expired_at() -> str:
return (datetime.utcnow() + timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S")

def _check_service_account_mgr_exist(
self,
service_account_mgr_id: str,
domain_id: str,
workspace_id: str,
) -> None:

# check user_id is valid
self.user_mgr.get_user(user_id=service_account_mgr_id, domain_id=domain_id)

rb_vos = self.rb_mgr.filter_role_bindings(
user_id=service_account_mgr_id,
workspace_id=workspace_id,
domain_id=domain_id,
)
if rb_vos.count() == 0:
raise ERROR_NOT_FOUND(
key="service_account_mgr_id", value=service_account_mgr_id
)
Loading