2023-09-01 13:13:53 -05:00
|
|
|
package uac
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-01-31 23:34:07 -05:00
|
|
|
"zotregistry.dev/zot/errors"
|
2023-09-01 13:13:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// request-local context key.
|
|
|
|
var amwCtxKey = Key(1) //nolint: gochecknoglobals
|
|
|
|
|
|
|
|
// pointer needed for use in context.WithValue.
|
|
|
|
func GetAuthnMiddlewareCtxKey() *Key {
|
|
|
|
return &amwCtxKey
|
|
|
|
}
|
|
|
|
|
|
|
|
type AuthnMiddlewareContext struct {
|
|
|
|
AuthnType string
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAuthnMiddlewareContext(ctx context.Context) (*AuthnMiddlewareContext, error) {
|
|
|
|
authnMiddlewareCtxKey := GetAuthnMiddlewareCtxKey()
|
|
|
|
if authnMiddlewareCtx := ctx.Value(authnMiddlewareCtxKey); authnMiddlewareCtx != nil {
|
|
|
|
amCtx, ok := authnMiddlewareCtx.(AuthnMiddlewareContext)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.ErrBadType
|
|
|
|
}
|
|
|
|
|
|
|
|
return &amCtx, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil //nolint: nilnil
|
|
|
|
}
|