Skip to content

Commit

Permalink
migrated all usages to the new package (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jul 13, 2023
1 parent 7bfafd4 commit 04b0b64
Show file tree
Hide file tree
Showing 38 changed files with 528 additions and 876 deletions.
16 changes: 8 additions & 8 deletions cmd/zrok/accessPrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/openziti/zrok/endpoints/proxy"
"github.com/openziti/zrok/endpoints/tcpTunnel"
"github.com/openziti/zrok/endpoints/udpTunnel"
"github.com/openziti/zrok/environment/env_v0_3"
"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"
Expand Down Expand Up @@ -48,28 +48,28 @@ func newAccessPrivateCommand() *accessPrivateCommand {
func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
shrToken := args[0]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
tui.Error("error loading environment", err)
}

if zrd.Env == nil {
if !env.IsEnabled() {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
if !panicInstead {
tui.Error("unable to create zrok client", err)
}
panic(err)
}

auth := httptransport.APIKeyAuth("X-TOKEN", "header", zrd.Env.Token)
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Environment().Token)
req := share.NewAccessParams()
req.Body = &rest_model_zrok.AccessRequest{
ShrToken: shrToken,
EnvZID: zrd.Env.ZId,
EnvZID: env.Environment().ZitiIdentity,
}
accessResp, err := zrok.Share.Access(req, auth)
if err != nil {
Expand Down Expand Up @@ -168,7 +168,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
cmd.destroy(accessResp.Payload.FrontendToken, env.Environment().ZitiIdentity, shrToken, zrok, auth)
os.Exit(0)
}()

Expand Down Expand Up @@ -203,7 +203,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
}

close(requests)
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
cmd.destroy(accessResp.Payload.FrontendToken, env.Environment().ZitiIdentity, shrToken, zrok, auth)
}
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/zrok/adminCreateFrontend.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package main

import (
"github.com/openziti/zrok/environment/env_v0_3"
"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/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
)

func init() {
Expand All @@ -35,12 +34,12 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
publicName := args[1]
urlTemplate := args[2]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
panic(err)
}
Expand Down
17 changes: 8 additions & 9 deletions cmd/zrok/adminCreateIdentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -32,7 +32,11 @@ func newAdminCreateIdentity() *adminCreateIdentity {
func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
name := args[0]

zif, err := env_v0_3.ZitiIdentityFile(name)
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}
zif, err := env.ZitiIdentityFile(name)
if err != nil {
panic(err)
}
Expand All @@ -41,12 +45,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
os.Exit(1)
}

zrd, err := env_v0_3.Load()
if err != nil {
panic(err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
panic(err)
}
Expand All @@ -59,7 +58,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
panic(err)
}

if err := env_v0_3.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil {
if err := env.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil {
panic(err)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/zrok/adminDeleteFrontend.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -30,12 +30,12 @@ func newAdminDeleteFrontendCommand() *adminDeleteFrontendCommand {
func (cmd *adminDeleteFrontendCommand) run(_ *cobra.Command, args []string) {
feToken := args[0]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/zrok/adminGenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/jaevor/go-nanoid"
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -43,12 +43,12 @@ func (cmd *adminGenerateCommand) run(_ *cobra.Command, args []string) {
}
}

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
logrus.Error("error loading environment", err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
if !panicInstead {
logrus.Error("error creating zrok api client", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/zrok/adminListFrontends.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/spf13/cobra"
"os"
Expand Down Expand Up @@ -31,12 +31,12 @@ func newAdminListFrontendsCommand() *adminListFrontendsCommand {
}

func (cmd *adminListFrontendsCommand) run(_ *cobra.Command, _ []string) {
zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/zrok/adminUpdateFrontend.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,12 +38,12 @@ func (cmd *adminUpdateFrontendCommand) run(_ *cobra.Command, args []string) {
panic("must specify at least one of public name or url template")
}

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

zrok, err := zrd.Client()
zrok, err := env.Client()
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/zrok/configGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/spf13/cobra"
)

Expand All @@ -28,15 +28,15 @@ func newConfigGetCommand() *configGetCommand {
func (cmd *configGetCommand) run(_ *cobra.Command, args []string) {
configName := args[0]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

switch configName {
case "apiEndpoint":
if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" {
fmt.Printf("apiEndpoint = %v\n", zrd.Cfg.ApiEndpoint)
if env.Config() != nil && env.Config().ApiEndpoint != "" {
fmt.Printf("apiEndpoint = %v\n", env.Config().ApiEndpoint)
} else {
fmt.Println("apiEndpoint = <unset>")
}
Expand Down
43 changes: 20 additions & 23 deletions cmd/zrok/configSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"fmt"
"github.com/openziti/zrok/environment/env_v0_3"
"net/url"
"os"

"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/tui"
"github.com/spf13/cobra"
"net/url"
"os"
)

func init() {
Expand All @@ -33,42 +33,39 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
configName := args[0]
value := args[1]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

modified := false
switch configName {
case "apiEndpoint":
if zrd.Cfg == nil {
zrd.Cfg = &env_v0_3.Config{}
}
ok, err := isFullyValidUrl(value)
if err != nil {
tui.Error("unable to validate api endpoint", err)
}
if !ok {
tui.Error("invalid apiEndpoint; please make sure URL starts with http:// or https://", nil)
}
zrd.Cfg.ApiEndpoint = value
modified = true

default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}

if modified {
if err := zrd.Save(); err != nil {
panic(err)
if env.Config() == nil {
if err := env.SetConfig(&env_core.Config{ApiEndpoint: value}); err != nil {
tui.Error("unable to save config", err)
}
} else {
cfg := env.Config()
cfg.ApiEndpoint = value
if err := env.SetConfig(cfg); err != nil {
tui.Error("unable to save config", err)
}
}
fmt.Println("zrok configuration updated")
if zrd.Env != nil && configName == "apiEndpoint" {
if env.IsEnabled() {
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
}
} else {
fmt.Println("zrok configuration not changed")

default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}
}

Expand Down
27 changes: 9 additions & 18 deletions cmd/zrok/configUnset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package main

import (
"fmt"
"github.com/openziti/zrok/environment/env_v0_3"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/tui"
"github.com/spf13/cobra"
"os"
Expand Down Expand Up @@ -30,33 +31,23 @@ func newConfigUnsetCommand() *configUnsetCommand {
func (cmd *configUnsetCommand) run(_ *cobra.Command, args []string) {
configName := args[0]

zrd, err := env_v0_3.Load()
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}

modified := false
switch configName {
case "apiEndpoint":
if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" {
zrd.Cfg.ApiEndpoint = ""
modified = true
if err := env.SetConfig(&env_core.Config{}); err != nil {
tui.Error("unable to save config", err)
}
fmt.Println("zrok configuration updated")
if env.IsEnabled() {
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
}

default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}

if modified {
if err := zrd.Save(); err != nil {
panic(err)
}
fmt.Println("zrok configuration updated")
if zrd.Env != nil && configName == "apiEndpoint" {
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
}
} else {
fmt.Println("zrok configuration not changed")
}
}
Loading

0 comments on commit 04b0b64

Please sign in to comment.