mirror of
https://github.com/openziti/zrok.git
synced 2025-03-15 07:58:15 +01:00
added 'zrok organization account-overview' ('zrok org overview') to allow admins to query overview data for any account in an org where they're an admin (#537)
This commit is contained in:
parent
65104e9e18
commit
5582ac0ea5
@ -28,6 +28,7 @@ func init() {
|
|||||||
rootCmd.AddCommand(adminCmd)
|
rootCmd.AddCommand(adminCmd)
|
||||||
rootCmd.AddCommand(configCmd)
|
rootCmd.AddCommand(configCmd)
|
||||||
rootCmd.AddCommand(modifyCmd)
|
rootCmd.AddCommand(modifyCmd)
|
||||||
|
rootCmd.AddCommand(organizationCmd)
|
||||||
rootCmd.AddCommand(shareCmd)
|
rootCmd.AddCommand(shareCmd)
|
||||||
rootCmd.AddCommand(testCmd)
|
rootCmd.AddCommand(testCmd)
|
||||||
rootCmd.AddCommand(gendoc.NewGendocCmd(rootCmd))
|
rootCmd.AddCommand(gendoc.NewGendocCmd(rootCmd))
|
||||||
@ -94,6 +95,12 @@ var modifyCmd = &cobra.Command{
|
|||||||
Short: "Modify resources",
|
Short: "Modify resources",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var organizationCmd = &cobra.Command{
|
||||||
|
Use: "organization",
|
||||||
|
Aliases: []string{"org"},
|
||||||
|
Short: "Organization admin commands",
|
||||||
|
}
|
||||||
|
|
||||||
var shareCmd = &cobra.Command{
|
var shareCmd = &cobra.Command{
|
||||||
Use: "share",
|
Use: "share",
|
||||||
Short: "Create backend access for shares",
|
Short: "Create backend access for shares",
|
||||||
|
79
cmd/zrok/orgAccountOverview.go
Normal file
79
cmd/zrok/orgAccountOverview.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/openziti/zrok/environment"
|
||||||
|
"github.com/openziti/zrok/tui"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
organizationCmd.AddCommand(newOrgAccountOverviewCommand().cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type orgAccountOverviewCommand struct {
|
||||||
|
cmd *cobra.Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOrgAccountOverviewCommand() *orgAccountOverviewCommand {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "account-overview <organizationToken> <accountEmail>",
|
||||||
|
Aliases: []string{"overview"},
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
}
|
||||||
|
command := &orgAccountOverviewCommand{cmd: cmd}
|
||||||
|
cmd.Run = command.run
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *orgAccountOverviewCommand) run(_ *cobra.Command, args []string) {
|
||||||
|
root, err := environment.LoadRoot()
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("error loading zrokdir", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !root.IsEnabled() {
|
||||||
|
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/%v/%v", apiEndpoint, args[0], args[1]), nil)
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("error creating request", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
req.Header.Add("X-TOKEN", root.Environment().Token)
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("error sending request", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("received error response", errors.New(resp.Status))
|
||||||
|
}
|
||||||
|
panic(errors.New(resp.Status))
|
||||||
|
}
|
||||||
|
|
||||||
|
json, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("error reading json", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
|
||||||
|
fmt.Println(string(json))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user