InitCommand is the entrypoint for the init command
(_ *config.Config)
| 18 | |
| 19 | // InitCommand is the entrypoint for the init command |
| 20 | func InitCommand(_ *config.Config) *cobra.Command { |
| 21 | initCmd := &cobra.Command{ |
| 22 | Use: "init", |
| 23 | Short: "initialise an OpenCloud config", |
| 24 | GroupID: CommandGroupServer, |
| 25 | RunE: func(cmd *cobra.Command, args []string) error { |
| 26 | insecureFlag := viper.GetString("insecure") |
| 27 | insecure := false |
| 28 | if insecureFlag == "ask" { |
| 29 | answer := strings.ToLower(stringPrompt("Do you want to configure OpenCloud with certificate checking disabled?\n This is not recommended for public instances! [yes | no = default]")) |
| 30 | if answer == "yes" || answer == "y" { |
| 31 | insecure = true |
| 32 | } |
| 33 | } else if insecureFlag == strings.ToLower("true") || insecureFlag == strings.ToLower("yes") || insecureFlag == strings.ToLower("y") { |
| 34 | insecure = true |
| 35 | } |
| 36 | forceOverwriteFlag := viper.GetBool("force-overwrite") |
| 37 | diffFlag, _ := cmd.Flags().GetBool("diff") |
| 38 | quietFlag, _ := cmd.Flags().GetBool("quiet") |
| 39 | configPathFlag := viper.GetString("config-path") |
| 40 | adminPasswordFlag := viper.GetString("admin-password") |
| 41 | err := ocinit.CreateConfig(insecure, forceOverwriteFlag, diffFlag, configPathFlag, adminPasswordFlag, quietFlag) |
| 42 | if err != nil { |
| 43 | log.Fatalf("Could not create config: %s", err) |
| 44 | } |
| 45 | return nil |
| 46 | }, |
| 47 | } |
| 48 | initCmd.Flags().String("insecure", "ask", "Allow insecure OpenCloud config") |
| 49 | _ = viper.BindEnv("insecure", "OC_INSECURE") |
| 50 | _ = viper.BindPFlag("insecure", initCmd.Flags().Lookup("insecure")) |
| 51 | |
| 52 | initCmd.Flags().BoolP("diff", "d", false, "Show the difference between the current config and the new one") |
| 53 | initCmd.Flags().BoolP("quiet", "q", false, "Work quietly. Surpresses and non-error message") |
| 54 | |
| 55 | initCmd.Flags().BoolP("force-overwrite", "f", false, "Force overwrite existing config file") |
| 56 | _ = viper.BindEnv("force-overwrite", "OC_FORCE_CONFIG_OVERWRITE") |
| 57 | _ = viper.BindPFlag("force-overwrite", initCmd.Flags().Lookup("force-overwrite")) |
| 58 | |
| 59 | initCmd.Flags().String("config-path", defaults.BaseConfigPath(), "Config path for the OpenCloud runtime") |
| 60 | _ = viper.BindEnv("config-path", "OC_CONFIG_DIR") |
| 61 | _ = viper.BindEnv("config-path", "OC_BASE_DATA_PATH") |
| 62 | _ = viper.BindPFlag("config-path", initCmd.Flags().Lookup("config-path")) |
| 63 | |
| 64 | initCmd.Flags().String("admin-password", "", "Set admin password instead of using a random generated one") |
| 65 | _ = viper.BindEnv("admin-password", "ADMIN_PASSWORD") |
| 66 | _ = viper.BindEnv("admin-password", "IDM_ADMIN_PASSWORD") |
| 67 | _ = viper.BindPFlag("admin-password", initCmd.Flags().Lookup("admin-password")) |
| 68 | return initCmd |
| 69 | } |
| 70 | |
| 71 | func init() { |
| 72 | register.AddCommand(InitCommand) |
nothing calls this directly
no test coverage detected