handler.go 1.3 KB

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