mirror of
https://github.com/openziti/zrok.git
synced 2025-02-22 21:21:07 +01:00
zrok config <get|set> (#136)
This commit is contained in:
parent
5bd11e46a5
commit
38132f2e7c
@ -30,7 +30,7 @@ func newAdminListFrontendsCommand() *adminListFrontendsCommand {
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *adminListFrontendsCommand) run(_ *cobra.Command, args []string) {
|
||||
func (cmd *adminListFrontendsCommand) run(_ *cobra.Command, _ []string) {
|
||||
zrd, err := zrokdir.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
46
cmd/zrok/configGet.go
Normal file
46
cmd/zrok/configGet.go
Normal file
@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
configCmd.AddCommand(newConfigGetCommand().cmd)
|
||||
}
|
||||
|
||||
type configGetCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newConfigGetCommand() *configGetCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "get <configName>",
|
||||
Short: "Get a value from the environment config",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &configGetCommand{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *configGetCommand) run(_ *cobra.Command, args []string) {
|
||||
configName := args[0]
|
||||
|
||||
zrd, err := zrokdir.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
switch configName {
|
||||
case "apiEndpoint":
|
||||
if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" {
|
||||
fmt.Printf("apiEndpoint = %v\n", zrd.Cfg.ApiEndpoint)
|
||||
} else {
|
||||
fmt.Println("apiEndpoint = <unset>")
|
||||
}
|
||||
default:
|
||||
fmt.Printf("unknown config name '%v'\n", configName)
|
||||
}
|
||||
}
|
58
cmd/zrok/configSet.go
Normal file
58
cmd/zrok/configSet.go
Normal file
@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
configCmd.AddCommand(newConfigSetCommand().cmd)
|
||||
}
|
||||
|
||||
type configSetCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newConfigSetCommand() *configSetCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "set <configName> <value>",
|
||||
Short: "Set a value into the environment config",
|
||||
Args: cobra.ExactArgs(2),
|
||||
}
|
||||
command := &configSetCommand{cmd: cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
|
||||
configName := args[0]
|
||||
value := args[1]
|
||||
|
||||
zrd, err := zrokdir.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
modified := false
|
||||
switch configName {
|
||||
case "apiEndpoint":
|
||||
if zrd.Cfg == nil {
|
||||
zrd.Cfg = &zrokdir.Config{}
|
||||
}
|
||||
zrd.Cfg.ApiEndpoint = value
|
||||
modified = true
|
||||
|
||||
default:
|
||||
fmt.Printf("unknown config name '%v'\n", configName)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if modified {
|
||||
if err := zrd.Save(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("zrok configuration updated")
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ func init() {
|
||||
adminCmd.AddCommand(adminListCmd)
|
||||
adminCmd.AddCommand(adminUpdateCmd)
|
||||
rootCmd.AddCommand(adminCmd)
|
||||
rootCmd.AddCommand(configCmd)
|
||||
rootCmd.AddCommand(shareCmd)
|
||||
rootCmd.AddCommand(testCmd)
|
||||
}
|
||||
@ -65,6 +66,11 @@ var adminUpdateCmd = &cobra.Command{
|
||||
Short: "Update global resources",
|
||||
}
|
||||
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Configure your zrok environment",
|
||||
}
|
||||
|
||||
var shareCmd = &cobra.Command{
|
||||
Use: "share",
|
||||
Short: "Create backend access for shares",
|
||||
|
@ -40,9 +40,9 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.SetStyle(table.StyleColoredDark)
|
||||
t.AppendHeader(table.Row{"Property", "Value", "Source"})
|
||||
t.AppendHeader(table.Row{"Config", "Value", "Source"})
|
||||
apiEndpoint, from := zrd.ApiEndpoint()
|
||||
t.AppendRow(table.Row{"API Endpoint", apiEndpoint, from})
|
||||
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, from})
|
||||
t.Render()
|
||||
_, _ = fmt.Fprintf(os.Stderr, "\n")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user