method.go 985 B

12345678910111213141516171819202122232425262728293031323334
  1. package provisioner
  2. import (
  3. "context"
  4. )
  5. // Method indicates the action to action that we will perform, it's used as part
  6. // of the context in the call to authorize. It defaults to Sing.
  7. type Method int
  8. // The key to save the Method in the context.
  9. type methodKey struct{}
  10. const (
  11. // SignMethod is the method used to sign X.509 certificates.
  12. SignMethod Method = iota
  13. // SignSSHMethod is the method used to sign SSH certificate.
  14. SignSSHMethod
  15. // RevokeMethod is the method used to revoke X.509 certificates.
  16. RevokeMethod
  17. )
  18. // NewContextWithMethod creates a new context from ctx and attaches method to
  19. // it.
  20. func NewContextWithMethod(ctx context.Context, method Method) context.Context {
  21. return context.WithValue(ctx, methodKey{}, method)
  22. }
  23. // MethodFromContext returns the Method saved in ctx. Returns Sign if the given
  24. // context has no Method associated with it.
  25. func MethodFromContext(ctx context.Context) Method {
  26. m, _ := ctx.Value(methodKey{}).(Method)
  27. return m
  28. }