certificates/authority/mgmt/api/handler.go

52 lines
1.5 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-18 04:07:25 +00:00
r.MethodFunc("GET", "/provisioner/{name}", h.GetProvisioner)
2021-05-03 19:48:20 +00:00
r.MethodFunc("GET", "/provisioners", h.GetProvisioners)
r.MethodFunc("POST", "/provisioner", h.CreateProvisioner)
2021-05-18 04:07:25 +00:00
r.MethodFunc("PUT", "/provisioner/{name}", h.UpdateProvisioner)
r.MethodFunc("DELETE", "/provisioner/{name}", h.DeleteProvisioner)
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)
2021-05-18 04:07:25 +00:00
r.MethodFunc("PATCH", "/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("PUT", "/authconfig/{id}", h.UpdateAuthConfig)
}