'zrok admin grants' CLI (#744)

This commit is contained in:
Michael Quigley 2024-09-05 10:55:21 -04:00
parent d2ee09bd44
commit a37009249a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 51 additions and 2 deletions

View File

@ -27,9 +27,7 @@ func newAdminGenerateCommand() *adminGenerateCommand {
} }
command := &adminGenerateCommand{cmd: cmd} command := &adminGenerateCommand{cmd: cmd}
cmd.Run = command.run cmd.Run = command.run
cmd.Flags().IntVarP(&command.amount, "count", "n", 5, "Number of tokens to generate") cmd.Flags().IntVarP(&command.amount, "count", "n", 5, "Number of tokens to generate")
return command return command
} }

51
cmd/zrok/adminGrants.go Normal file
View File

@ -0,0 +1,51 @@
package main
import (
"fmt"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/rest_client_zrok/admin"
"github.com/spf13/cobra"
)
func init() {
adminCmd.AddCommand(newAdminGrantsCommand().cmd)
}
type adminGrantsCommand struct {
cmd *cobra.Command
email string
}
func newAdminGrantsCommand() *adminGrantsCommand {
cmd := &cobra.Command{
Use: "grants <email>",
Short: "Synchronize ziti objects with account grants",
Args: cobra.ExactArgs(1),
}
command := &adminGrantsCommand{cmd: cmd}
cmd.Run = command.run
cmd.Flags().StringVarP(&command.email, "email", "e", "", "email address")
return command
}
func (command *adminGrantsCommand) run(_ *cobra.Command, args []string) {
env, err := environment.LoadRoot()
if err != nil {
panic(err)
}
zrok, err := env.Client()
if err != nil {
panic(err)
}
req := admin.NewGrantsParams()
req.Body.Email = args[0]
_, err = zrok.Admin.Grants(req, mustGetAdminAuth())
if err != nil {
panic(err)
}
fmt.Println("success.")
}