From 4637d25c3262cfc680622f8f9939e87143f9752f Mon Sep 17 00:00:00 2001 From: Chen Anidam Date: Sat, 9 Apr 2022 00:20:11 +0300 Subject: [PATCH] Read password of generic git bootstrap command from env or stdin Signed-off-by: Chen Anidam --- cmd/flux/bootstrap_git.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 3104ea97b8..3966994347 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -50,9 +50,12 @@ command will perform an upgrade if needed.`, Example: ` # Run bootstrap for a Git repository and authenticate with your SSH agent flux bootstrap git --url=ssh://git@example.com/repository.git - # Run bootstrap for a Git repository and authenticate using a password + # Run bootstrap for a Git repository and authenticate using a password CLI flux bootstrap git --url=https://example.com/repository.git --password= + # Run bootstrap for a Git repository and authenticate using a password from environment variable + GIT_PASSWORD= flux bootstrap git --url=https://example.com/repository.git + # Run bootstrap for a Git repository with a passwordless private key flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file= @@ -71,6 +74,10 @@ type gitFlags struct { silent bool } +const ( + gitPasswordEnvVar = "GIT_PASSWORD" +) + var gitArgs gitFlags func init() { @@ -85,6 +92,18 @@ func init() { } func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { + if gitArgs.password == "" { + var err error + gitPassword := os.Getenv(gitPasswordEnvVar) + if gitPassword == "" { + gitPassword, err = readPasswordFromStdin("Please enter your Git repository password: ") + if err != nil { + return fmt.Errorf("could not read token: %w", err) + } + } + gitArgs.password = gitPassword + } + if err := bootstrapValidate(); err != nil { return err }