mirror of
https://github.com/openziti/zrok.git
synced 2024-11-21 23:53:19 +01:00
use sdk types/constants throughout the codebase for backend and share modes (#34)
This commit is contained in:
parent
141c9ae685
commit
c0503ae593
@ -6,6 +6,7 @@ import (
|
||||
"github.com/openziti/zrok/model"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -39,8 +40,8 @@ func newReserveCommand() *reserveCommand {
|
||||
}
|
||||
|
||||
func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
|
||||
shareMode := args[0]
|
||||
if shareMode != "public" && shareMode != "private" {
|
||||
shareMode := sdk.ShareMode(args[0])
|
||||
if shareMode != sdk.PublicShareMode && shareMode != sdk.PrivateShareMode {
|
||||
tui.Error("invalid sharing mode; expecting 'public' or 'private'", nil)
|
||||
}
|
||||
|
||||
@ -83,13 +84,13 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
|
||||
req := share.NewShareParams()
|
||||
req.Body = &rest_model_zrok.ShareRequest{
|
||||
EnvZID: env.Environment().ZitiIdentity,
|
||||
ShareMode: shareMode,
|
||||
ShareMode: string(shareMode),
|
||||
BackendMode: cmd.backendMode,
|
||||
BackendProxyEndpoint: target,
|
||||
AuthScheme: string(model.None),
|
||||
Reserved: true,
|
||||
}
|
||||
if shareMode == "public" {
|
||||
if shareMode == sdk.PublicShareMode {
|
||||
req.Body.FrontendSelection = cmd.frontendSelection
|
||||
}
|
||||
if len(cmd.basicAuth) > 0 {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/openziti/zrok/rest_client_zrok"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -110,7 +111,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
req := share.NewShareParams()
|
||||
req.Body = &rest_model_zrok.ShareRequest{
|
||||
EnvZID: env.Environment().ZitiIdentity,
|
||||
ShareMode: "private",
|
||||
ShareMode: string(sdk.PrivateShareMode),
|
||||
BackendMode: cmd.backendMode,
|
||||
BackendProxyEndpoint: target,
|
||||
AuthScheme: string(model.None),
|
||||
@ -231,7 +232,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
|
||||
} else {
|
||||
shareDescription := fmt.Sprintf("access your share with: %v", tui.Code.Render(fmt.Sprintf("zrok access private %v", resp.Payload.ShrToken)))
|
||||
mdl := newShareModel(resp.Payload.ShrToken, []string{shareDescription}, "private", cmd.backendMode)
|
||||
mdl := newShareModel(resp.Payload.ShrToken, []string{shareDescription}, sdk.PrivateShareMode, sdk.BackendMode(cmd.backendMode))
|
||||
logrus.SetOutput(mdl)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
mdl.prg = prg
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/openziti/zrok/rest_client_zrok"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -104,7 +105,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
||||
req := share.NewShareParams()
|
||||
req.Body = &rest_model_zrok.ShareRequest{
|
||||
EnvZID: env.Environment().ZitiIdentity,
|
||||
ShareMode: "public",
|
||||
ShareMode: string(sdk.PublicShareMode),
|
||||
FrontendSelection: cmd.frontendSelection,
|
||||
BackendMode: cmd.backendMode,
|
||||
BackendProxyEndpoint: target,
|
||||
@ -185,7 +186,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
} else {
|
||||
mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, "public", cmd.backendMode)
|
||||
mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, sdk.PublicShareMode, sdk.BackendMode(cmd.backendMode))
|
||||
logrus.SetOutput(mdl)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
mdl.prg = prg
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/openziti/zrok/rest_client_zrok/metadata"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -144,10 +145,10 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
|
||||
|
||||
if cmd.headless {
|
||||
switch resp.Payload.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
logrus.Infof("access your zrok share: %v", resp.Payload.FrontendEndpoint)
|
||||
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
logrus.Infof("use this command to access your zrok share: 'zrok access private %v'", shrToken)
|
||||
}
|
||||
for {
|
||||
@ -159,13 +160,13 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
|
||||
} else {
|
||||
var shareDescription string
|
||||
switch resp.Payload.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
shareDescription = resp.Payload.FrontendEndpoint
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
shareDescription = fmt.Sprintf("access your share with: %v", tui.Code.Render(fmt.Sprintf("zrok access private %v", shrToken)))
|
||||
}
|
||||
|
||||
mdl := newShareModel(shrToken, []string{shareDescription}, resp.Payload.ShareMode, resp.Payload.BackendMode)
|
||||
mdl := newShareModel(shrToken, []string{shareDescription}, sdk.ShareMode(resp.Payload.ShareMode), sdk.BackendMode(resp.Payload.BackendMode))
|
||||
logrus.SetOutput(mdl)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
mdl.prg = prg
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -19,8 +20,8 @@ var wordwrapBreakpoints = map[rune]bool{' ': true, '-': true}
|
||||
type shareModel struct {
|
||||
shrToken string
|
||||
frontendDescriptions []string
|
||||
shareMode string
|
||||
backendMode string
|
||||
shareMode sdk.ShareMode
|
||||
backendMode sdk.BackendMode
|
||||
requests []*endpoints.Request
|
||||
log []string
|
||||
showLog bool
|
||||
@ -32,7 +33,7 @@ type shareModel struct {
|
||||
|
||||
type shareLogLine string
|
||||
|
||||
func newShareModel(shrToken string, frontendEndpoints []string, shareMode, backendMode string) *shareModel {
|
||||
func newShareModel(shrToken string, frontendEndpoints []string, shareMode sdk.ShareMode, backendMode sdk.BackendMode) *shareModel {
|
||||
return &shareModel{
|
||||
shrToken: shrToken,
|
||||
frontendDescriptions: frontendEndpoints,
|
||||
@ -116,15 +117,15 @@ func (m *shareModel) adjustPaneHeights() {
|
||||
func (m *shareModel) renderConfig() string {
|
||||
out := "["
|
||||
if m.shareMode == "public" {
|
||||
out += shareModePublicStyle.Render(strings.ToUpper(m.shareMode))
|
||||
out += shareModePublicStyle.Render(strings.ToUpper(string(m.shareMode)))
|
||||
} else {
|
||||
out += shareModePrivateStyle.Render(strings.ToUpper(m.shareMode))
|
||||
out += shareModePrivateStyle.Render(strings.ToUpper(string(m.shareMode)))
|
||||
}
|
||||
out += "] ["
|
||||
if m.backendMode == "proxy" {
|
||||
out += backendModeProxyStyle.Render(strings.ToUpper(m.backendMode))
|
||||
out += backendModeProxyStyle.Render(strings.ToUpper(string(m.backendMode)))
|
||||
} else {
|
||||
out += backendModeWebStyle.Render(strings.ToUpper(m.backendMode))
|
||||
out += backendModeWebStyle.Render(strings.ToUpper(string(m.backendMode)))
|
||||
}
|
||||
out += "]"
|
||||
return out
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/openziti/zrok/rest_client_zrok"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/openziti/zrok/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -198,9 +199,9 @@ func (l *looper) startup() {
|
||||
tunnelReq := share.NewShareParams()
|
||||
tunnelReq.Body = &rest_model_zrok.ShareRequest{
|
||||
EnvZID: l.env.ZitiIdentity,
|
||||
ShareMode: "public",
|
||||
ShareMode: string(sdk.PublicShareMode),
|
||||
FrontendSelection: l.cmd.frontendSelection,
|
||||
BackendMode: "proxy",
|
||||
BackendMode: string(sdk.ProxyBackendMode),
|
||||
BackendProxyEndpoint: fmt.Sprintf("looper#%d", l.id),
|
||||
AuthScheme: string(model.None),
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -38,11 +39,11 @@ func (a *accountRelaxAction) HandleAccount(acct *store.Account, _, _ int64, _ *B
|
||||
|
||||
for _, shr := range shrs {
|
||||
switch shr.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
if err := relaxPublicShare(a.str, edge, shr, trx); err != nil {
|
||||
return errors.Wrap(err, "error relaxing public share")
|
||||
}
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
if err := relaxPrivateShare(a.str, edge, shr, trx); err != nil {
|
||||
return errors.Wrap(err, "error relaxing private share")
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -33,11 +34,11 @@ func (a *environmentRelaxAction) HandleEnvironment(env *store.Environment, rxByt
|
||||
for _, shr := range shrs {
|
||||
if !shr.Deleted {
|
||||
switch shr.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
if err := relaxPublicShare(a.str, edge, shr, trx); err != nil {
|
||||
return err
|
||||
}
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
if err := relaxPrivateShare(a.str, edge, shr, trx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/openziti/edge-api/rest_management_api_client"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -28,11 +29,11 @@ func (a *shareRelaxAction) HandleShare(shr *store.Share, _, _ int64, _ *Bandwidt
|
||||
}
|
||||
|
||||
switch shr.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
if err := relaxPublicShare(a.str, edge, shr, trx); err != nil {
|
||||
return err
|
||||
}
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
if err := relaxPrivateShare(a.str, edge, shr, trx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/openziti/zrok/rest_server_zrok/operations/share"
|
||||
"github.com/openziti/zrok/sdk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -68,7 +69,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
var shrZId string
|
||||
var frontendEndpoints []string
|
||||
switch params.Body.ShareMode {
|
||||
case "public":
|
||||
case string(sdk.PublicShareMode):
|
||||
if len(params.Body.FrontendSelection) < 1 {
|
||||
logrus.Info("no frontend selection provided")
|
||||
return share.NewShareNotFound()
|
||||
@ -94,7 +95,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
case "private":
|
||||
case string(sdk.PrivateShareMode):
|
||||
logrus.Info("doing private")
|
||||
shrZId, frontendEndpoints, err = newPrivateResourceAllocator().allocate(envZId, shrToken, params, edge)
|
||||
if err != nil {
|
||||
@ -123,7 +124,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
}
|
||||
if len(frontendEndpoints) > 0 {
|
||||
sshr.FrontendEndpoint = &frontendEndpoints[0]
|
||||
} else if sshr.ShareMode == "private" {
|
||||
} else if sshr.ShareMode == string(sdk.PrivateShareMode) {
|
||||
sshr.FrontendEndpoint = &sshr.ShareMode
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user