Skip to content

Commit

Permalink
Merge pull request #240 from ImMin5/feature-service-accont-auto-sync
Browse files Browse the repository at this point in the history
Modify unique rule for service account name
  • Loading branch information
ImMin5 authored Apr 4, 2024
2 parents 23f1362 + 1a746fc commit de9dcc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/spaceone/identity/manager/resource_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
from typing import Union

from spaceone.core.manager import BaseManager
from spaceone.core.error import ERROR_NOT_FOUND

from spaceone.identity.error.custom import ERROR_MANAGED_RESOURCE_CAN_NOT_BE_MODIFIED
from spaceone.identity.model.service_account.database import ServiceAccount
Expand All @@ -9,6 +11,8 @@
from spaceone.identity.model.project_group.database import ProjectGroup
from spaceone.identity.model.workspace.database import Workspace

_LOGGER = logging.getLogger(__name__)


class ResourceManager(BaseManager):
def __init__(self, *args, **kwargs):
Expand All @@ -19,10 +23,16 @@ def check_is_managed_resource(
self,
resource_vo: Union[ServiceAccount, Project, ProjectGroup, Workspace],
) -> None:
if resource_vo.is_managed:
trusted_account_vo = self.trusted_account_model.get(
trusted_account_id=resource_vo.trusted_account_id,
domain_id=resource_vo.domain_id,
try:
if resource_vo.is_managed:
trusted_account_vo = self.trusted_account_model.get(
trusted_account_id=resource_vo.trusted_account_id,
domain_id=resource_vo.domain_id,
)
if trusted_account_vo.schedule.get("state") != "ENABLED":
raise ERROR_MANAGED_RESOURCE_CAN_NOT_BE_MODIFIED()
except ERROR_NOT_FOUND:
_LOGGER.debug(
f"[check_is_managed_resource] TrustedAccount not found. (trusted_account_id={resource_vo.trusted_account_id})"
)
if trusted_account_vo.schedule.get("state") != "ENABLED":
raise ERROR_MANAGED_RESOURCE_CAN_NOT_BE_MODIFIED()
return
2 changes: 1 addition & 1 deletion src/spaceone/identity/model/service_account/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ServiceAccount(MongoModel):
service_account_id = StringField(max_length=40, generate_id="sa", unique=True)
name = StringField(max_length=255, unique_with=["domain_id"])
name = StringField(max_length=255, unique_with=["project_id"])
data = DictField(default=None)
provider = StringField(max_length=40)
options = DictField(default=None)
Expand Down

0 comments on commit de9dcc6

Please sign in to comment.