Skip to content

Commit

Permalink
implemented patching frontend descriptions (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Feb 5, 2025
1 parent 2a49705 commit 5228e25
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func Run(inCfg *config.Config) error {
api.ShareShareHandler = newShareHandler()
api.ShareUnaccessHandler = newUnaccessHandler()
api.ShareUnshareHandler = newUnshareHandler()
api.ShareUpdateAccessHandler = newUpdateAccessHandler()
api.ShareUpdateShareHandler = newUpdateShareHandler()

if err := controllerStartup(); err != nil {
Expand Down
66 changes: 66 additions & 0 deletions controller/updateAccess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package controller

import (
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/sirupsen/logrus"
)

type updateAccessHandler struct{}

func newUpdateAccessHandler() *updateAccessHandler {
return &updateAccessHandler{}
}

func (h *updateAccessHandler) Handle(params share.UpdateAccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
feToken := params.Body.FrontendToken
desc := params.Body.Description

trx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
return share.NewUpdateAccessInternalServerError()
}
defer func() { _ = trx.Rollback() }()

fe, err := str.FindFrontendWithToken(feToken, trx)
if err != nil {
logrus.Errorf("error finding frontend with token '%v': %v", feToken, err)
return share.NewUpdateAccessNotFound()
}

envs, err := str.FindEnvironmentsForAccount(int(principal.ID), trx)
if err != nil {
logrus.Errorf("error finding environments for account '%v': %v", principal.Email, err)
}

envMatched := false
for _, env := range envs {
if fe.EnvironmentId != nil && env.Id == *fe.EnvironmentId {
envMatched = true
break
}
}
if !envMatched {
logrus.Errorf("account '%v' does not own frontend '%v'", principal.Email, feToken)
return share.NewUpdateAccessNotFound()
}

if desc != "" {
fe.Description = &desc
} else {
fe.Description = nil
}
if err := str.UpdateFrontend(fe, trx); err != nil {
logrus.Errorf("error updating frontend '%v': %v", feToken, err)
return share.NewUpdateAccessInternalServerError()
}

if err := trx.Commit(); err != nil {
logrus.Errorf("error committing transaction for frontend '%v': %v", feToken, err)
return share.NewUpdateAccessInternalServerError()
}

return share.NewUpdateAccessOK()
}

0 comments on commit 5228e25

Please sign in to comment.