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

Method UpdateWorkspaceAgentMetadata

coderd/database/dbauthz/dbauthz.go:7778–7806  ·  view source on GitHub ↗
(ctx context.Context, arg database.UpdateWorkspaceAgentMetadataParams)

Source from the content-addressed store, hash-verified

7776}
7777
7778func (q *querier) UpdateWorkspaceAgentMetadata(ctx context.Context, arg database.UpdateWorkspaceAgentMetadataParams) error {
7779 // Fast path: Check if we have an RBAC object in context.
7780 // This is set by the workspace agent RPC handler to avoid the expensive
7781 // GetWorkspaceByAgentID query for every metadata update.
7782 // NOTE: The cached RBAC object is refreshed every 5 minutes in agentapi/api.go.
7783 if rbacObj, ok := WorkspaceRBACFromContext(ctx); ok {
7784 // Errors here will result in falling back to the GetWorkspaceAgentByID query, skipping
7785 // the cache in case the cached data is stale.
7786 if err := q.authorizeContext(ctx, policy.ActionUpdate, rbacObj); err == nil {
7787 return q.db.UpdateWorkspaceAgentMetadata(ctx, arg)
7788 }
7789 q.log.Debug(ctx, "fast path authorization failed, using slow path",
7790 slog.F("agent_id", arg.WorkspaceAgentID))
7791 }
7792
7793 // Slow path: Fallback to fetching the workspace for authorization if the RBAC object is not present (or is invalid)
7794 // in the request context.
7795 workspace, err := q.db.GetWorkspaceByAgentID(ctx, arg.WorkspaceAgentID)
7796 if err != nil {
7797 return err
7798 }
7799
7800 err = q.authorizeContext(ctx, policy.ActionUpdate, workspace)
7801 if err != nil {
7802 return err
7803 }
7804
7805 return q.db.UpdateWorkspaceAgentMetadata(ctx, arg)
7806}
7807
7808func (q *querier) UpdateWorkspaceAgentStartupByID(ctx context.Context, arg database.UpdateWorkspaceAgentStartupByIDParams) error {
7809 agent, err := q.db.GetWorkspaceAgentByID(ctx, arg.ID)

Callers

nothing calls this directly

Calls 4

authorizeContextMethod · 0.95
WorkspaceRBACFromContextFunction · 0.85
GetWorkspaceByAgentIDMethod · 0.65

Tested by

no test coverage detected