4
0

handler.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package api
  2. import (
  3. "github.com/smallstep/certificates/acme"
  4. "github.com/smallstep/certificates/api"
  5. "github.com/smallstep/certificates/authority/admin"
  6. )
  7. // Handler is the Admin API request handler.
  8. type Handler struct {
  9. adminDB admin.DB
  10. auth adminAuthority
  11. acmeDB acme.DB
  12. acmeResponder acmeAdminResponderInterface
  13. }
  14. // NewHandler returns a new Authority Config Handler.
  15. func NewHandler(auth adminAuthority, adminDB admin.DB, acmeDB acme.DB, acmeResponder acmeAdminResponderInterface) api.RouterHandler {
  16. return &Handler{
  17. auth: auth,
  18. adminDB: adminDB,
  19. acmeDB: acmeDB,
  20. acmeResponder: acmeResponder,
  21. }
  22. }
  23. // Route traffic and implement the Router interface.
  24. func (h *Handler) Route(r api.Router) {
  25. authnz := func(next nextHTTP) nextHTTP {
  26. return h.extractAuthorizeTokenAdmin(h.requireAPIEnabled(next))
  27. }
  28. requireEABEnabled := func(next nextHTTP) nextHTTP {
  29. return h.requireEABEnabled(next)
  30. }
  31. // Provisioners
  32. r.MethodFunc("GET", "/provisioners/{name}", authnz(h.GetProvisioner))
  33. r.MethodFunc("GET", "/provisioners", authnz(h.GetProvisioners))
  34. r.MethodFunc("POST", "/provisioners", authnz(h.CreateProvisioner))
  35. r.MethodFunc("PUT", "/provisioners/{name}", authnz(h.UpdateProvisioner))
  36. r.MethodFunc("DELETE", "/provisioners/{name}", authnz(h.DeleteProvisioner))
  37. // Admins
  38. r.MethodFunc("GET", "/admins/{id}", authnz(h.GetAdmin))
  39. r.MethodFunc("GET", "/admins", authnz(h.GetAdmins))
  40. r.MethodFunc("POST", "/admins", authnz(h.CreateAdmin))
  41. r.MethodFunc("PATCH", "/admins/{id}", authnz(h.UpdateAdmin))
  42. r.MethodFunc("DELETE", "/admins/{id}", authnz(h.DeleteAdmin))
  43. // ACME External Account Binding Keys
  44. r.MethodFunc("GET", "/acme/eab/{provisionerName}/{reference}", authnz(requireEABEnabled(h.acmeResponder.GetExternalAccountKeys)))
  45. r.MethodFunc("GET", "/acme/eab/{provisionerName}", authnz(requireEABEnabled(h.acmeResponder.GetExternalAccountKeys)))
  46. r.MethodFunc("POST", "/acme/eab/{provisionerName}", authnz(requireEABEnabled(h.acmeResponder.CreateExternalAccountKey)))
  47. r.MethodFunc("DELETE", "/acme/eab/{provisionerName}/{id}", authnz(requireEABEnabled(h.acmeResponder.DeleteExternalAccountKey)))
  48. }