From c47e43318a03700370b487ff0893b7aae87cb94e Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Fri, 29 Apr 2022 14:15:48 +0200 Subject: [PATCH] allow override of admin password wit ocis init Signed-off-by: Christian Richter --- ocis/pkg/command/init.go | 12 ++++++++++-- ocis/pkg/init/init.go | 12 ++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ocis/pkg/command/init.go b/ocis/pkg/command/init.go index 27f50b03a7..ecbcb27412 100644 --- a/ocis/pkg/command/init.go +++ b/ocis/pkg/command/init.go @@ -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) } diff --git a/ocis/pkg/init/init.go b/ocis/pkg/init/init.go index cd6c968f8e..e2d4b0f60c 100644 --- a/ocis/pkg/init/init.go +++ b/ocis/pkg/init/init.go @@ -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)