2021-05-03 19:48:20 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-04-27 18:59:32 +00:00
|
|
|
"context"
|
|
|
|
|
2021-07-22 21:48:41 +00:00
|
|
|
"github.com/smallstep/certificates/acme"
|
2021-05-03 19:48:20 +00:00
|
|
|
"github.com/smallstep/certificates/api"
|
2022-04-27 18:59:32 +00:00
|
|
|
"github.com/smallstep/certificates/authority"
|
2021-05-03 19:48:20 +00:00
|
|
|
"github.com/smallstep/certificates/authority/admin"
|
|
|
|
)
|
|
|
|
|
2021-12-08 14:19:38 +00:00
|
|
|
// Handler is the Admin API request handler.
|
2021-05-03 19:48:20 +00:00
|
|
|
type Handler struct {
|
2022-02-08 12:26:30 +00:00
|
|
|
acmeResponder acmeAdminResponderInterface
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 18:59:32 +00:00
|
|
|
// Route traffic and implement the Router interface.
|
|
|
|
//
|
|
|
|
// Deprecated: use Route(r api.Router, acmeResponder acmeAdminResponderInterface)
|
|
|
|
func (h *Handler) Route(r api.Router) {
|
|
|
|
Route(r, h.acmeResponder)
|
|
|
|
}
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
// NewHandler returns a new Authority Config Handler.
|
2022-04-27 18:59:32 +00:00
|
|
|
//
|
|
|
|
// Deprecated: use Route(r api.Router, acmeResponder acmeAdminResponderInterface)
|
2022-02-08 12:26:30 +00:00
|
|
|
func NewHandler(auth adminAuthority, adminDB admin.DB, acmeDB acme.DB, acmeResponder acmeAdminResponderInterface) api.RouterHandler {
|
2021-07-22 21:48:41 +00:00
|
|
|
return &Handler{
|
2022-02-08 12:26:30 +00:00
|
|
|
acmeResponder: acmeResponder,
|
2021-07-22 21:48:41 +00:00
|
|
|
}
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 18:59:32 +00:00
|
|
|
var mustAuthority = func(ctx context.Context) adminAuthority {
|
|
|
|
return authority.MustFromContext(ctx)
|
|
|
|
}
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
// Route traffic and implement the Router interface.
|
2022-04-27 18:59:32 +00:00
|
|
|
func Route(r api.Router, acmeResponder acmeAdminResponderInterface) {
|
2021-05-03 19:48:20 +00:00
|
|
|
authnz := func(next nextHTTP) nextHTTP {
|
2022-04-27 18:59:32 +00:00
|
|
|
return extractAuthorizeTokenAdmin(requireAPIEnabled(next))
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provisioners
|
2022-04-27 18:59:32 +00:00
|
|
|
r.MethodFunc("GET", "/provisioners/{name}", authnz(GetProvisioner))
|
|
|
|
r.MethodFunc("GET", "/provisioners", authnz(GetProvisioners))
|
|
|
|
r.MethodFunc("POST", "/provisioners", authnz(CreateProvisioner))
|
|
|
|
r.MethodFunc("PUT", "/provisioners/{name}", authnz(UpdateProvisioner))
|
|
|
|
r.MethodFunc("DELETE", "/provisioners/{name}", authnz(DeleteProvisioner))
|
2021-05-03 19:48:20 +00:00
|
|
|
|
|
|
|
// Admins
|
2022-04-27 18:59:32 +00:00
|
|
|
r.MethodFunc("GET", "/admins/{id}", authnz(GetAdmin))
|
|
|
|
r.MethodFunc("GET", "/admins", authnz(GetAdmins))
|
|
|
|
r.MethodFunc("POST", "/admins", authnz(CreateAdmin))
|
|
|
|
r.MethodFunc("PATCH", "/admins/{id}", authnz(UpdateAdmin))
|
|
|
|
r.MethodFunc("DELETE", "/admins/{id}", authnz(DeleteAdmin))
|
2021-07-17 15:35:44 +00:00
|
|
|
|
2021-07-23 13:16:11 +00:00
|
|
|
// ACME External Account Binding Keys
|
2022-04-27 18:59:32 +00:00
|
|
|
r.MethodFunc("GET", "/acme/eab/{provisionerName}/{reference}", authnz(requireEABEnabled(acmeResponder.GetExternalAccountKeys)))
|
|
|
|
r.MethodFunc("GET", "/acme/eab/{provisionerName}", authnz(requireEABEnabled(acmeResponder.GetExternalAccountKeys)))
|
|
|
|
r.MethodFunc("POST", "/acme/eab/{provisionerName}", authnz(requireEABEnabled(acmeResponder.CreateExternalAccountKey)))
|
|
|
|
r.MethodFunc("DELETE", "/acme/eab/{provisionerName}/{id}", authnz(requireEABEnabled(acmeResponder.DeleteExternalAccountKey)))
|
2021-05-03 19:48:20 +00:00
|
|
|
}
|