2020-04-23 01:47:27 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2022-02-28 03:15:01 +00:00
|
|
|
"fmt"
|
2020-04-23 01:47:27 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-12-22 00:21:29 +00:00
|
|
|
func newValidateConfigCmd(ctx *CmdCtx) (cmd *cobra.Command) {
|
2021-08-03 09:55:21 +00:00
|
|
|
cmd = &cobra.Command{
|
2022-06-14 12:40:00 +00:00
|
|
|
Use: "validate-config",
|
|
|
|
Short: cmdAutheliaValidateConfigShort,
|
|
|
|
Long: cmdAutheliaValidateConfigLong,
|
|
|
|
Example: cmdAutheliaValidateConfigExample,
|
|
|
|
Args: cobra.NoArgs,
|
2022-12-22 00:21:29 +00:00
|
|
|
PreRunE: ctx.ChainRunE(
|
|
|
|
ctx.ConfigLoadRunE,
|
|
|
|
ctx.ConfigValidateKeysRunE,
|
|
|
|
ctx.ConfigValidateRunE,
|
|
|
|
),
|
|
|
|
RunE: ctx.ValidateConfigRunE,
|
2022-09-01 02:24:47 +00:00
|
|
|
|
|
|
|
DisableAutoGenTag: true,
|
2021-08-03 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2022-12-22 00:21:29 +00:00
|
|
|
// ValidateConfigRunE is the RunE for the authelia validate-config command.
|
|
|
|
func (ctx *CmdCtx) ValidateConfigRunE(_ *cobra.Command, _ []string) (err error) {
|
2022-02-28 03:15:01 +00:00
|
|
|
switch {
|
2022-12-22 00:21:29 +00:00
|
|
|
case ctx.cconfig.validator.HasErrors():
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Println("Configuration parsed and loaded with errors:")
|
|
|
|
fmt.Println("")
|
2021-08-03 09:55:21 +00:00
|
|
|
|
2022-12-22 00:21:29 +00:00
|
|
|
for _, err = range ctx.cconfig.validator.Errors() {
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Printf("\t - %v\n", err)
|
|
|
|
}
|
2021-08-03 09:55:21 +00:00
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Println("")
|
2021-08-03 09:55:21 +00:00
|
|
|
|
2022-12-22 00:21:29 +00:00
|
|
|
if !ctx.cconfig.validator.HasWarnings() {
|
2022-02-28 03:15:01 +00:00
|
|
|
break
|
2020-04-23 01:47:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
fallthrough
|
2022-12-22 00:21:29 +00:00
|
|
|
case ctx.cconfig.validator.HasWarnings():
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Println("Configuration parsed and loaded with warnings:")
|
|
|
|
fmt.Println("")
|
2021-08-03 09:55:21 +00:00
|
|
|
|
2022-12-22 00:21:29 +00:00
|
|
|
for _, err = range ctx.cconfig.validator.Warnings() {
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Printf("\t - %v\n", err)
|
2020-04-23 01:47:27 +00:00
|
|
|
}
|
2021-08-03 09:55:21 +00:00
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
fmt.Println("")
|
|
|
|
default:
|
|
|
|
fmt.Println("Configuration parsed and loaded successfully without errors.")
|
|
|
|
fmt.Println("")
|
2021-08-03 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
return nil
|
2020-04-23 01:47:27 +00:00
|
|
|
}
|