zrokdir -> environment (#34)

This commit is contained in:
Michael Quigley 2023-07-10 16:41:16 -04:00
parent 917ba12ce6
commit ea71493f2f
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
35 changed files with 132 additions and 132 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -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)
}

View File

@ -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

View File

@ -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`).

View File

@ -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_.

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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"

View File

@ -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")

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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
}