certificates/authority/mgmt/api/handler.go

51 lines
1.4 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-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-07 00:03:12 +00:00
db mgmt.DB
2021-05-03 19:48:20 +00:00
}
// NewHandler returns a new Authority Config Handler.
2021-05-07 00:03:12 +00:00
func NewHandler(db mgmt.DB) api.RouterHandler {
return &Handler{db}
2021-05-03 19:48:20 +00:00
}
// Route traffic and implement the Router interface.
func (h *Handler) Route(r api.Router) {
// Provisioners
r.MethodFunc("GET", "/provisioner/{id}", h.GetProvisioner)
r.MethodFunc("GET", "/provisioners", h.GetProvisioners)
r.MethodFunc("POST", "/provisioner", h.CreateProvisioner)
2021-05-12 07:03:40 +00:00
r.MethodFunc("PUT", "/provisioner/{id}", h.UpdateProvisioner)
//r.MethodFunc("DELETE", "/provisioner/{id}", h.UpdateAdmin)
2021-05-03 19:48:20 +00:00
// Admins
r.MethodFunc("GET", "/admin/{id}", h.GetAdmin)
r.MethodFunc("GET", "/admins", h.GetAdmins)
r.MethodFunc("POST", "/admin", h.CreateAdmin)
r.MethodFunc("PUT", "/admin/{id}", h.UpdateAdmin)
2021-05-12 07:03:40 +00:00
r.MethodFunc("DELETE", "/admin/{id}", h.DeleteAdmin)
2021-05-03 19:48:20 +00:00
// AuthConfig
r.MethodFunc("GET", "/authconfig/{id}", h.GetAuthConfig)
r.MethodFunc("POST", "/authconfig", h.CreateAuthConfig)
r.MethodFunc("PUT", "/authconfig/{id}", h.UpdateAuthConfig)
}