From ea71493f2f1362655672eadd691b1b31cd98006e Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 10 Jul 2023 16:41:16 -0400 Subject: [PATCH] zrokdir -> environment (#34) --- cmd/zrok/accessPrivate.go | 6 ++-- cmd/zrok/adminCreateFrontend.go | 4 +-- cmd/zrok/adminCreateIdentity.go | 8 ++--- cmd/zrok/adminDeleteFrontend.go | 4 +-- cmd/zrok/adminGenerate.go | 6 ++-- cmd/zrok/adminListFrontends.go | 4 +-- cmd/zrok/adminUpdateFrontend.go | 4 +-- cmd/zrok/configGet.go | 4 +-- cmd/zrok/configSet.go | 6 ++-- cmd/zrok/configUnset.go | 4 +-- cmd/zrok/console.go | 8 ++--- cmd/zrok/disable.go | 18 +++++----- cmd/zrok/enable.go | 12 +++---- cmd/zrok/invite.go | 6 ++-- cmd/zrok/release.go | 6 ++-- cmd/zrok/reserve.go | 6 ++-- cmd/zrok/sharePrivate.go | 8 ++--- cmd/zrok/sharePublic.go | 8 ++--- cmd/zrok/shareReserved.go | 8 ++--- cmd/zrok/status.go | 6 ++-- cmd/zrok/testLoopPublic.go | 8 ++--- controller/bootstrap.go | 8 ++--- docs/_attic/overview.md | 6 ++-- docs/getting-started.md | 4 +-- endpoints/proxy/frontend.go | 6 ++-- endpoints/publicProxy/http.go | 6 ++-- endpoints/tcpTunnel/frontend.go | 6 ++-- endpoints/udpTunnel/frontend.go | 6 ++-- {zrokdir => environment}/client.go | 8 ++--- {zrokdir => environment}/config.go | 4 +-- {zrokdir => environment}/environment.go | 4 +-- {zrokdir => environment}/identity.go | 4 +-- zrokdir/zrokdir.go => environment/root.go | 40 +++++++++++------------ {zrokdir => environment}/version.go | 6 ++-- sdk/share.go | 12 +++---- 35 files changed, 132 insertions(+), 132 deletions(-) rename {zrokdir => environment}/client.go (89%) rename {zrokdir => environment}/config.go (92%) rename {zrokdir => environment}/environment.go (94%) rename {zrokdir => environment}/identity.go (88%) rename zrokdir/zrokdir.go => environment/root.go (75%) rename {zrokdir => environment}/version.go (84%) diff --git a/cmd/zrok/accessPrivate.go b/cmd/zrok/accessPrivate.go index 9c23990e8..d97edac0f 100644 --- a/cmd/zrok/accessPrivate.go +++ b/cmd/zrok/accessPrivate.go @@ -8,11 +8,11 @@ import ( "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/tcpTunnel" "github.com/openziti/zrok/endpoints/udpTunnel" + "github.com/openziti/zrok/environment" "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/tui" - "github.com/openziti/zrok/zrokdir" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "net/url" @@ -48,9 +48,9 @@ func newAccessPrivateCommand() *accessPrivateCommand { func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) { shrToken := args[0] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { - tui.Error("unable to load zrokdir", err) + tui.Error("error loading environment", err) } if zrd.Env == nil { diff --git a/cmd/zrok/adminCreateFrontend.go b/cmd/zrok/adminCreateFrontend.go index 34588f6c3..c9da26270 100644 --- a/cmd/zrok/adminCreateFrontend.go +++ b/cmd/zrok/adminCreateFrontend.go @@ -3,10 +3,10 @@ package main import ( "os" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/rest_client_zrok/admin" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -35,7 +35,7 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) { publicName := args[1] urlTemplate := args[2] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/adminCreateIdentity.go b/cmd/zrok/adminCreateIdentity.go index ee04feefd..61ae340f2 100644 --- a/cmd/zrok/adminCreateIdentity.go +++ b/cmd/zrok/adminCreateIdentity.go @@ -3,7 +3,7 @@ package main import ( "fmt" "github.com/openziti/zrok/rest_client_zrok/admin" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "os" @@ -32,7 +32,7 @@ func newAdminCreateIdentity() *adminCreateIdentity { func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) { name := args[0] - zif, err := zrokdir.ZitiIdentityFile(name) + zif, err := environment.ZitiIdentityFile(name) if err != nil { panic(err) } @@ -41,7 +41,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) { os.Exit(1) } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } @@ -59,7 +59,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) { panic(err) } - if err := zrokdir.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil { + if err := environment.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil { panic(err) } diff --git a/cmd/zrok/adminDeleteFrontend.go b/cmd/zrok/adminDeleteFrontend.go index 071889bed..4783fdeb7 100644 --- a/cmd/zrok/adminDeleteFrontend.go +++ b/cmd/zrok/adminDeleteFrontend.go @@ -3,7 +3,7 @@ package main import ( "github.com/openziti/zrok/rest_client_zrok/admin" "github.com/openziti/zrok/rest_model_zrok" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -30,7 +30,7 @@ func newAdminDeleteFrontendCommand() *adminDeleteFrontendCommand { func (cmd *adminDeleteFrontendCommand) run(_ *cobra.Command, args []string) { feToken := args[0] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/adminGenerate.go b/cmd/zrok/adminGenerate.go index afe5aa15c..26e7951a1 100644 --- a/cmd/zrok/adminGenerate.go +++ b/cmd/zrok/adminGenerate.go @@ -3,9 +3,9 @@ package main import ( "fmt" "github.com/jaevor/go-nanoid" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/rest_client_zrok/admin" "github.com/openziti/zrok/rest_model_zrok" - "github.com/openziti/zrok/zrokdir" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -43,9 +43,9 @@ func (cmd *adminGenerateCommand) run(_ *cobra.Command, args []string) { } } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { - logrus.Error("error loading zrokdir", err) + logrus.Error("error loading environment", err) } zrok, err := zrd.Client() diff --git a/cmd/zrok/adminListFrontends.go b/cmd/zrok/adminListFrontends.go index 8a8fbf640..5d63b3759 100644 --- a/cmd/zrok/adminListFrontends.go +++ b/cmd/zrok/adminListFrontends.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/jedib0t/go-pretty/v6/table" "github.com/openziti/zrok/rest_client_zrok/admin" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/spf13/cobra" "os" "time" @@ -31,7 +31,7 @@ func newAdminListFrontendsCommand() *adminListFrontendsCommand { } func (cmd *adminListFrontendsCommand) run(_ *cobra.Command, _ []string) { - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/adminUpdateFrontend.go b/cmd/zrok/adminUpdateFrontend.go index 2605458a0..1de2d9676 100644 --- a/cmd/zrok/adminUpdateFrontend.go +++ b/cmd/zrok/adminUpdateFrontend.go @@ -3,7 +3,7 @@ package main import ( "github.com/openziti/zrok/rest_client_zrok/admin" "github.com/openziti/zrok/rest_model_zrok" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -38,7 +38,7 @@ func (cmd *adminUpdateFrontendCommand) run(_ *cobra.Command, args []string) { panic("must specify at least one of public name or url template") } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/configGet.go b/cmd/zrok/configGet.go index 5340cf4b8..544177724 100644 --- a/cmd/zrok/configGet.go +++ b/cmd/zrok/configGet.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/spf13/cobra" ) @@ -28,7 +28,7 @@ func newConfigGetCommand() *configGetCommand { func (cmd *configGetCommand) run(_ *cobra.Command, args []string) { configName := args[0] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/configSet.go b/cmd/zrok/configSet.go index a72d29f40..13e9d6ce0 100644 --- a/cmd/zrok/configSet.go +++ b/cmd/zrok/configSet.go @@ -5,8 +5,8 @@ import ( "net/url" "os" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/spf13/cobra" ) @@ -33,7 +33,7 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { configName := args[0] value := args[1] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } @@ -42,7 +42,7 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) { switch configName { case "apiEndpoint": if zrd.Cfg == nil { - zrd.Cfg = &zrokdir.Config{} + zrd.Cfg = &environment.Config{} } ok, err := isFullyValidUrl(value) if err != nil { diff --git a/cmd/zrok/configUnset.go b/cmd/zrok/configUnset.go index 6d27a930d..2aa506123 100644 --- a/cmd/zrok/configUnset.go +++ b/cmd/zrok/configUnset.go @@ -3,7 +3,7 @@ package main import ( "fmt" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/spf13/cobra" "os" ) @@ -30,7 +30,7 @@ func newConfigUnsetCommand() *configUnsetCommand { func (cmd *configUnsetCommand) run(_ *cobra.Command, args []string) { configName := args[0] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } diff --git a/cmd/zrok/console.go b/cmd/zrok/console.go index 1650e6c1b..83eb97c3c 100644 --- a/cmd/zrok/console.go +++ b/cmd/zrok/console.go @@ -2,8 +2,8 @@ package main import ( "fmt" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/spf13/cobra" ) @@ -27,12 +27,12 @@ func newConsoleCommand() *consoleCommand { } func (cmd *consoleCommand) run(_ *cobra.Command, _ []string) { - zrd, err := zrokdir.Load() + env, err := environment.Load() if err != nil { - tui.Error("unable to load zrokdir", err) + tui.Error("unable to load environment", err) } - apiEndpoint, _ := zrd.ApiEndpoint() + apiEndpoint, _ := env.ApiEndpoint() if err := openBrowser(apiEndpoint); err != nil { tui.Error(fmt.Sprintf("unable to open '%v'", apiEndpoint), err) } diff --git a/cmd/zrok/disable.go b/cmd/zrok/disable.go index d1382e8cf..17e804d03 100644 --- a/cmd/zrok/disable.go +++ b/cmd/zrok/disable.go @@ -2,11 +2,11 @@ package main import ( "fmt" - httptransport "github.com/go-openapi/runtime/client" - "github.com/openziti/zrok/rest_client_zrok/environment" + httpTransport "github.com/go-openapi/runtime/client" + "github.com/openziti/zrok/environment" + restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -31,10 +31,10 @@ func newDisableCommand() *disableCommand { } func (cmd *disableCommand) run(_ *cobra.Command, _ []string) { - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("unable to load zrokdir", err) + tui.Error("unable to load environment", err) } panic(err) } @@ -50,8 +50,8 @@ func (cmd *disableCommand) run(_ *cobra.Command, _ []string) { } panic(err) } - auth := httptransport.APIKeyAuth("X-TOKEN", "header", zrd.Env.Token) - req := environment.NewDisableParams() + auth := httpTransport.APIKeyAuth("X-TOKEN", "header", zrd.Env.Token) + req := restEnvironment.NewDisableParams() req.Body = &rest_model_zrok.DisableRequest{ Identity: zrd.Env.ZId, } @@ -59,13 +59,13 @@ func (cmd *disableCommand) run(_ *cobra.Command, _ []string) { if err != nil { logrus.Warnf("share cleanup failed (%v); will clean up local environment", err) } - if err := zrokdir.DeleteEnvironment(); err != nil { + if err := environment.DeleteEnvironment(); err != nil { if !panicInstead { tui.Error("error removing zrok environment", err) } panic(err) } - if err := zrokdir.DeleteZitiIdentity("backend"); err != nil { + if err := environment.DeleteZitiIdentity("backend"); err != nil { if !panicInstead { tui.Error("error removing zrok backend identity", err) } diff --git a/cmd/zrok/enable.go b/cmd/zrok/enable.go index d9790f951..c6bf946c7 100644 --- a/cmd/zrok/enable.go +++ b/cmd/zrok/enable.go @@ -10,10 +10,10 @@ import ( "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" httptransport "github.com/go-openapi/runtime/client" - "github.com/openziti/zrok/rest_client_zrok/environment" + "github.com/openziti/zrok/environment" + restEnvironment "github.com/openziti/zrok/rest_client_zrok/environment" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/shirou/gopsutil/v3/host" "github.com/spf13/cobra" ) @@ -42,7 +42,7 @@ func newEnableCommand() *enableCommand { } func (cmd *enableCommand) run(_ *cobra.Command, args []string) { - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } @@ -70,7 +70,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { tui.Error("error creating service client", err) } auth := httptransport.APIKeyAuth("X-TOKEN", "header", token) - req := environment.NewEnableParams() + req := restEnvironment.NewEnableParams() req.Body = &rest_model_zrok.EnableRequest{ Description: cmd.description, Host: hostDetail, @@ -117,7 +117,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { prg.Send("writing the environment details...") } apiEndpoint, _ := zrd.ApiEndpoint() - zrd.Env = &zrokdir.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: apiEndpoint} + zrd.Env = &environment.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: apiEndpoint} if err := zrd.Save(); err != nil { if !cmd.headless && prg != nil { prg.Send(fmt.Sprintf("there was an error saving the new environment: %v", err)) @@ -131,7 +131,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { } os.Exit(1) } - if err := zrokdir.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil { + if err := environment.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil { if !cmd.headless && prg != nil { prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err)) prg.Quit() diff --git a/cmd/zrok/invite.go b/cmd/zrok/invite.go index ed33cf26d..1a69269a8 100644 --- a/cmd/zrok/invite.go +++ b/cmd/zrok/invite.go @@ -8,12 +8,12 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/rest_client_zrok/account" "github.com/openziti/zrok/rest_client_zrok/metadata" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" "github.com/openziti/zrok/util" - "github.com/openziti/zrok/zrokdir" "github.com/spf13/cobra" ) @@ -42,9 +42,9 @@ func newInviteCommand() *inviteCommand { } func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) { - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { - tui.Error("error loading zrokdir", err) + tui.Error("error loading environment", err) } zrok, err := zrd.Client() diff --git a/cmd/zrok/release.go b/cmd/zrok/release.go index 32b5525b0..967b3cd51 100644 --- a/cmd/zrok/release.go +++ b/cmd/zrok/release.go @@ -2,10 +2,10 @@ package main import ( httptransport "github.com/go-openapi/runtime/client" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/rest_client_zrok/share" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -31,10 +31,10 @@ func newReleaseCommand() *releaseCommand { func (cmd *releaseCommand) run(_ *cobra.Command, args []string) { shrToken := args[0] - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("unable to load zrokdir", err) + tui.Error("unable to load environment", err) } panic(err) } diff --git a/cmd/zrok/reserve.go b/cmd/zrok/reserve.go index bf21b6648..d39237576 100644 --- a/cmd/zrok/reserve.go +++ b/cmd/zrok/reserve.go @@ -2,11 +2,11 @@ package main import ( httptransport "github.com/go-openapi/runtime/client" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" "github.com/openziti/zrok/rest_client_zrok/share" "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -60,10 +60,10 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) { target = args[1] } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("error loading zrokdir", err) + tui.Error("error loading environment", err) } panic(err) } diff --git a/cmd/zrok/sharePrivate.go b/cmd/zrok/sharePrivate.go index 049d91a52..a3e6c3c99 100644 --- a/cmd/zrok/sharePrivate.go +++ b/cmd/zrok/sharePrivate.go @@ -9,12 +9,12 @@ import ( "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/tcpTunnel" "github.com/openziti/zrok/endpoints/udpTunnel" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" "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/tui" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -78,10 +78,10 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { tui.Error(fmt.Sprintf("invalid backend mode '%v'; expected {proxy, web, tcpTunnel}", cmd.backendMode), nil) } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("unable to load zrokdir", err) + tui.Error("unable to load environment", err) } panic(err) } @@ -90,7 +90,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { tui.Error("unable to load environment; did you 'zrok enable'?", nil) } - zif, err := zrokdir.ZitiIdentityFile("backend") + zif, err := environment.ZitiIdentityFile("backend") if err != nil { if !panicInstead { tui.Error("unable to load ziti identity configuration", err) diff --git a/cmd/zrok/sharePublic.go b/cmd/zrok/sharePublic.go index 336c51b7b..d88e2ea7b 100644 --- a/cmd/zrok/sharePublic.go +++ b/cmd/zrok/sharePublic.go @@ -7,12 +7,12 @@ import ( httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/endpoints/proxy" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" "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/tui" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -72,10 +72,10 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { tui.Error(fmt.Sprintf("invalid backend mode '%v'; expected {proxy, web}", cmd.backendMode), nil) } - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("unable to load zrokdir", err) + tui.Error("unable to load environment", err) } panic(err) } @@ -84,7 +84,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { tui.Error("unable to load environment; did you 'zrok enable'?", nil) } - zif, err := zrokdir.ZitiIdentityFile("backend") + zif, err := environment.ZitiIdentityFile("backend") if err != nil { if !panicInstead { tui.Error("unable to load ziti identity configuration", err) diff --git a/cmd/zrok/shareReserved.go b/cmd/zrok/shareReserved.go index dafeeb569..ac3300134 100644 --- a/cmd/zrok/shareReserved.go +++ b/cmd/zrok/shareReserved.go @@ -6,11 +6,11 @@ import ( httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/endpoints/proxy" + "github.com/openziti/zrok/environment" "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/tui" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -44,10 +44,10 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) { shrToken := args[0] var target string - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { if !panicInstead { - tui.Error("error loading zrokdir", err) + tui.Error("error loading environment", err) } panic(err) } @@ -78,7 +78,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) { target = resp.Payload.BackendProxyEndpoint } - zif, err := zrokdir.ZitiIdentityFile("backend") + zif, err := environment.ZitiIdentityFile("backend") if err != nil { if !panicInstead { tui.Error("unable to load ziti identity configuration", err) diff --git a/cmd/zrok/status.go b/cmd/zrok/status.go index 3cdccb8be..8728dd17b 100644 --- a/cmd/zrok/status.go +++ b/cmd/zrok/status.go @@ -3,8 +3,8 @@ package main import ( "fmt" "github.com/jedib0t/go-pretty/v6/table" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/tui" - "github.com/openziti/zrok/zrokdir" "github.com/spf13/cobra" "os" ) @@ -34,9 +34,9 @@ func newStatusCommand() *statusCommand { func (cmd *statusCommand) run(_ *cobra.Command, _ []string) { _, _ = fmt.Fprintf(os.Stderr, "\n") - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { - tui.Error("unable to load zrokdir", err) + tui.Error("error loading environment", err) } _, _ = fmt.Fprintf(os.Stdout, tui.Code.Render("Config")+":\n\n") diff --git a/cmd/zrok/testLoopPublic.go b/cmd/zrok/testLoopPublic.go index 7f7da5503..1e66e8f8e 100644 --- a/cmd/zrok/testLoopPublic.go +++ b/cmd/zrok/testLoopPublic.go @@ -14,7 +14,7 @@ import ( "github.com/openziti/zrok/rest_model_zrok" "github.com/openziti/zrok/tui" "github.com/openziti/zrok/util" - "github.com/openziti/zrok/zrokdir" + "github.com/openziti/zrok/environment" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "io" @@ -105,7 +105,7 @@ func (cmd *testLoopPublicCommand) run(_ *cobra.Command, _ []string) { type looper struct { id int cmd *testLoopPublicCommand - env *zrokdir.Environment + env *environment.Environment done chan struct{} listener edge.Listener zif string @@ -175,7 +175,7 @@ func (l *looper) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (l *looper) startup() { logrus.Infof("starting #%d", l.id) - zrd, err := zrokdir.Load() + zrd, err := environment.Load() if err != nil { panic(err) } @@ -185,7 +185,7 @@ func (l *looper) startup() { } l.env = zrd.Env - l.zif, err = zrokdir.ZitiIdentityFile("backend") + l.zif, err = environment.ZitiIdentityFile("backend") if err != nil { panic(err) } diff --git a/controller/bootstrap.go b/controller/bootstrap.go index 084c51b14..70929f93c 100644 --- a/controller/bootstrap.go +++ b/controller/bootstrap.go @@ -14,8 +14,8 @@ import ( zrok_config "github.com/openziti/zrok/controller/config" "github.com/openziti/zrok/controller/store" "github.com/openziti/zrok/controller/zrokEdgeSdk" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "time" @@ -133,9 +133,9 @@ func assertZrokProxyConfigType(edge *rest_management_api_client.ZitiEdgeManageme } func getIdentityId(identityName string) (string, error) { - zif, err := zrokdir.ZitiIdentityFile(identityName) + zif, err := environment.ZitiIdentityFile(identityName) if err != nil { - return "", errors.Wrapf(err, "error opening identity '%v' from zrokdir", identityName) + return "", errors.Wrapf(err, "error opening identity '%v' from environment", identityName) } zcfg, err := ziti.NewConfigFromFile(zif) if err != nil { @@ -195,7 +195,7 @@ func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeMan if err != nil { return "", errors.Wrapf(err, "error encoding identity config '%v'", name) } - if err := zrokdir.SaveZitiIdentity(name, out.String()); err != nil { + if err := environment.SaveZitiIdentity(name, out.String()); err != nil { return "", errors.Wrapf(err, "error saving identity config '%v'", name) } return zId, nil diff --git a/docs/_attic/overview.md b/docs/_attic/overview.md index d098ac634..9aa3a3d7f 100644 --- a/docs/_attic/overview.md +++ b/docs/_attic/overview.md @@ -56,15 +56,15 @@ When the user runs `zrok enable` from their shell, here's what happens: 2. The `zrok` controller creates a new OpenZiti identity for the environment and enrolls it. 3. The `zrok` controller creates an edge router policy associating the new OpenZiti identity with `#all` edge routers. 4. The `zrok` controller returns the entire SDK configuration back to the `zrok enable` client. -5. The `zrok enable` client then stores the OpenZiti identity along with a few other housekeeping details in the user's `~/.zrok` folder (we refer to this as `zrokdir`, conceptually in the code). -6. With the OpenZiti identity and configuration details stored in the user's `zrokdir`, the user is then able to create any number of binding endpoints using the `zrok http` command. +5. The `zrok enable` client then stores the OpenZiti identity along with a few other housekeeping details in the user's `~/.zrok` folder. +6. With the OpenZiti identity and configuration details stored in the user's `environment`, the user is then able to create any number of binding endpoints using the `zrok http` command. ### The `zrok http` Flow When a `zrok` user issues a `zrok http` command for an endpoint, here's what happens: -1. The `zrok http` client gathers the necessary identity details from the `zrokdir` (this was all staged during `zrok enable`). +1. The `zrok http` client gathers the necessary identity details from the `environment` (this was all staged during `zrok enable`). 2. The `zrok http` client reaches out to the `zrok` controller with an authenticated `tunnel` request, asking to have a new endpoint binding created. 3. The `zrok` controller allocates a new "service name" for the binding. 4. The `zrok` controller creates a `zrok.proxy.v1` configuration describing the user's requested authentication details (currently: `none` or `basic`). diff --git a/docs/getting-started.md b/docs/getting-started.md index 7ab2fe795..45cac38ba 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -107,13 +107,13 @@ The `zrok` executable defaults to using the `zrok` service instance at `api.zrok ``` $ zrok config set apiEndpoint https://zrok.mydomain.com -[WARNING]: unable to open zrokdir metadata; ignoring +[WARNING]: unable to open environment metadata; ignoring zrok configuration updated ``` :::note -The `WARNING` about `zrokdir metadata` is ignorable. Running the `zrok config set` command writes a small piece of metadata into a `.zrok` folder inside your home directory. This allows `zrok` to identify the version of its settings, providing a mechanism to upgrade your installation as new versions are released. This `WARNING` is letting you know that your current environment has not been initialized by `zrok`. +The `WARNING` about `environment metadata` is ignorable. Running the `zrok config set` command writes a small piece of metadata into a `.zrok` folder inside your home directory. This allows `zrok` to identify the version of its settings, providing a mechanism to upgrade your installation as new versions are released. This `WARNING` is letting you know that your current environment has not been initialized by `zrok`. ::: You can use the `zrok status` command to inspect the state of your local _environment_. `zrok` refers to each shell where you install and `enable` a copy of `zrok` as as an _environment_. diff --git a/endpoints/proxy/frontend.go b/endpoints/proxy/frontend.go index be6393357..d38ea3e60 100644 --- a/endpoints/proxy/frontend.go +++ b/endpoints/proxy/frontend.go @@ -6,9 +6,9 @@ import ( "github.com/openziti/sdk-golang/ziti" "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/endpoints/publicProxy/notFoundUi" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" "github.com/openziti/zrok/util" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "net" @@ -40,9 +40,9 @@ type Frontend struct { } func NewFrontend(cfg *FrontendConfig) (*Frontend, error) { - zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName) + zCfgPath, err := environment.ZitiIdentityFile(cfg.IdentityName) if err != nil { - return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName) + return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName) } zCfg, err := ziti.NewConfigFromFile(zCfgPath) if err != nil { diff --git a/endpoints/publicProxy/http.go b/endpoints/publicProxy/http.go index e9aab21b8..42672b95f 100644 --- a/endpoints/publicProxy/http.go +++ b/endpoints/publicProxy/http.go @@ -7,9 +7,9 @@ import ( "github.com/openziti/zrok/endpoints" "github.com/openziti/zrok/endpoints/publicProxy/healthUi" "github.com/openziti/zrok/endpoints/publicProxy/notFoundUi" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" "github.com/openziti/zrok/util" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "net" @@ -26,9 +26,9 @@ type httpFrontend struct { } func NewHTTP(cfg *Config) (*httpFrontend, error) { - zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity) + zCfgPath, err := environment.ZitiIdentityFile(cfg.Identity) if err != nil { - return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.Identity) + return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.Identity) } zCfg, err := ziti.NewConfigFromFile(zCfgPath) if err != nil { diff --git a/endpoints/tcpTunnel/frontend.go b/endpoints/tcpTunnel/frontend.go index 217a63530..f4f9e3aa4 100644 --- a/endpoints/tcpTunnel/frontend.go +++ b/endpoints/tcpTunnel/frontend.go @@ -3,8 +3,8 @@ package tcpTunnel import ( "github.com/openziti/sdk-golang/ziti" "github.com/openziti/zrok/endpoints" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "net" @@ -29,9 +29,9 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) { if err != nil { return nil, errors.Wrapf(err, "error resolving tcp address '%v'", cfg.BindAddress) } - zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName) + zCfgPath, err := environment.ZitiIdentityFile(cfg.IdentityName) if err != nil { - return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName) + return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName) } zCfg, err := ziti.NewConfigFromFile(zCfgPath) if err != nil { diff --git a/endpoints/udpTunnel/frontend.go b/endpoints/udpTunnel/frontend.go index 954433cbc..785597f9c 100644 --- a/endpoints/udpTunnel/frontend.go +++ b/endpoints/udpTunnel/frontend.go @@ -3,8 +3,8 @@ package udpTunnel import ( "github.com/openziti/sdk-golang/ziti" "github.com/openziti/zrok/endpoints" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/model" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" "github.com/sirupsen/logrus" "net" @@ -99,9 +99,9 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) { if err != nil { return nil, errors.Wrapf(err, "error resolving udp address '%v'", cfg.BindAddress) } - zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName) + zCfgPath, err := environment.ZitiIdentityFile(cfg.IdentityName) if err != nil { - return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName) + return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName) } zCfg, err := ziti.NewConfigFromFile(zCfgPath) if err != nil { diff --git a/zrokdir/client.go b/environment/client.go similarity index 89% rename from zrokdir/client.go rename to environment/client.go index 2f41b47b0..62f0983a5 100644 --- a/zrokdir/client.go +++ b/environment/client.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "github.com/go-openapi/runtime" @@ -12,7 +12,7 @@ import ( "regexp" ) -func (zrd *ZrokDir) Client() (*rest_client_zrok.Zrok, error) { +func (zrd *Root) Client() (*rest_client_zrok.Zrok, error) { apiEndpoint, _ := zrd.ApiEndpoint() apiUrl, err := url.Parse(apiEndpoint) if err != nil { @@ -30,14 +30,14 @@ func (zrd *ZrokDir) Client() (*rest_client_zrok.Zrok, error) { // allow reported version string to be optionally prefixed with // "refs/heads/" or "refs/tags/" re := regexp.MustCompile(`^(refs/(heads|tags)/)?` + build.Series) - if ! re.MatchString(string(v.Payload)) { + if !re.MatchString(string(v.Payload)) { return nil, errors.Errorf("expected a '%v' version, received: '%v'", build.Series, v.Payload) } return zrok, nil } -func (zrd *ZrokDir) ApiEndpoint() (apiEndpoint string, from string) { +func (zrd *Root) ApiEndpoint() (apiEndpoint string, from string) { apiEndpoint = "https://api.zrok.io" from = "binary" diff --git a/zrokdir/config.go b/environment/config.go similarity index 92% rename from zrokdir/config.go rename to environment/config.go index d8e77cfdc..181758ff3 100644 --- a/zrokdir/config.go +++ b/environment/config.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "encoding/json" @@ -52,7 +52,7 @@ func saveConfig(cfg *Config) error { return errors.Wrap(err, "error getting config file path") } if err := os.MkdirAll(filepath.Dir(cf), os.FileMode(0700)); err != nil { - return errors.Wrapf(err, "error creating zrokdir path '%v'", filepath.Dir(cf)) + return errors.Wrapf(err, "error creating environment path '%v'", filepath.Dir(cf)) } if err := os.WriteFile(cf, data, os.FileMode(0600)); err != nil { return errors.Wrap(err, "error saving config file") diff --git a/zrokdir/environment.go b/environment/environment.go similarity index 94% rename from zrokdir/environment.go rename to environment/environment.go index 56b502276..300db0532 100644 --- a/zrokdir/environment.go +++ b/environment/environment.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "encoding/json" @@ -54,7 +54,7 @@ func saveEnvironment(env *Environment) error { return errors.Wrap(err, "error getting environment file") } if err := os.MkdirAll(filepath.Dir(ef), os.FileMode(0700)); err != nil { - return errors.Wrapf(err, "error creating zrokdir path '%v'", filepath.Dir(ef)) + return errors.Wrapf(err, "error creating environment path '%v'", filepath.Dir(ef)) } if err := os.WriteFile(ef, data, os.FileMode(0600)); err != nil { return errors.Wrap(err, "error saving environment file") diff --git a/zrokdir/identity.go b/environment/identity.go similarity index 88% rename from zrokdir/identity.go rename to environment/identity.go index 4c912ebc0..b3ef5a6f0 100644 --- a/zrokdir/identity.go +++ b/environment/identity.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "github.com/pkg/errors" @@ -16,7 +16,7 @@ func SaveZitiIdentity(name, data string) error { return err } if err := os.MkdirAll(filepath.Dir(zif), os.FileMode(0700)); err != nil { - return errors.Wrapf(err, "error creating zrokdir path '%v'", filepath.Dir(zif)) + return errors.Wrapf(err, "error creating environment path '%v'", filepath.Dir(zif)) } if err := os.WriteFile(zif, []byte(data), os.FileMode(0600)); err != nil { return errors.Wrapf(err, "error writing ziti identity file '%v'", zif) diff --git a/zrokdir/zrokdir.go b/environment/root.go similarity index 75% rename from zrokdir/zrokdir.go rename to environment/root.go index 9c8d0c710..d50ef165a 100644 --- a/zrokdir/zrokdir.go +++ b/environment/root.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "fmt" @@ -8,39 +8,39 @@ import ( "strings" ) -type ZrokDir struct { +type Root struct { Env *Environment Cfg *Config identities map[string]struct{} } -func Initialize() (*ZrokDir, error) { - zrd, err := zrokDir() +func Initialize() (*Root, error) { + zrd, err := rootDir() if err != nil { - return nil, errors.Wrap(err, "error getting zrokdir path") + return nil, errors.Wrap(err, "error getting environment path") } if err := os.MkdirAll(zrd, os.FileMode(0700)); err != nil { - return nil, errors.Wrapf(err, "error creating zrokdir root path '%v'", zrd) + return nil, errors.Wrapf(err, "error creating environment root path '%v'", zrd) } if err := DeleteEnvironment(); err != nil { return nil, errors.Wrap(err, "error deleting environment") } idd, err := identitiesDir() if err != nil { - return nil, errors.Wrap(err, "error getting zrokdir identities path") + return nil, errors.Wrap(err, "error getting environment identities path") } if err := os.MkdirAll(idd, os.FileMode(0700)); err != nil { - return nil, errors.Wrapf(err, "error creating zrokdir identities root path '%v'", idd) + return nil, errors.Wrapf(err, "error creating environment identities root path '%v'", idd) } return Load() } -func Load() (*ZrokDir, error) { +func Load() (*Root, error) { if err := checkMetadata(); err != nil { return nil, err } - zrd := &ZrokDir{} + zrd := &Root{} ids, err := listIdentities() if err != nil { @@ -75,7 +75,7 @@ func Load() (*ZrokDir, error) { return zrd, nil } -func (zrd *ZrokDir) Save() error { +func (zrd *Root) Save() error { if err := writeMetadata(); err != nil { return errors.Wrap(err, "error saving metadata") } @@ -93,7 +93,7 @@ func (zrd *ZrokDir) Save() error { } func Obliterate() error { - zrd, err := zrokDir() + zrd, err := rootDir() if err != nil { return err } @@ -108,18 +108,18 @@ func listIdentities() (map[string]struct{}, error) { idd, err := identitiesDir() if err != nil { - return nil, errors.Wrap(err, "error getting zrokdir identities path") + return nil, errors.Wrap(err, "error getting environment identities path") } _, err = os.Stat(idd) if os.IsNotExist(err) { return ids, nil } if err != nil { - return nil, errors.Wrapf(err, "error stat-ing zrokdir identities root '%v'", idd) + return nil, errors.Wrapf(err, "error stat-ing environment identities root '%v'", idd) } des, err := os.ReadDir(idd) if err != nil { - return nil, errors.Wrapf(err, "error listing zrokdir identities from '%v'", idd) + return nil, errors.Wrapf(err, "error listing environment identities from '%v'", idd) } for _, de := range des { if strings.HasSuffix(de.Name(), ".json") && !de.IsDir() { @@ -131,7 +131,7 @@ func listIdentities() (map[string]struct{}, error) { } func configFile() (string, error) { - zrd, err := zrokDir() + zrd, err := rootDir() if err != nil { return "", err } @@ -139,7 +139,7 @@ func configFile() (string, error) { } func environmentFile() (string, error) { - zrd, err := zrokDir() + zrd, err := rootDir() if err != nil { return "", err } @@ -155,7 +155,7 @@ func identityFile(name string) (string, error) { } func identitiesDir() (string, error) { - zrd, err := zrokDir() + zrd, err := rootDir() if err != nil { return "", err } @@ -163,14 +163,14 @@ func identitiesDir() (string, error) { } func metadataFile() (string, error) { - zrd, err := zrokDir() + zrd, err := rootDir() if err != nil { return "", err } return filepath.Join(zrd, "metadata.json"), nil } -func zrokDir() (string, error) { +func rootDir() (string, error) { home, err := os.UserHomeDir() if err != nil { return "", err diff --git a/zrokdir/version.go b/environment/version.go similarity index 84% rename from zrokdir/version.go rename to environment/version.go index e073aa99f..e75238ed1 100644 --- a/zrokdir/version.go +++ b/environment/version.go @@ -1,4 +1,4 @@ -package zrokdir +package environment import ( "encoding/json" @@ -21,7 +21,7 @@ func checkMetadata() error { } data, err := os.ReadFile(mf) if err != nil { - tui.Warning("unable to open zrokdir metadata; ignoring\n") + tui.Warning("unable to open environment metadata; ignoring\n") return nil } m := &Metadata{} @@ -29,7 +29,7 @@ func checkMetadata() error { return errors.Wrapf(err, "error unmarshaling metadata file '%v'", mf) } if m.V != V { - return errors.Errorf("invalid zrokdir metadata version '%v'", m.V) + return errors.Errorf("invalid environment metadata version '%v'", m.V) } return nil } diff --git a/sdk/share.go b/sdk/share.go index 0a09e8d05..d98f9b5b3 100644 --- a/sdk/share.go +++ b/sdk/share.go @@ -1,8 +1,8 @@ package sdk import ( + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/rest_model_zrok" - "github.com/openziti/zrok/zrokdir" "github.com/pkg/errors" ) @@ -29,14 +29,14 @@ func newPublicShare(request *ShareRequest) (*Share, error) { return nil, nil } -func loadEnvironment(request *ShareRequest) (*zrokdir.ZrokDir, error) { - zrd, err := zrokdir.Load() +func loadEnvironment(request *ShareRequest) (*environment.Root, error) { + env, err := environment.Load() if err != nil { - return nil, errors.Wrap(err, "error loading zrokdir") + return nil, errors.Wrap(err, "error loading environment") } - return zrd, nil + return env, nil } -func createShare(zrd *zrokdir.ZrokDir, req *rest_model_zrok.ShareRequest) (*Share, error) { +func createShare(zrd *environment.Root, req *rest_model_zrok.ShareRequest) (*Share, error) { return nil, nil }