services.go 2.4 KB

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