Skip to content

Commit

Permalink
Merge pull request #260 from yjinjo/master
Browse files Browse the repository at this point in the history
Add Agent list query
  • Loading branch information
yjinjo authored Apr 12, 2024
2 parents 9621fef + 9a581e6 commit 6082560
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/spaceone/identity/service/agent_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,17 @@ def list(self, params: AgentSearchQueryRequest) -> Union[AgentsResponse, dict]:
agent_vos, agent_total_count = self.agent_mgr.list_agents(query)
agents_info = [agent_vo.to_dict() for agent_vo in agent_vos]

# app_ids = [agent_vo.app_id for agent_vo in agent_vos]
# app_vos, app_total_count = self.app_mgr.list_apps({"app_id": {"$in": app_ids}})
app_ids = [agent_vo.app_id for agent_vo in agent_vos]

return AgentsResponse(results=agents_info, total_count=agent_total_count)
app_vos, app_total_count = self.app_mgr.list_apps(
{"filter": [{"k": "app_id", "v": app_ids, "o": "in"}]}
)

apps_info = [app_vo.to_dict() for app_vo in app_vos]

agents_info = self._update_agents_info_with_apps_info(agents_info, apps_info)

return AgentsResponse(results=agents_info, total_count=len(agents_info))

def _create_agent_client_secret(
self, app_vo: App, service_account_id: str
Expand Down Expand Up @@ -413,8 +420,30 @@ def _update_agent_info_with_app_vo(agent_vo, app_vo):
agent_info["client_id"] = app_vo.client_id
agent_info["expired_at"] = app_vo.expired_at
agent_info["last_accessed_at"] = app_vo.last_accessed_at

return agent_info

@staticmethod
def _update_agents_info_with_apps_info(agents_info, apps_info):
agents_info_with_apps_info = []

for agent_info, app_info in zip(agents_info, apps_info):
agent_info.update(
{
"state": app_info["state"],
"is_managed": app_info["is_managed"],
"role_type": app_info["role_type"],
"role_id": app_info["role_id"],
"app_id": app_info["app_id"],
"client_id": app_info["client_id"],
"expired_at": app_info["expired_at"],
"last_accessed_at": app_info["last_accessed_at"],
}
)
agents_info_with_apps_info.append(agent_info)

return agents_info_with_apps_info

@staticmethod
def _get_expired_at() -> str:
return (datetime.utcnow() + timedelta(days=365)).strftime("%Y-%m-%d %H:%M:%S")

0 comments on commit 6082560

Please sign in to comment.