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

Function As

coderd/database/dbauthz/dbauthz.go:889–899  ·  view source on GitHub ↗

As returns a context with the given actor stored in the context. This is used for cases where the actor touching the database is not the actor stored in the context. When you use this function, be sure to add a //nolint comment explaining why it is necessary.

(ctx context.Context, actor rbac.Subject)

Source from the content-addressed store, hash-verified

887// When you use this function, be sure to add a //nolint comment
888// explaining why it is necessary.
889func As(ctx context.Context, actor rbac.Subject) context.Context {
890 if actor.Equal(AsRemoveActor) {
891 // AsRemoveActor is a special case that is used to indicate that the actor
892 // should be removed from the context.
893 return context.WithValue(ctx, authContextKey{}, nil)
894 }
895 if rlogger := loggermw.RequestLoggerFromContext(ctx); rlogger != nil {
896 rlogger.WithAuthContext(actor)
897 }
898 return context.WithValue(ctx, authContextKey{}, actor)
899}
900
901//
902// Generic functions used to implement the database.Store methods.

Calls 3

RequestLoggerFromContextFunction · 0.92
WithAuthContextMethod · 0.65
EqualMethod · 0.45