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)
| 887 | // When you use this function, be sure to add a //nolint comment |
| 888 | // explaining why it is necessary. |
| 889 | func 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. |