Skip to content

Commit

Permalink
fix: fix service account search error
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMin5 committed Mar 12, 2024
1 parent 683b25a commit cfe35f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/cloudforet/search/conf/search_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{"data.account_id": "account"},
{"data.subscription_id": "account"},
{"data.project_id": "account"},
{"service_account_id": "account"},
],
},
},
Expand Down
57 changes: 29 additions & 28 deletions src/cloudforet/search/service/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def search(self, params: ResourceSearchRequest) -> Union[ResourcesResponse, dict
elif params.workspace_id:
find_filter["$and"].append({"workspace_id": params.workspace_id})
if (
params.user_projects
and resource_type not in DISABLED_PROJECT_RESOURCE_TYPES
params.user_projects
and resource_type not in DISABLED_PROJECT_RESOURCE_TYPES
):
find_filter["$and"].append(
{"project_id": {"$in": params.user_projects}}
Expand Down Expand Up @@ -158,10 +158,10 @@ def check_resource_type(self, resource_type: str):
)

def _get_all_workspaces(
self,
domain_id: str,
role_type: str,
user_id: str = None,
self,
domain_id: str,
role_type: str,
user_id: str = None,
) -> list:
identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")

Expand All @@ -178,7 +178,7 @@ def _get_all_workspaces(
return workspaces

def _get_all_projects(
self, domain_id: str, workspace_id: str, user_id: str = None
self, domain_id: str, workspace_id: str, user_id: str = None
) -> list:
user_projects = []

Expand All @@ -202,10 +202,10 @@ def _get_all_projects(
return user_projects

def _get_workspace_project_map(
self,
domain_id: str,
workspaces: list,
user_id: str,
self,
domain_id: str,
workspaces: list,
user_id: str,
) -> dict:
workspace_project_map = {}
for workspace_id in workspaces:
Expand All @@ -216,11 +216,11 @@ def _get_workspace_project_map(
return workspace_project_map

def _get_accessible_workspaces(
self,
domain_id: str,
role_type: str,
workspaces: list = None,
user_id: str = None,
self,
domain_id: str,
role_type: str,
workspaces: list = None,
user_id: str = None,
) -> list:
# check is accessible workspace with params.workspaces
workspace_ids = self._get_all_workspaces(domain_id, role_type, user_id)
Expand All @@ -232,7 +232,7 @@ def _get_accessible_workspaces(
return workspaces

def _make_find_filter_by_resource_type(
self, find_filter: dict, resource_type: str, regex_pattern: str
self, find_filter: dict, resource_type: str, regex_pattern: str
) -> dict:
if search_target := self.search_conf.get(resource_type):
or_filter = {"$or": []}
Expand All @@ -250,7 +250,7 @@ def _make_find_filter_by_resource_type(
return find_filter

def _make_response(
self, results: list, next_token: str, response_conf: dict
self, results: list, next_token: str, response_conf: dict
) -> dict:
name_format = response_conf["name"]
description_format = response_conf.get("description")
Expand All @@ -276,12 +276,12 @@ def _make_response(
}

def _encode_next_token_base64(
self,
results: list,
resource_type: str,
find_filter: dict,
limit: int,
page: int,
self,
results: list,
resource_type: str,
find_filter: dict,
limit: int,
page: int,
) -> Union[str, None]:
if limit == 0 or len(results) != limit:
return None
Expand Down Expand Up @@ -315,8 +315,8 @@ def _decode_next_token(self, resource_type: str, next_token: str) -> dict:

@staticmethod
def _make_filter_by_workspaces(
find_filter: dict,
workspaces: list,
find_filter: dict,
workspaces: list,
):
if workspaces:
find_filter["$and"].append({"$or": [{"workspace_id": {"$in": workspaces}}]})
Expand All @@ -326,7 +326,7 @@ def _make_filter_by_workspaces(

@staticmethod
def _make_filter_by_workspace_project_map(
find_filter: dict, workspace_project_map: dict
find_filter: dict, workspace_project_map: dict
):
or_filter = {"$or": []}
for workspace_id, user_projects in workspace_project_map.items():
Expand Down Expand Up @@ -363,7 +363,8 @@ def _convert_result_by_alias(result: dict, aliases: list) -> dict:
for alias in aliases:
for target_field, alias_name in alias.items():
if value := get_dict_value(result, target_field):
result[alias_name] = value
if not result.get(alias_name):
result[alias_name] = value
return result

@staticmethod
Expand Down

0 comments on commit cfe35f5

Please sign in to comment.