zrok status now shows origination for api endpoint (#136)

This commit is contained in:
Michael Quigley 2023-01-09 14:33:17 -05:00
parent 434943c964
commit 5bd11e46a5
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 22 additions and 10 deletions

View File

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

View File

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

View File

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