(ctx context.Context, id uuid.UUID)
| 4880 | } |
| 4881 | |
| 4882 | func (q *querier) GetWorkspaceAgentByID(ctx context.Context, id uuid.UUID) (database.WorkspaceAgent, error) { |
| 4883 | // Fast path: Check if we have a workspace RBAC object in context. |
| 4884 | // In the agent API this is set at agent connection time to avoid the expensive |
| 4885 | // GetWorkspaceByAgentID query for every agent operation. |
| 4886 | // NOTE: The cached RBAC object is refreshed every 5 minutes in agentapi/api.go. |
| 4887 | if rbacObj, ok := WorkspaceRBACFromContext(ctx); ok { |
| 4888 | // Errors here will result in falling back to GetWorkspaceByAgentID, |
| 4889 | // in case the cached data is stale. |
| 4890 | if err := q.authorizeContext(ctx, policy.ActionRead, rbacObj); err == nil { |
| 4891 | return q.db.GetWorkspaceAgentByID(ctx, id) |
| 4892 | } |
| 4893 | q.log.Debug(ctx, "fast path authorization failed for GetWorkspaceAgentByID, using slow path", |
| 4894 | slog.F("agent_id", id)) |
| 4895 | } |
| 4896 | |
| 4897 | // Slow path: Fallback to fetching the workspace for authorization |
| 4898 | if _, err := q.GetWorkspaceByAgentID(ctx, id); err != nil { |
| 4899 | return database.WorkspaceAgent{}, err |
| 4900 | } |
| 4901 | return q.db.GetWorkspaceAgentByID(ctx, id) |
| 4902 | } |
| 4903 | |
| 4904 | func (q *querier) GetWorkspaceAgentDevcontainersByAgentID(ctx context.Context, workspaceAgentID uuid.UUID) ([]database.WorkspaceAgentDevcontainer, error) { |
| 4905 | _, err := q.GetWorkspaceAgentByID(ctx, workspaceAgentID) |
no test coverage detected