handler.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package api
  2. import (
  3. "time"
  4. "github.com/smallstep/certificates/api"
  5. "github.com/smallstep/certificates/authority"
  6. "github.com/smallstep/certificates/authority/mgmt"
  7. )
  8. // Clock that returns time in UTC rounded to seconds.
  9. type Clock struct{}
  10. // Now returns the UTC time rounded to seconds.
  11. func (c *Clock) Now() time.Time {
  12. return time.Now().UTC().Truncate(time.Second)
  13. }
  14. var clock Clock
  15. // Handler is the ACME API request handler.
  16. type Handler struct {
  17. db mgmt.DB
  18. auth *authority.Authority
  19. }
  20. // NewHandler returns a new Authority Config Handler.
  21. func NewHandler(auth *authority.Authority) api.RouterHandler {
  22. return &Handler{auth.GetAdminDatabase(), auth}
  23. }
  24. // Route traffic and implement the Router interface.
  25. func (h *Handler) Route(r api.Router) {
  26. // Provisioners
  27. r.MethodFunc("GET", "/provisioners/{name}", h.GetProvisioner)
  28. r.MethodFunc("GET", "/provisioners", h.GetProvisioners)
  29. r.MethodFunc("POST", "/provisioners", h.CreateProvisioner)
  30. r.MethodFunc("PUT", "/provisioners/{name}", h.UpdateProvisioner)
  31. r.MethodFunc("DELETE", "/provisioners/{name}", h.DeleteProvisioner)
  32. // Admins
  33. r.MethodFunc("GET", "/admins/{id}", h.GetAdmin)
  34. r.MethodFunc("GET", "/admins", h.GetAdmins)
  35. r.MethodFunc("POST", "/admins", h.CreateAdmin)
  36. r.MethodFunc("PATCH", "/admins/{id}", h.UpdateAdmin)
  37. r.MethodFunc("DELETE", "/admins/{id}", h.DeleteAdmin)
  38. // AuthConfig
  39. r.MethodFunc("GET", "/authconfigs/{id}", h.GetAuthConfig)
  40. r.MethodFunc("PUT", "/authconfigs/{id}", h.UpdateAuthConfig)
  41. }