Files
nmon/internal/api/actor.go

20 lines
559 B
Go

package api
import (
"context"
"github.com/v10networks/nmon/internal/auth"
)
// anonymousActor names the caller when no auth middleware ran (unit tests that call the API directly).
const anonymousActor = "anonymous"
// actorOf names the authenticated caller for the audit log, acknowledgements and maintenance windows:
// the OIDC subject, "token:<name>" for an API token, "breakglass", or "dev" in development-open mode.
func actorOf(ctx context.Context) string {
if p, ok := auth.FromContext(ctx); ok {
return p.Actor()
}
return anonymousActor
}