You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
smallstep-certificates/authority/mgmt/api/handler.go

48 lines
1.3 KiB
Go

3 years ago
package api
import (
"time"
"github.com/smallstep/certificates/api"
3 years ago
"github.com/smallstep/certificates/authority"
3 years ago
"github.com/smallstep/certificates/authority/mgmt"
3 years ago
)
// 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 {
3 years ago
db mgmt.DB
auth *authority.Authority
3 years ago
}
// NewHandler returns a new Authority Config Handler.
3 years ago
func NewHandler(auth *authority.Authority) api.RouterHandler {
return &Handler{auth.GetAdminDatabase(), auth}
3 years ago
}
// Route traffic and implement the Router interface.
func (h *Handler) Route(r api.Router) {
// Provisioners
3 years ago
r.MethodFunc("GET", "/provisioners/{name}", h.GetProvisioner)
3 years ago
r.MethodFunc("GET", "/provisioners", h.GetProvisioners)
3 years ago
r.MethodFunc("POST", "/provisioners", h.CreateProvisioner)
r.MethodFunc("PUT", "/provisioners/{name}", h.UpdateProvisioner)
r.MethodFunc("DELETE", "/provisioners/{name}", h.DeleteProvisioner)
3 years ago
// Admins
3 years ago
r.MethodFunc("GET", "/admins/{id}", h.GetAdmin)
3 years ago
r.MethodFunc("GET", "/admins", h.GetAdmins)
3 years ago
r.MethodFunc("POST", "/admins", h.CreateAdmin)
r.MethodFunc("PATCH", "/admins/{id}", h.UpdateAdmin)
r.MethodFunc("DELETE", "/admins/{id}", h.DeleteAdmin)
3 years ago
}