MCPcopy Index your code
hub / github.com/coder/coder / GetWorkspaceAgentByID

Method GetWorkspaceAgentByID

coderd/database/dbauthz/dbauthz.go:4882–4902  ·  view source on GitHub ↗
(ctx context.Context, id uuid.UUID)

Source from the content-addressed store, hash-verified

4880}
4881
4882func (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
4904func (q *querier) GetWorkspaceAgentDevcontainersByAgentID(ctx context.Context, workspaceAgentID uuid.UUID) ([]database.WorkspaceAgentDevcontainer, error) {
4905 _, err := q.GetWorkspaceAgentByID(ctx, workspaceAgentID)

Calls 4

authorizeContextMethod · 0.95
GetWorkspaceByAgentIDMethod · 0.95
WorkspaceRBACFromContextFunction · 0.85
GetWorkspaceAgentByIDMethod · 0.65

Tested by

no test coverage detected