2021-02-26 11:32:43 +00:00
|
|
|
package scep
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2021-02-26 23:34:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ContextKey is the key type for storing and searching for SCEP request
|
|
|
|
// essentials in the context of a request.
|
|
|
|
type ContextKey string
|
2021-02-26 11:32:43 +00:00
|
|
|
|
2021-02-26 23:34:50 +00:00
|
|
|
const (
|
|
|
|
// ProvisionerContextKey provisioner key
|
|
|
|
ProvisionerContextKey = ContextKey("provisioner")
|
2021-02-26 11:32:43 +00:00
|
|
|
)
|
|
|
|
|
2022-01-14 09:48:23 +00:00
|
|
|
// provisionerFromContext searches the context for a SCEP provisioner.
|
2021-02-26 11:32:43 +00:00
|
|
|
// Returns the provisioner or an error.
|
2022-01-14 09:48:23 +00:00
|
|
|
func provisionerFromContext(ctx context.Context) (Provisioner, error) {
|
2021-02-26 23:34:50 +00:00
|
|
|
val := ctx.Value(ProvisionerContextKey)
|
2021-02-26 11:32:43 +00:00
|
|
|
if val == nil {
|
|
|
|
return nil, errors.New("provisioner expected in request context")
|
|
|
|
}
|
|
|
|
p, ok := val.(Provisioner)
|
|
|
|
if !ok || p == nil {
|
|
|
|
return nil, errors.New("provisioner in context is not a SCEP provisioner")
|
|
|
|
}
|
|
|
|
return p, nil
|
|
|
|
}
|