services.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package apiv1
  2. import (
  3. "net/http"
  4. "strings"
  5. )
  6. // CertificateAuthorityService is the interface implemented to support external
  7. // certificate authorities.
  8. type CertificateAuthorityService interface {
  9. CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error)
  10. RenewCertificate(req *RenewCertificateRequest) (*RenewCertificateResponse, error)
  11. RevokeCertificate(req *RevokeCertificateRequest) (*RevokeCertificateResponse, error)
  12. }
  13. // CertificateAuthorityGetter is an interface implemented by a
  14. // CertificateAuthorityService that has a method to get the root certificate.
  15. type CertificateAuthorityGetter interface {
  16. GetCertificateAuthority(req *GetCertificateAuthorityRequest) (*GetCertificateAuthorityResponse, error)
  17. }
  18. // CertificateAuthorityCreator is an interface implamented by a
  19. // CertificateAuthorityService that has a method to create a new certificate
  20. // authority.
  21. type CertificateAuthorityCreator interface {
  22. CreateCertificateAuthority(req *CreateCertificateAuthorityRequest) (*CreateCertificateAuthorityResponse, error)
  23. }
  24. // Type represents the CAS type used.
  25. type Type string
  26. const (
  27. // DefaultCAS is a CertificateAuthorityService using software.
  28. DefaultCAS = ""
  29. // SoftCAS is a CertificateAuthorityService using software.
  30. SoftCAS = "softcas"
  31. // CloudCAS is a CertificateAuthorityService using Google Cloud CAS.
  32. CloudCAS = "cloudcas"
  33. // StepCAS is a CertificateAuthorityService using another step-ca instance.
  34. StepCAS = "stepcas"
  35. )
  36. // String returns a string from the type. It will always return the lower case
  37. // version of the Type, as we need a standard type to compare and use as the
  38. // registry key.
  39. func (t Type) String() string {
  40. if t == "" {
  41. return SoftCAS
  42. }
  43. return strings.ToLower(string(t))
  44. }
  45. // ErrNotImplemented is the type of error returned if an operation is not
  46. // implemented.
  47. type ErrNotImplemented struct {
  48. Message string
  49. }
  50. // ErrNotImplemented implements the error interface.
  51. func (e ErrNotImplemented) Error() string {
  52. if e.Message != "" {
  53. return e.Message
  54. }
  55. return "not implemented"
  56. }
  57. // StatusCode implements the StatusCoder interface and returns the HTTP 501
  58. // error.
  59. func (e ErrNotImplemented) StatusCode() int {
  60. return http.StatusNotImplemented
  61. }