Skip to content

Commit

Permalink
Add flag for random password
Browse files Browse the repository at this point in the history
  • Loading branch information
hexmode committed Sep 4, 2022
1 parent 53fc300 commit 2b324b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions internal/canasta/canasta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type CanastaVariables struct {
WikiName string
DomainName string
AdminPassword string
RandomPassword bool
AdminName string
}

Expand Down
9 changes: 6 additions & 3 deletions internal/mediawiki/mediawiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -72,14 +72,17 @@ 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)
}
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)
Expand Down

0 comments on commit 2b324b0

Please sign in to comment.