diff --git a/CHANGELOG.md b/CHANGELOG.md index e49304c1..6a55502d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # v0.4.8 +FEATURE: The `sdk` package now includes a `sdk.Overview` function, which returns a complete description of the account attached to the enabled environment. Useful for inventorying the deployed shares and environments (https://github.com/openziti/zrok/issues/407) + CHANGE: The title color of the header was changed from white to flourescent green, to better match the overall branding CHANGE: Tweaks to build and release process for logging and deprecations. Pin golang version at 1.21.3+ and node version at 18.x across all platforms diff --git a/cmd/zrok/overview.go b/cmd/zrok/overview.go index 329e4a29..31fe69e3 100644 --- a/cmd/zrok/overview.go +++ b/cmd/zrok/overview.go @@ -3,10 +3,9 @@ package main import ( "fmt" "github.com/openziti/zrok/environment" + "github.com/openziti/zrok/sdk" "github.com/openziti/zrok/tui" "github.com/spf13/cobra" - "io" - "net/http" ) func init() { @@ -41,32 +40,13 @@ func (cmd *overviewCommand) run(_ *cobra.Command, _ []string) { tui.Error("unable to load environment; did you 'zrok enable'?", nil) } - client := &http.Client{} - apiEndpoint, _ := root.ApiEndpoint() - req, err := http.NewRequest("GET", fmt.Sprintf("%v/api/v1/overview", apiEndpoint), nil) + json, err := sdk.Overview(root) if err != nil { if !panicInstead { - tui.Error("error accessing overview", err) - } - panic(err) - } - req.Header.Add("X-TOKEN", root.Environment().Token) - resp, err := client.Do(req) - if err != nil { - if !panicInstead { - tui.Error("error requesting overview", err) + tui.Error("error loading zrokdir", err) } panic(err) } - json, err := io.ReadAll(resp.Body) - if err != nil { - if !panicInstead { - tui.Error("error reading body", err) - } - panic(err) - } - _ = resp.Body.Close() - - fmt.Println(string(json)) + fmt.Println(json) } diff --git a/sdk/overview.go b/sdk/overview.go new file mode 100644 index 00000000..cff5d5d3 --- /dev/null +++ b/sdk/overview.go @@ -0,0 +1,35 @@ +package sdk + +import ( + "errors" + "fmt" + "github.com/openziti/zrok/environment/env_core" + "io" + "net/http" +) + +func Overview(root env_core.Root) (string, error) { + if !root.IsEnabled() { + return "", errors.New("environment is not enabled; enable with 'zrok enable' first!") + } + + client := &http.Client{} + apiEndpoint, _ := root.ApiEndpoint() + req, err := http.NewRequest("GET", fmt.Sprintf("%v/api/v1/overview", apiEndpoint), nil) + if err != nil { + return "", err + } + req.Header.Add("X-TOKEN", root.Environment().Token) + resp, err := client.Do(req) + if err != nil { + return "", err + } + + json, err := io.ReadAll(resp.Body) + if err != nil { + return "", err + } + _ = resp.Body.Close() + + return string(json), nil +}