diff --git a/cmd/zrok/testLoopPublic.go b/cmd/zrok/testLoopPublic.go index 1e66e8f8..902ec482 100644 --- a/cmd/zrok/testLoopPublic.go +++ b/cmd/zrok/testLoopPublic.go @@ -8,13 +8,13 @@ import ( httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/sdk-golang/ziti" "github.com/openziti/sdk-golang/ziti/edge" + "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/util" - "github.com/openziti/zrok/environment" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "io" diff --git a/environment/client.go b/environment/client.go index 62f0983a..bb752a81 100644 --- a/environment/client.go +++ b/environment/client.go @@ -12,11 +12,11 @@ import ( "regexp" ) -func (zrd *Root) Client() (*rest_client_zrok.Zrok, error) { - apiEndpoint, _ := zrd.ApiEndpoint() +func (r *Root) Client() (*rest_client_zrok.Zrok, error) { + apiEndpoint, _ := r.ApiEndpoint() apiUrl, err := url.Parse(apiEndpoint) if err != nil { - return nil, errors.Wrapf(err, "error parsing api endpoint '%v'", zrd) + return nil, errors.Wrapf(err, "error parsing api endpoint '%v'", r) } transport := httptransport.New(apiUrl.Host, "/api/v1", []string{apiUrl.Scheme}) transport.Producers["application/zrok.v1+json"] = runtime.JSONProducer() @@ -37,12 +37,12 @@ func (zrd *Root) Client() (*rest_client_zrok.Zrok, error) { return zrok, nil } -func (zrd *Root) ApiEndpoint() (apiEndpoint string, from string) { +func (r *Root) ApiEndpoint() (apiEndpoint string, from string) { apiEndpoint = "https://api.zrok.io" from = "binary" - if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" { - apiEndpoint = zrd.Cfg.ApiEndpoint + if r.Cfg != nil && r.Cfg.ApiEndpoint != "" { + apiEndpoint = r.Cfg.ApiEndpoint from = "config" } @@ -52,8 +52,8 @@ func (zrd *Root) ApiEndpoint() (apiEndpoint string, from string) { from = "ZROK_API_ENDPOINT" } - if zrd.Env != nil && zrd.Env.ApiEndpoint != "" { - apiEndpoint = zrd.Env.ApiEndpoint + if r.Env != nil && r.Env.ApiEndpoint != "" { + apiEndpoint = r.Env.ApiEndpoint from = "env" } diff --git a/environment/config.go b/environment/config.go index 181758ff..46931e5b 100644 --- a/environment/config.go +++ b/environment/config.go @@ -11,7 +11,7 @@ type Config struct { ApiEndpoint string `json:"api_endpoint"` } -func hasConfig() (bool, error) { +func HasConfig() (bool, error) { cf, err := configFile() if err != nil { return false, errors.Wrap(err, "error getting config file path") @@ -26,7 +26,7 @@ func hasConfig() (bool, error) { return true, nil } -func loadConfig() (*Config, error) { +func LoadConfig() (*Config, error) { cf, err := configFile() if err != nil { return nil, errors.Wrap(err, "error getting config file path") @@ -42,7 +42,7 @@ func loadConfig() (*Config, error) { return cfg, nil } -func saveConfig(cfg *Config) error { +func SaveConfig(cfg *Config) error { data, err := json.MarshalIndent(cfg, "", " ") if err != nil { return errors.Wrap(err, "error marshaling config") diff --git a/environment/environment.go b/environment/environment.go index 300db053..8542ab30 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -13,7 +13,7 @@ type Environment struct { ApiEndpoint string `json:"api_endpoint"` } -func hasEnvironment() (bool, error) { +func IsEnabled() (bool, error) { ef, err := environmentFile() if err != nil { return false, errors.Wrap(err, "error getting environment file path") diff --git a/environment/root.go b/environment/root.go index d50ef165..ff015350 100644 --- a/environment/root.go +++ b/environment/root.go @@ -48,19 +48,19 @@ func Load() (*Root, error) { } zrd.identities = ids - hasCfg, err := hasConfig() + hasCfg, err := HasConfig() if err != nil { return nil, err } if hasCfg { - cfg, err := loadConfig() + cfg, err := LoadConfig() if err != nil { return nil, err } zrd.Cfg = cfg } - hasEnv, err := hasEnvironment() + hasEnv, err := IsEnabled() if err != nil { return nil, err } @@ -75,17 +75,17 @@ func Load() (*Root, error) { return zrd, nil } -func (zrd *Root) Save() error { +func (r *Root) Save() error { if err := writeMetadata(); err != nil { return errors.Wrap(err, "error saving metadata") } - if zrd.Env != nil { - if err := saveEnvironment(zrd.Env); err != nil { + if r.Env != nil { + if err := saveEnvironment(r.Env); err != nil { return errors.Wrap(err, "error saving environment") } } - if zrd.Cfg != nil { - if err := saveConfig(zrd.Cfg); err != nil { + if r.Cfg != nil { + if err := SaveConfig(r.Cfg); err != nil { return errors.Wrap(err, "error saving config") } }