mirror of
https://github.com/openziti/zrok.git
synced 2024-11-21 15:43:22 +01:00
crud for defaultFrontend config (#663)
This commit is contained in:
parent
671d1aa944
commit
bb8bb0a377
@ -40,6 +40,12 @@ func (cmd *configGetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println("apiEndpoint = <unset>")
|
fmt.Println("apiEndpoint = <unset>")
|
||||||
}
|
}
|
||||||
|
case "defaultFrontend":
|
||||||
|
if env.Config() != nil && env.Config().DefaultFrontend != "" {
|
||||||
|
fmt.Printf("defaultFrontend = %v\n", env.Config().DefaultFrontend)
|
||||||
|
} else {
|
||||||
|
fmt.Println("defaultFrontend = <unset>")
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Printf("unknown config name '%v'\n", configName)
|
fmt.Printf("unknown config name '%v'\n", configName)
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,20 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
|
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "defaultFrontend":
|
||||||
|
if env.Config() == nil {
|
||||||
|
if err := env.SetConfig(&env_core.Config{DefaultFrontend: value}); err != nil {
|
||||||
|
tui.Error("unable to save config", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cfg := env.Config()
|
||||||
|
cfg.DefaultFrontend = value
|
||||||
|
if err := env.SetConfig(cfg); err != nil {
|
||||||
|
tui.Error("unable to save config", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("zrok configuration updated")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Printf("unknown config name '%v'\n", configName)
|
fmt.Printf("unknown config name '%v'\n", configName)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -48,8 +48,10 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
t.SetOutputMirror(os.Stdout)
|
t.SetOutputMirror(os.Stdout)
|
||||||
t.SetStyle(table.StyleColoredDark)
|
t.SetStyle(table.StyleColoredDark)
|
||||||
t.AppendHeader(table.Row{"Config", "Value", "Source"})
|
t.AppendHeader(table.Row{"Config", "Value", "Source"})
|
||||||
apiEndpoint, from := env.ApiEndpoint()
|
apiEndpoint, apiEndpointFrom := env.ApiEndpoint()
|
||||||
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, from})
|
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, apiEndpointFrom})
|
||||||
|
defaultFrontend, defaultFrontendFrom := env.DefaultFrontend()
|
||||||
|
t.AppendRow(table.Row{"defaultFrontend", defaultFrontend, defaultFrontendFrom})
|
||||||
t.Render()
|
t.Render()
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\n")
|
_, _ = fmt.Fprintf(os.Stderr, "\n")
|
||||||
|
|
||||||
|
@ -223,13 +223,14 @@ func loadConfig() (*env_core.Config, error) {
|
|||||||
return nil, errors.Wrapf(err, "error unmarshaling config file '%v'", cf)
|
return nil, errors.Wrapf(err, "error unmarshaling config file '%v'", cf)
|
||||||
}
|
}
|
||||||
out := &env_core.Config{
|
out := &env_core.Config{
|
||||||
ApiEndpoint: cfg.ApiEndpoint,
|
ApiEndpoint: cfg.ApiEndpoint,
|
||||||
|
DefaultFrontend: cfg.DefaultFrontend,
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveConfig(cfg *env_core.Config) error {
|
func saveConfig(cfg *env_core.Config) error {
|
||||||
in := &config{ApiEndpoint: cfg.ApiEndpoint}
|
in := &config{ApiEndpoint: cfg.ApiEndpoint, DefaultFrontend: cfg.DefaultFrontend}
|
||||||
data, err := json.MarshalIndent(in, "", " ")
|
data, err := json.MarshalIndent(in, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error marshaling config")
|
return errors.Wrap(err, "error marshaling config")
|
||||||
@ -323,7 +324,8 @@ type metadata struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
ApiEndpoint string `json:"api_endpoint"`
|
ApiEndpoint string `json:"api_endpoint"`
|
||||||
|
DefaultFrontend string `json:"default_frontend"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type environment struct {
|
type environment struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user