mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
ce4924f841
Signed-off-by: Andrei Aaron <aaaron@luxoft.com>
33 lines
712 B
Go
33 lines
712 B
Go
package uac
|
|
|
|
import (
|
|
"context"
|
|
|
|
"zotregistry.dev/zot/errors"
|
|
)
|
|
|
|
// 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
|
|
}
|