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

Function WithWorkspaceRBAC

coderd/database/dbauthz/workspace_rbac_context.go:24–35  ·  view source on GitHub ↗

WithWorkspaceRBAC attaches a workspace RBAC object to the context. RBAC fields on this RBAC object should not be used. This is primarily used by the workspace agent RPC handler to cache workspace authorization data for the duration of an agent connection.

(ctx context.Context, rbacObj rbac.Object)

Source from the content-addressed store, hash-verified

22// This is primarily used by the workspace agent RPC handler to cache workspace
23// authorization data for the duration of an agent connection.
24func WithWorkspaceRBAC(ctx context.Context, rbacObj rbac.Object) (context.Context, error) {
25 if rbacObj.Type != rbac.ResourceWorkspace.Type {
26 return ctx, xerrors.New("RBAC Object must be of type Workspace")
27 }
28 if isWorkspaceRBACObjectEmpty(rbacObj) {
29 return ctx, xerrors.Errorf("cannot attach empty RBAC object to context: %+v", rbacObj)
30 }
31 if len(rbacObj.ACLGroupList) != 0 || len(rbacObj.ACLUserList) != 0 {
32 return ctx, xerrors.New("ACL fields for Workspace RBAC object must be nullified, the can be changed during runtime and should not be cached")
33 }
34 return context.WithValue(ctx, workspaceRBACContextKey{}, rbacObj), nil
35}
36
37// WorkspaceRBACFromContext attempts to retrieve the workspace RBAC object from context.
38func WorkspaceRBACFromContext(ctx context.Context) (rbac.Object, bool) {

Callers 4

monitorMethod · 0.92
ContextInjectMethod · 0.92

Calls 3

NewMethod · 0.65
ErrorfMethod · 0.45