From 2f5803a541ee554ba92cdd4b83dc5d42d072649f Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 4 Sep 2024 16:18:20 -0400 Subject: [PATCH] grants handler wiring (#744) --- controller/controller.go | 1 + controller/grants.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 controller/grants.go diff --git a/controller/controller.go b/controller/controller.go index 0ebc134f..5603ddbd 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -56,6 +56,7 @@ func Run(inCfg *config.Config) error { api.AdminCreateFrontendHandler = newCreateFrontendHandler() api.AdminCreateIdentityHandler = newCreateIdentityHandler() api.AdminDeleteFrontendHandler = newDeleteFrontendHandler() + api.AdminGrantsHandler = newGrantsHandler() api.AdminInviteTokenGenerateHandler = newInviteTokenGenerateHandler() api.AdminListFrontendsHandler = newListFrontendsHandler() api.AdminUpdateFrontendHandler = newUpdateFrontendHandler() diff --git a/controller/grants.go b/controller/grants.go new file mode 100644 index 00000000..b4f74d56 --- /dev/null +++ b/controller/grants.go @@ -0,0 +1,22 @@ +package controller + +import ( + "github.com/go-openapi/runtime/middleware" + "github.com/openziti/zrok/rest_model_zrok" + "github.com/openziti/zrok/rest_server_zrok/operations/admin" + "github.com/sirupsen/logrus" +) + +type grantsHandler struct{} + +func newGrantsHandler() *grantsHandler { + return &grantsHandler{} +} + +func (h *grantsHandler) Handle(params admin.GrantsParams, principal *rest_model_zrok.Principal) middleware.Responder { + if !principal.Admin { + logrus.Errorf("invalid admin principal") + return admin.NewGrantsUnauthorized() + } + return admin.NewGrantsOK() +}