Skip to content

Commit

Permalink
Read password of generic git bootstrap command from env or stdin
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Anidam <canidam@gmail.com>
  • Loading branch information
canidam committed Apr 8, 2022
1 parent d012f0f commit 4637d25
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/flux/bootstrap_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<password>
# Run bootstrap for a Git repository and authenticate using a password from environment variable
GIT_PASSWORD=<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=<path/to/private.key>
Expand All @@ -71,6 +74,10 @@ type gitFlags struct {
silent bool
}

const (
gitPasswordEnvVar = "GIT_PASSWORD"
)

var gitArgs gitFlags

func init() {
Expand All @@ -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
}
Expand Down

0 comments on commit 4637d25

Please sign in to comment.