Skip to content

Commit

Permalink
Merge pull request #330 from yjinjo/master
Browse files Browse the repository at this point in the history
Add list_basic_role method
  • Loading branch information
yjinjo authored Aug 29, 2024
2 parents 263c475 + fd9f6f0 commit fdccf09
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 22 deletions.
9 changes: 8 additions & 1 deletion src/spaceone/identity/interface/grpc/role.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from spaceone.core.pygrpc import BaseAPI
from spaceone.api.identity.v2 import role_pb2, role_pb2_grpc
from spaceone.core.pygrpc import BaseAPI

from spaceone.identity.service.role_service import RoleService


Expand Down Expand Up @@ -49,6 +50,12 @@ def list(self, request, context):
response: dict = endpoint_svc.list(params)
return self.dict_to_message(response)

def list_basic_role(self, request, context):
params, metadata = self.parse_request(request, context)
endpoint_svc = RoleService(metadata)
response: dict = endpoint_svc.list_basic_role(params)
return self.dict_to_message(response)

def stat(self, request, context):
params, metadata = self.parse_request(request, context)
endpoint_svc = RoleService(metadata)
Expand Down
12 changes: 6 additions & 6 deletions src/spaceone/identity/manager/role_manager.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from typing import Tuple
from mongoengine import QuerySet

from spaceone.core import utils, cache
from mongoengine import QuerySet
from spaceone.core import cache, utils
from spaceone.core.manager import BaseManager
from spaceone.core.connector.space_connector import SpaceConnector
from spaceone.identity.model.role.database import Role
from spaceone.identity.manager.role_binding_manager import RoleBindingManager
from spaceone.identity.manager.managed_resource_manager import ManagedResourceManager

from spaceone.identity.error.error_role import ERROR_ROLE_IN_USED
from spaceone.identity.manager.managed_resource_manager import ManagedResourceManager
from spaceone.identity.manager.role_binding_manager import RoleBindingManager
from spaceone.identity.model.role.database import Role

_LOGGER = logging.getLogger(__name__)

Expand Down
17 changes: 9 additions & 8 deletions src/spaceone/identity/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from spaceone.identity.model.agent.database import Agent
from spaceone.identity.model.app.database import App
from spaceone.identity.model.domain.database import Domain
from spaceone.identity.model.external_auth.database import ExternalAuth
from spaceone.identity.model.workspace.database import Workspace
from spaceone.identity.model.project_group.database import ProjectGroup
from spaceone.identity.model.job.database import Job
from spaceone.identity.model.project.database import Project
from spaceone.identity.model.project_group.database import ProjectGroup
from spaceone.identity.model.provider.database import Provider
from spaceone.identity.model.schema.database import Schema
from spaceone.identity.model.trusted_account.database import TrustedAccount
from spaceone.identity.model.service_account.database import ServiceAccount
from spaceone.identity.model.job.database import Job
from spaceone.identity.model.role.database import Role
from spaceone.identity.model.role_binding.database import RoleBinding
from spaceone.identity.model.schema.database import Schema
from spaceone.identity.model.service_account.database import ServiceAccount
from spaceone.identity.model.trusted_account.database import TrustedAccount
from spaceone.identity.model.user.database import User
from spaceone.identity.model.user_group.database import UserGroup
from spaceone.identity.model.app.database import App
from spaceone.identity.model.agent.database import Agent
from spaceone.identity.model.workspace.database import Workspace
from spaceone.identity.model.workspace_group.database import WorkspaceGroup
12 changes: 11 additions & 1 deletion src/spaceone/identity/model/role/request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Union, List, Literal
from typing import List, Literal, Union

from pydantic import BaseModel

__all__ = [
Expand Down Expand Up @@ -65,6 +66,15 @@ class RoleSearchQueryRequest(BaseModel):
domain_id: str


class BasicRoleSearchQueryRequest(BaseModel):
query: Union[dict, None] = None
role_id: Union[str, None] = None
name: Union[str, None] = None
state: Union[State, None] = None
role_type: Union[RoleType, None] = None
domain_id: str


class RoleStatQueryRequest(BaseModel):
query: dict
domain_id: str
26 changes: 24 additions & 2 deletions src/spaceone/identity/model/role/response.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime
from typing import Union, List
from typing import List, Union

from pydantic import BaseModel
from spaceone.core import utils

from spaceone.identity.model.role.request import RoleType, State

__all__ = ["RoleResponse", "RolesResponse"]
__all__ = ["RoleResponse", "RolesResponse", "BasicRoleResponse", "BasicRolesResponse"]


class RoleResponse(BaseModel):
Expand All @@ -31,3 +32,24 @@ def dict(self, *args, **kwargs):
class RolesResponse(BaseModel):
results: List[RoleResponse]
total_count: int


class BasicRoleResponse(BaseModel):
role_id: Union[str, None] = None
name: Union[str, None] = None
state: Union[State, None] = None
role_type: Union[RoleType, None] = None
domain_id: Union[str, None] = None
created_at: Union[datetime, None] = None
updated_at: Union[datetime, None] = None

def dict(self, *args, **kwargs):
data = super().dict(*args, **kwargs)
data["created_at"] = utils.datetime_to_iso8601(data["created_at"])
data["updated_at"] = utils.datetime_to_iso8601(data["updated_at"])
return data


class BasicRolesResponse(BaseModel):
results: List[BasicRoleResponse]
total_count: int
39 changes: 35 additions & 4 deletions src/spaceone/identity/service/role_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging
from typing import Union
from spaceone.core import config

from spaceone.core.error import *
from spaceone.core.service import *
from spaceone.core.service.utils import *
from spaceone.core.error import *

from spaceone.identity.manager.role_manager import RoleManager
from spaceone.identity.model.role.request import *
from spaceone.identity.model.role.request import BasicRoleSearchQueryRequest
from spaceone.identity.model.role.response import *
from spaceone.identity.manager.role_manager import RoleManager
from spaceone.identity.manager.domain_manager import DomainManager

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -187,6 +186,38 @@ def list(self, params: RoleSearchQueryRequest) -> Union[RolesResponse, dict]:
roles_info = [role_vo.to_dict() for role_vo in role_vos]
return RolesResponse(results=roles_info, total_count=total_count)

@transaction(
permission="identity:Role.read",
role_types=["USER"],
)
@append_query_filter(["role_id", "name", "state", "role_type", "domain_id"])
@append_keyword_filter(["role_id", "name"])
@convert_model
def list_basic_role(
self, params: BasicRoleSearchQueryRequest
) -> Union[BasicRolesResponse, dict]:
"""list basic roles
Args:
params (RoleSearchQueryRequest): {
'query': 'dict (spaceone.api.core.v1.Query)',
'role_id': 'str',
'name': 'str',
'state': 'str',
'role_type': 'str',
'domain_id': 'str', # injected from auth (required)
}
Returns:
BasicRolesResponse:
"""

query = params.query or {}
role_vos, total_count = self.role_mgr.list_roles(query, params.domain_id)

basic_roles_info = [role_vo.to_dict() for role_vo in role_vos]
return BasicRolesResponse(results=basic_roles_info, total_count=total_count)

@transaction(
permission="identity:Role.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"],
Expand Down

0 comments on commit fdccf09

Please sign in to comment.