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

Method ContextInject

coderd/agentapi/cached_workspace.go:70–82  ·  view source on GitHub ↗

ContextInject attempts to inject the rbac object for the cached workspace fields into the given context, either returning the wrapped context or the original.

(ctx context.Context)

Source from the content-addressed store, hash-verified

68// ContextInject attempts to inject the rbac object for the cached workspace fields
69// into the given context, either returning the wrapped context or the original.
70func (cws *CachedWorkspaceFields) ContextInject(ctx context.Context) (context.Context, error) {
71 var err error
72 rbacCtx := ctx
73 if dbws, ok := cws.AsWorkspaceIdentity(); ok {
74 rbacCtx, err = dbauthz.WithWorkspaceRBAC(ctx, dbws.RBACObject())
75 if err != nil {
76 // Don't error level log here, will exit the function. We want to fall back to GetWorkspaceByAgentID.
77 //nolint:gocritic
78 return ctx, xerrors.Errorf("Cached workspace was present but RBAC object was invalid: %w", err)
79 }
80 }
81 return rbacCtx, nil
82}

Callers

nothing calls this directly

Calls 4

AsWorkspaceIdentityMethod · 0.95
WithWorkspaceRBACFunction · 0.92
RBACObjectMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected