allow override of admin password wit ocis init

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2022-04-29 14:15:48 +02:00
parent 59c96413d9
commit c47e43318a
2 changed files with 18 additions and 6 deletions

View File

@@ -24,17 +24,25 @@ func InitCommand(cfg *config.Config) *cli.Command {
Name: "insecure",
EnvVars: []string{"OCIS_INSECURE"},
Value: "ask",
Usage: "Allow insecure oCIS config",
},
&cli.BoolFlag{
Name: "force-overwrite",
Aliases: []string{"f"},
EnvVars: []string{"OCIS_FORCE_CONFIG_OVERWRITE"},
Value: false,
Usage: "Force overwrite existing config file",
},
&cli.StringFlag{
Name: "config-path",
Value: defaults.BaseConfigPath(),
Usage: "config path for the ocis runtime",
Usage: "Config path for the ocis runtime",
},
&cli.StringFlag{
Name: "admin-password",
Aliases: []string{"ap"},
EnvVars: []string{"ADMIN_PASSWORD"},
Usage: "Set admin password instead of using a random gnerated one",
},
},
Action: func(c *cli.Context) error {
@@ -48,7 +56,7 @@ func InitCommand(cfg *config.Config) *cli.Command {
} else if insecureFlag == strings.ToLower("true") || insecureFlag == strings.ToLower("yes") || insecureFlag == strings.ToLower("y") {
insecure = true
}
err := ocisinit.CreateConfig(insecure, c.Bool("force-overwrite"), c.String("config-path"))
err := ocisinit.CreateConfig(insecure, c.Bool("force-overwrite"), c.String("config-path"), c.String("admin-password"))
if err != nil {
log.Fatalf("Could not create config: %s", err)
}

View File

@@ -142,7 +142,7 @@ func backupOcisConfigFile(configPath string) (string, error) {
return targetBackupConfig, nil
}
func CreateConfig(insecure, forceOverwrite bool, configPath string) error {
func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword string) error {
targetBackupConfig := ""
err := checkConfigPath(configPath)
@@ -167,10 +167,14 @@ func CreateConfig(insecure, forceOverwrite bool, configPath string) error {
if err != nil {
return fmt.Errorf("could not generate random password for idp: %s", err)
}
ocisAdminServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("could not generate random password for ocis admin: %s", err)
ocisAdminServicePassword := adminPassword
if ocisAdminServicePassword == "" {
ocisAdminServicePassword, err = generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("could not generate random password for ocis admin: %s", err)
}
}
revaServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("could not generate random password for reva: %s", err)