Skip to content

Commit

Permalink
additional data for frontend details (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Feb 5, 2025
1 parent e7f126b commit 66ad600
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/zrok/accessPrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)

upReq := share.NewUpdateAccessParams()
upReq.Body.FrontendToken = accessResp.Payload.FrontendToken
upReq.Body.Description = bindAddress
upReq.Body.BindAddress = bindAddress
_, err = zrok.Share.UpdateAccess(upReq, auth)
if err != nil {
cmd.error(err)
Expand Down
4 changes: 4 additions & 0 deletions controller/frontendDetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (h *getFrontendDetailHandler) Handle(params metadata.GetFrontendDetailParam
CreatedAt: fe.CreatedAt.UnixMilli(),
UpdatedAt: fe.UpdatedAt.UnixMilli(),
}
if fe.BindAddress != nil {
payload.BindAddress = *fe.BindAddress
}
if fe.Description != nil {
payload.Description = *fe.Description
}
Expand All @@ -62,6 +65,7 @@ func (h *getFrontendDetailHandler) Handle(params metadata.GetFrontendDetailParam
return metadata.NewGetFrontendDetailInternalServerError()
}
payload.ShareToken = shr.Token
payload.BackendMode = shr.BackendMode
}
return metadata.NewGetFrontendDetailOK().WithPayload(payload)
}
20 changes: 12 additions & 8 deletions controller/updateAccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func newUpdateAccessHandler() *updateAccessHandler {
}

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

trx, err := str.Begin()
Expand All @@ -24,9 +25,9 @@ func (h *updateAccessHandler) Handle(params share.UpdateAccessParams, principal
}
defer func() { _ = trx.Rollback() }()

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

Expand All @@ -43,7 +44,7 @@ func (h *updateAccessHandler) Handle(params share.UpdateAccessParams, principal
}
}
if !envMatched {
logrus.Errorf("account '%v' does not own frontend '%v'", principal.Email, feToken)
logrus.Errorf("account '%v' does not own frontend '%v'", principal.Email, frontendToken)
return share.NewUpdateAccessNotFound()
}

Expand All @@ -52,14 +53,17 @@ func (h *updateAccessHandler) Handle(params share.UpdateAccessParams, principal
} else {
fe.Description = nil
}
if bindAddress != "" {
fe.BindAddress = &bindAddress
} else {
fe.BindAddress = nil
}
if err := str.UpdateFrontend(fe, trx); err != nil {
logrus.Errorf("error updating frontend '%v': %v", feToken, err)
logrus.Errorf("error updating frontend '%v': %v", frontendToken, err)
return share.NewUpdateAccessInternalServerError()
}
logrus.Warnf("updated frontend '%v' description to '%v'", feToken, *fe.Description)

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

0 comments on commit 66ad600

Please sign in to comment.