Improve SCEP API logic and error handling

This commit is contained in:
Herman Slatman 2021-02-27 00:34:50 +01:00
parent a6d50f2fa0
commit 2fc5a7f22e
No known key found for this signature in database
GPG key ID: F4D8A44EA0A75A4F
4 changed files with 146 additions and 103 deletions

View file

@ -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")
}