diff --git a/cmd/zrok/enable.go b/cmd/zrok/enable.go index faa7b6e0..9469e60c 100644 --- a/cmd/zrok/enable.go +++ b/cmd/zrok/enable.go @@ -69,7 +69,8 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) { } panic(err) } - zrd.Env = &zrokdir.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: zrd.ApiEndpoint()} + apiEndpoint, _ := zrd.ApiEndpoint() + zrd.Env = &zrokdir.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: apiEndpoint} if err := zrd.Save(); err != nil { if !panicInstead { showError("there was an error saving the new environment", err) diff --git a/cmd/zrok/status.go b/cmd/zrok/status.go index 371cbf04..d7f815c5 100644 --- a/cmd/zrok/status.go +++ b/cmd/zrok/status.go @@ -36,22 +36,29 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) { showError("unable to load zrokdir", err) } + _, _ = fmt.Fprintf(os.Stdout, codeStyle.Render("Config")+":\n\n") + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.SetStyle(table.StyleColoredDark) + t.AppendHeader(table.Row{"Property", "Value", "Source"}) + apiEndpoint, from := zrd.ApiEndpoint() + t.AppendRow(table.Row{"API Endpoint", apiEndpoint, from}) + t.Render() + _, _ = fmt.Fprintf(os.Stderr, "\n") + if zrd.Env == nil { _, _ = fmt.Fprintf(os.Stderr, "%v: Unable to load your local environment!\n\n", warningLabel) _, _ = fmt.Fprintf(os.Stderr, "To create a local environment use the %v command.\n", codeStyle.Render("zrok enable")) } else { - _, _ = fmt.Fprintf(os.Stdout, codeStyle.Render("Environment"+":\n")) - _, _ = fmt.Fprintf(os.Stdout, "\n") + _, _ = fmt.Fprintf(os.Stdout, codeStyle.Render("Environment")+":\n\n") t := table.NewWriter() t.SetOutputMirror(os.Stdout) t.SetStyle(table.StyleColoredDark) t.AppendHeader(table.Row{"Property", "Value"}) - t.AppendRow(table.Row{"API Endpoint", zrd.Env.ApiEndpoint}) t.AppendRow(table.Row{"Secret Token", zrd.Env.Token}) t.AppendRow(table.Row{"Ziti Identity", zrd.Env.ZId}) t.Render() } - - _, _ = fmt.Fprintf(os.Stderr, "\n") + _, _ = fmt.Fprintf(os.Stdout, "\n") } diff --git a/zrokdir/client.go b/zrokdir/client.go index 2725d3c3..ede9e5e3 100644 --- a/zrokdir/client.go +++ b/zrokdir/client.go @@ -13,7 +13,7 @@ import ( ) func (zrd *ZrokDir) Client() (*rest_client_zrok.Zrok, error) { - apiEndpoint := zrd.ApiEndpoint() + apiEndpoint, _ := zrd.ApiEndpoint() apiUrl, err := url.Parse(apiEndpoint) if err != nil { return nil, errors.Wrapf(err, "error parsing api endpoint '%v'", zrd) @@ -34,21 +34,25 @@ func (zrd *ZrokDir) Client() (*rest_client_zrok.Zrok, error) { return zrok, nil } -func (zrd *ZrokDir) ApiEndpoint() string { - apiEndpoint := "https://api.zrok.io" +func (zrd *ZrokDir) ApiEndpoint() (apiEndpoint string, from string) { + apiEndpoint = "https://api.zrok.io" + from = "binary" if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" { apiEndpoint = zrd.Cfg.ApiEndpoint + from = "config" } env := os.Getenv("ZROK_API_ENDPOINT") if env != "" { apiEndpoint = env + from = "ZROK_API_ENDPOINT" } if zrd.Env != nil && zrd.Env.ApiEndpoint != "" { apiEndpoint = zrd.Env.ApiEndpoint + from = "env" } - return apiEndpoint + return apiEndpoint, from }