zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/pkg/requestcontext/authn.go (about) 1 package uac 2 3 import ( 4 "context" 5 6 "zotregistry.dev/zot/errors" 7 ) 8 9 // request-local context key. 10 var amwCtxKey = Key(1) //nolint: gochecknoglobals 11 12 // pointer needed for use in context.WithValue. 13 func GetAuthnMiddlewareCtxKey() *Key { 14 return &amwCtxKey 15 } 16 17 type AuthnMiddlewareContext struct { 18 AuthnType string 19 } 20 21 func GetAuthnMiddlewareContext(ctx context.Context) (*AuthnMiddlewareContext, error) { 22 authnMiddlewareCtxKey := GetAuthnMiddlewareCtxKey() 23 if authnMiddlewareCtx := ctx.Value(authnMiddlewareCtxKey); authnMiddlewareCtx != nil { 24 amCtx, ok := authnMiddlewareCtx.(AuthnMiddlewareContext) 25 if !ok { 26 return nil, errors.ErrBadType 27 } 28 29 return &amCtx, nil 30 } 31 32 return nil, nil //nolint: nilnil 33 }