smallstep-certificates/authority/mgmt/api/handler.go

48 lines
1.3 KiB
Go
Raw Normal View History

2021-05-03 19:48:20 +00:00
package api
import (
"time"
"github.com/smallstep/certificates/api"
2021-05-18 04:07:25 +00:00
"github.com/smallstep/certificates/authority"
2021-05-07 00:03:12 +00:00
"github.com/smallstep/certificates/authority/mgmt"
2021-05-03 19:48:20 +00:00
)
// Clock that returns time in UTC rounded to seconds.
type Clock struct{}
// Now returns the UTC time rounded to seconds.
func (c *Clock) Now() time.Time {
return time.Now().UTC().Truncate(time.Second)
}
var clock Clock
// Handler is the ACME API request handler.
type Handler struct {
2021-05-18 04:07:25 +00:00
db mgmt.DB
auth *authority.Authority
2021-05-03 19:48:20 +00:00
}
// NewHandler returns a new Authority Config Handler.
2021-05-20 20:01:58 +00:00
func NewHandler(auth *authority.Authority) api.RouterHandler {
return &Handler{auth.GetAdminDatabase(), auth}
2021-05-03 19:48:20 +00:00
}
// Route traffic and implement the Router interface.
func (h *Handler) Route(r api.Router) {
// Provisioners
2021-05-20 23:02:20 +00:00
r.MethodFunc("GET", "/provisioners/{name}", h.GetProvisioner)
2021-05-03 19:48:20 +00:00
r.MethodFunc("GET", "/provisioners", h.GetProvisioners)
2021-05-20 23:02:20 +00:00
r.MethodFunc("POST", "/provisioners", h.CreateProvisioner)
r.MethodFunc("PUT", "/provisioners/{name}", h.UpdateProvisioner)
r.MethodFunc("DELETE", "/provisioners/{name}", h.DeleteProvisioner)
2021-05-03 19:48:20 +00:00
// Admins
2021-05-20 23:02:20 +00:00
r.MethodFunc("GET", "/admins/{id}", h.GetAdmin)
2021-05-03 19:48:20 +00:00
r.MethodFunc("GET", "/admins", h.GetAdmins)
2021-05-20 23:02:20 +00:00
r.MethodFunc("POST", "/admins", h.CreateAdmin)
r.MethodFunc("PATCH", "/admins/{id}", h.UpdateAdmin)
r.MethodFunc("DELETE", "/admins/{id}", h.DeleteAdmin)
2021-05-03 19:48:20 +00:00
}