services.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // VaultCAS is a CertificateAuthorityService using Hasicorp Vault PKI.
  42. VaultCAS = "vaultcas"
  43. )
  44. // String returns a string from the type. It will always return the lower case
  45. // version of the Type, as we need a standard type to compare and use as the
  46. // registry key.
  47. func (t Type) String() string {
  48. if t == "" {
  49. return SoftCAS
  50. }
  51. return strings.ToLower(string(t))
  52. }
  53. // NotImplementedError is the type of error returned if an operation is not implemented.
  54. type NotImplementedError struct {
  55. Message string
  56. }
  57. // NotImplementedError implements the error interface.
  58. func (e NotImplementedError) Error() string {
  59. if e.Message != "" {
  60. return e.Message
  61. }
  62. return "not implemented"
  63. }
  64. // StatusCode implements the StatusCoder interface and returns the HTTP 501
  65. // error.
  66. func (e NotImplementedError) StatusCode() int {
  67. return http.StatusNotImplemented
  68. }