| 346 | } |
| 347 | |
| 348 | func (a *SubAgentAPI) ListSubAgents(ctx context.Context, _ *agentproto.ListSubAgentsRequest) (*agentproto.ListSubAgentsResponse, error) { |
| 349 | //nolint:gocritic // This gives us only the permissions required to do the job. |
| 350 | ctx = dbauthz.AsSubAgentAPI(ctx, a.OrganizationID, a.OwnerID) |
| 351 | |
| 352 | parentAgent, err := a.AgentFn(ctx) |
| 353 | if err != nil { |
| 354 | return nil, xerrors.Errorf("get parent agent: %w", err) |
| 355 | } |
| 356 | |
| 357 | workspaceAgents, err := a.Database.GetWorkspaceAgentsByParentID(ctx, parentAgent.ID) |
| 358 | if err != nil { |
| 359 | return nil, err |
| 360 | } |
| 361 | |
| 362 | agents := make([]*agentproto.SubAgent, len(workspaceAgents)) |
| 363 | |
| 364 | for i, agent := range workspaceAgents { |
| 365 | agents[i] = &agentproto.SubAgent{ |
| 366 | Name: agent.Name, |
| 367 | Id: agent.ID[:], |
| 368 | AuthToken: agent.AuthToken[:], |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | return &agentproto.ListSubAgentsResponse{Agents: agents}, nil |
| 373 | } |