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)
| 22 | // This is primarily used by the workspace agent RPC handler to cache workspace |
| 23 | // authorization data for the duration of an agent connection. |
| 24 | func 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. |
| 38 | func WorkspaceRBACFromContext(ctx context.Context) (rbac.Object, bool) { |