common.go 750 B

1234567891011121314151617181920212223242526272829
  1. package scep
  2. import (
  3. "context"
  4. "errors"
  5. )
  6. // ContextKey is the key type for storing and searching for SCEP request
  7. // essentials in the context of a request.
  8. type ContextKey string
  9. const (
  10. // ProvisionerContextKey provisioner key
  11. ProvisionerContextKey = ContextKey("provisioner")
  12. )
  13. // provisionerFromContext searches the context for a SCEP provisioner.
  14. // Returns the provisioner or an error.
  15. func provisionerFromContext(ctx context.Context) (Provisioner, error) {
  16. val := ctx.Value(ProvisionerContextKey)
  17. if val == nil {
  18. return nil, errors.New("provisioner expected in request context")
  19. }
  20. p, ok := val.(Provisioner)
  21. if !ok || p == nil {
  22. return nil, errors.New("provisioner in context is not a SCEP provisioner")
  23. }
  24. return p, nil
  25. }