basic controller configuration validation (#238)

This commit is contained in:
Michael Quigley 2023-02-16 13:51:47 -05:00
parent 14e0e39b85
commit ad09adc941
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 40 additions and 1 deletions

View File

@ -7,8 +7,11 @@ import (
"github.com/spf13/cobra"
)
var controllerCmd *controllerCommand
func init() {
rootCmd.AddCommand(newControllerCommand().cmd)
controllerCmd = newControllerCommand()
rootCmd.AddCommand(controllerCmd.cmd)
}
type controllerCommand struct {

View File

@ -0,0 +1,36 @@
package main
import (
"github.com/michaelquigley/cf"
"github.com/openziti/zrok/controller"
"github.com/openziti/zrok/tui"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
controllerCmd.cmd.AddCommand(newControllerValidateCommand().cmd)
}
type controllerValidateCommand struct {
cmd *cobra.Command
}
func newControllerValidateCommand() *controllerValidateCommand {
cmd := &cobra.Command{
Use: "validate <configPath>",
Short: "Validate a zrok controlle configuration document",
Args: cobra.ExactArgs(1),
}
command := &controllerValidateCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *controllerValidateCommand) run(_ *cobra.Command, args []string) {
cfg, err := controller.LoadConfig(args[0])
if err != nil {
tui.Error("controller config validation failed", err)
}
logrus.Infof(cf.Dump(cfg, cf.DefaultOptions()))
}