(ctx context.Context, arg database.UpdateWorkspaceAgentMetadataParams)
| 7776 | } |
| 7777 | |
| 7778 | func (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 | |
| 7808 | func (q *querier) UpdateWorkspaceAgentStartupByID(ctx context.Context, arg database.UpdateWorkspaceAgentStartupByIDParams) error { |
| 7809 | agent, err := q.db.GetWorkspaceAgentByID(ctx, arg.ID) |
nothing calls this directly
no test coverage detected