Skip to content
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

Add get_accessible_configs api to PublicConfig for USER role_type #12

Merged
merged 1 commit into from
Dec 18, 2024
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
6 changes: 6 additions & 0 deletions src/spaceone/config/interface/grpc/public_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def get(self, request, context):
response: dict = public_config_svc.get(params)
return self.dict_to_message(response)

def get_accessible_configs(self, request, context):
params, metadata = self.parse_request(request, context)
public_config_svc = PublicConfigService(metadata)
response: dict = public_config_svc.get_accessible_configs(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)
public_config_svc = PublicConfigService(metadata)
Expand Down
7 changes: 7 additions & 0 deletions src/spaceone/config/model/public_config/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"PublicConfigSetRequest",
"PublicConfigDeleteRequest",
"PublicConfigGetRequest",
"PublicConfigGetAccessibleConfigRequest",
"PublicConfigSearchQueryRequest",
"PublicConfigQueryRequest",
]
Expand Down Expand Up @@ -61,6 +62,12 @@ class PublicConfigGetRequest(BaseModel):
domain_id: str


class PublicConfigGetAccessibleConfigRequest(BaseModel):
query: Union[dict, None] = None
name: Union[str, None] = None
domain_id: str


class PublicConfigSearchQueryRequest(BaseModel):
query: Union[dict, None] = None
name: Union[str, None] = None
Expand Down
96 changes: 76 additions & 20 deletions src/spaceone/config/service/public_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ def update(self, params: PublicConfigUpdateRequest) -> Union[PublicConfigRespons
# )
# return PublicConfigResponse(**public_config_vo.to_dict())

@transaction(permission="config:PublicConfig.write",
@transaction(permission="config:PublicConfig.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"])
@change_value_by_rule("APPEND", "workspace_id", "*")
@change_value_by_rule("APPEND", "project_id", "*")
@convert_model
def delete(self, params: PublicConfigDeleteRequest) -> None:
"""Delete workspace config
def get(self, params: PublicConfigGetRequest) -> Union[PublicConfigResponse, dict]:
"""Get workspace config

Args:
params (dict): {
Expand All @@ -131,21 +133,71 @@ def delete(self, params: PublicConfigDeleteRequest) -> None:
}

Returns:
None
public_config_vo (object)
"""

workspace_id = params.workspace_id
project_id = params.project_id or params.user_projects
public_config_vo = self.public_config_mgr.get_public_config(params.name, params.domain_id, params.workspace_id,
params.user_projects)

public_config_vo = self.public_config_mgr.get_public_config(params.name, params.domain_id, workspace_id,
project_id)
self.public_config_mgr.delete_public_config_by_vo(public_config_vo)
return PublicConfigResponse(**public_config_vo.to_dict())

@transaction(permission="config:PublicConfig.read",
@transaction(permission="config:PublicConfig.read", role_types=["USER"])
@convert_model
def get_accessible_configs(self, params: PublicConfigGetAccessibleConfigRequest) -> Union[
PublicConfigsResponse, dict]:
"""Get accessible workspace config

Args:
params (dict): {
"query": "dict",
'name': 'str', # required

'domain_id': 'str' # injected from auth
}

Returns:
public_config_vo (object)
"""

query = params.query or {}
if "filter" not in query:
query["filter"] = []

query_filter = [
{
"key": "domain_id",
"value": params.domain_id,
"operator": "eq"
},
{
"key": "resource_group",
"value": "DOMAIN",
"operator": "eq"
}
]

query["filter"].extend(query_filter)

if params.name:
query["filter"].append({
"key": "name ",
"value": params.name,
"operator": "eq"
})

_LOGGER.debug(f'[get_accessible_configs] query: {query}')

public_config_vos, total_count = self.public_config_mgr.list_public_configs(query)

public_configs_info = [public_config_vo.to_dict() for public_config_vo in public_config_vos]

return PublicConfigsResponse(results=public_configs_info, total_count=total_count)

@transaction(permission="config:PublicConfig.write",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"])
@convert_model
def get(self, params: PublicConfigGetRequest) -> Union[PublicConfigResponse, dict]:
"""Get workspace config
def delete(self, params: PublicConfigDeleteRequest) -> None:
"""Delete workspace config

Args:
params (dict): {
Expand All @@ -157,20 +209,22 @@ def get(self, params: PublicConfigGetRequest) -> Union[PublicConfigResponse, dic
}

Returns:
public_config_vo (object)
None
"""

public_config_vo = self.public_config_mgr.get_public_config(params.name, params.domain_id, params.workspace_id,
params.user_projects)
workspace_id = params.workspace_id
project_id = params.project_id or params.user_projects

return PublicConfigResponse(**public_config_vo.to_dict())
public_config_vo = self.public_config_mgr.get_public_config(params.name, params.domain_id, workspace_id,
project_id)
self.public_config_mgr.delete_public_config_by_vo(public_config_vo)

@transaction(permission="config:PublicConfig.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"])
@append_query_filter(["name", "domain_id"])
@append_keyword_filter(["name"])
@change_value_by_rule("APPEND", "workspace_id", "*")
@change_value_by_rule("APPEND", "project_id", "*")
@append_query_filter(["name", "workspace_id", "users_project", "domain_id"])
@convert_model
def list(self, params: PublicConfigSearchQueryRequest) -> Union[PublicConfigsResponse, dict]:
"""List workspace configs
Expand All @@ -191,12 +245,14 @@ def list(self, params: PublicConfigSearchQueryRequest) -> Union[PublicConfigsRes

query = params.query or {}
public_config_vos, total_count = self.public_config_mgr.list_public_configs(query)
workspaces_info = [public_config_vo.to_dict() for public_config_vo in public_config_vos]
return PublicConfigsResponse(results=workspaces_info, total_count=total_count)
public_configs_info = [public_config_vo.to_dict() for public_config_vo in public_config_vos]
return PublicConfigsResponse(results=public_configs_info, total_count=total_count)

@transaction(permission="config:PublicConfig.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"])
@append_query_filter(["workspace_id", "domain_id"])
@change_value_by_rule("APPEND", "workspace_id", "*")
@change_value_by_rule("APPEND", "project_id", "*")
@append_query_filter(["users_project", "workspace_id", "domain_id"])
@append_keyword_filter(["name"])
@convert_model
def stat(self, params: PublicConfigQueryRequest) -> dict:
Expand Down
Loading