diff --git a/cmd/create/create.go b/cmd/create/create.go index d3a7cc2..7d7e40e 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -56,6 +56,7 @@ func NewCmdCreate() *cobra.Command { createCmd.Flags().StringVarP(&canastaInfo.DomainName, "domain-name", "n", "localhost", "Domain name") createCmd.Flags().StringVarP(&canastaInfo.AdminName, "admin", "a", "", "Initial wiki admin username") createCmd.Flags().StringVarP(&canastaInfo.AdminPassword, "password", "s", "", "Initial wiki admin password") + createCmd.Flags().BoolVarP(&canastaInfo.RandomPassword, "random", "r", false, "Use a random password for the wiki admin password") return createCmd } diff --git a/internal/canasta/canasta.go b/internal/canasta/canasta.go index 62ac312..7502459 100644 --- a/internal/canasta/canasta.go +++ b/internal/canasta/canasta.go @@ -18,6 +18,7 @@ type CanastaVariables struct { WikiName string DomainName string AdminPassword string + RandomPassword bool AdminName string } diff --git a/internal/mediawiki/mediawiki.go b/internal/mediawiki/mediawiki.go index b5ac9eb..ab21bb1 100644 --- a/internal/mediawiki/mediawiki.go +++ b/internal/mediawiki/mediawiki.go @@ -27,7 +27,7 @@ func PromptUser(canastaInfo canasta.CanastaVariables) (canasta.CanastaVariables, if err != nil { logging.Fatal(err) } - canastaInfo.AdminName, canastaInfo.AdminPassword, err = promptUserPassword(canastaInfo.AdminName, canastaInfo.AdminPassword, "admin name", "admin password") + canastaInfo.AdminName, canastaInfo.AdminPassword, err = promptUserPassword(canastaInfo.AdminName, canastaInfo.AdminPassword, "admin name", "admin password", canastaInfo.RandomPassword) if err != nil { logging.Fatal(err) } @@ -43,7 +43,7 @@ func Install(path, orchestrator string, canastaInfo canasta.CanastaVariables) (c command := "/wait-for-it.sh -t 60 db:3306" orchestrators.Exec(path, orchestrator, "web", command) - if canastaInfo.AdminPassword == "" { + if canastaInfo.RandomPassword == true { canastaInfo.AdminPassword, err = password.Generate(12, 2, 4, false, true) if err != nil { logging.Fatal(err) @@ -72,7 +72,7 @@ func prompt(value, prompt string) (string, error) { return input, nil } -func promptUserPassword(userValue, passwordValue, userPrompt, passwordPrompt string) (string, string, error) { +func promptUserPassword(userValue, passwordValue, userPrompt, passwordPrompt string, random bool) (string, string, error) { username, err := prompt(userValue, userPrompt) if err != nil { logging.Fatal(err) @@ -80,6 +80,9 @@ func promptUserPassword(userValue, passwordValue, userPrompt, passwordPrompt str if passwordValue != "" { logging.Fatal(err) } + if random { + return username, "", nil + } fmt.Printf("Enter the %s (Press Enter to autogenerate the password): \n", passwordPrompt) pass, err := term.ReadPassword(0) password := string(pass)