Improve SCEP API logic and error handling
This commit is contained in:
parent
a6d50f2fa0
commit
2fc5a7f22e
4 changed files with 146 additions and 103 deletions
|
@ -3,14 +3,21 @@ package scep
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
"github.com/smallstep/certificates/acme"
|
||||
// ContextKey is the key type for storing and searching for SCEP request
|
||||
// essentials in the context of a request.
|
||||
type ContextKey string
|
||||
|
||||
const (
|
||||
// ProvisionerContextKey provisioner key
|
||||
ProvisionerContextKey = ContextKey("provisioner")
|
||||
)
|
||||
|
||||
// ProvisionerFromContext searches the context for a SCEP provisioner.
|
||||
// Returns the provisioner or an error.
|
||||
func ProvisionerFromContext(ctx context.Context) (Provisioner, error) {
|
||||
val := ctx.Value(acme.ProvisionerContextKey)
|
||||
val := ctx.Value(ProvisionerContextKey)
|
||||
if val == nil {
|
||||
return nil, errors.New("provisioner expected in request context")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue