@@ -388,59 +388,59 @@ var (
388388// AsProvisionerd returns a context with an actor that has permissions required
389389// for provisionerd to function.
390390func AsProvisionerd (ctx context.Context ) context.Context {
391- return context . WithValue (ctx , authContextKey {} , subjectProvisionerd )
391+ return InjectActorToContext (ctx , subjectProvisionerd )
392392}
393393
394394// AsAutostart returns a context with an actor that has permissions required
395395// for autostart to function.
396396func AsAutostart (ctx context.Context ) context.Context {
397- return context . WithValue (ctx , authContextKey {} , subjectAutostart )
397+ return InjectActorToContext (ctx , subjectAutostart )
398398}
399399
400400// AsHangDetector returns a context with an actor that has permissions required
401401// for unhanger.Detector to function.
402402func AsHangDetector (ctx context.Context ) context.Context {
403- return context . WithValue (ctx , authContextKey {} , subjectHangDetector )
403+ return InjectActorToContext (ctx , subjectHangDetector )
404404}
405405
406406// AsKeyRotator returns a context with an actor that has permissions required for rotating crypto keys.
407407func AsKeyRotator (ctx context.Context ) context.Context {
408- return context . WithValue (ctx , authContextKey {} , subjectCryptoKeyRotator )
408+ return InjectActorToContext (ctx , subjectCryptoKeyRotator )
409409}
410410
411411// AsKeyReader returns a context with an actor that has permissions required for reading crypto keys.
412412func AsKeyReader (ctx context.Context ) context.Context {
413- return context . WithValue (ctx , authContextKey {} , subjectCryptoKeyReader )
413+ return InjectActorToContext (ctx , subjectCryptoKeyReader )
414414}
415415
416416// AsNotifier returns a context with an actor that has permissions required for
417417// creating/reading/updating/deleting notifications.
418418func AsNotifier (ctx context.Context ) context.Context {
419- return context . WithValue (ctx , authContextKey {} , subjectNotifier )
419+ return InjectActorToContext (ctx , subjectNotifier )
420420}
421421
422422// AsResourceMonitor returns a context with an actor that has permissions required for
423423// updating resource monitors.
424424func AsResourceMonitor (ctx context.Context ) context.Context {
425- return context . WithValue (ctx , authContextKey {} , subjectResourceMonitor )
425+ return InjectActorToContext (ctx , subjectResourceMonitor )
426426}
427427
428428// AsSystemRestricted returns a context with an actor that has permissions
429429// required for various system operations (login, logout, metrics cache).
430430func AsSystemRestricted (ctx context.Context ) context.Context {
431- return context . WithValue (ctx , authContextKey {} , subjectSystemRestricted )
431+ return InjectActorToContext (ctx , subjectSystemRestricted )
432432}
433433
434434// AsSystemReadProvisionerDaemons returns a context with an actor that has permissions
435435// to read provisioner daemons.
436436func AsSystemReadProvisionerDaemons (ctx context.Context ) context.Context {
437- return context . WithValue (ctx , authContextKey {} , subjectSystemReadProvisionerDaemons )
437+ return InjectActorToContext (ctx , subjectSystemReadProvisionerDaemons )
438438}
439439
440440// AsPrebuildsOrchestrator returns a context with an actor that has permissions
441441// to read orchestrator workspace prebuilds.
442442func AsPrebuildsOrchestrator (ctx context.Context ) context.Context {
443- return context . WithValue (ctx , authContextKey {} , subjectPrebuildsOrchestrator )
443+ return InjectActorToContext (ctx , subjectPrebuildsOrchestrator )
444444}
445445
446446var AsRemoveActor = rbac.Subject {
@@ -458,6 +458,16 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
458458 // should be removed from the context.
459459 return context .WithValue (ctx , authContextKey {}, nil )
460460 }
461+ return InjectActorToContext (ctx , actor )
462+ }
463+
464+ func InjectActorToContext (ctx context.Context , actor rbac.Subject ) context.Context {
465+ // if rlogger := httpmw.RequestLoggerFromContext(ctx); rlogger != nil {
466+ // rlogger.WithFields(
467+ // slog.F("requestor_id", actor.ID),
468+ // slog.F("requestor_email", actor.Email),
469+ // )
470+ // }
461471 return context .WithValue (ctx , authContextKey {}, actor )
462472}
463473
0 commit comments