mirror of
https://github.com/openziti/zrok.git
synced 2024-12-23 07:09:12 +01:00
sdk.Overview implementation; migrated 'zrok overview' to dogfood the sdk implementation (#407)
This commit is contained in:
parent
d93b40fc1e
commit
8dbebed34a
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
35
sdk/overview.go
Normal file
35
sdk/overview.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user