Skip to content

Commit

Permalink
Fix password prompt file keyring issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bn0ir authored and jacobbednarz committed Sep 12, 2022
1 parent 91313cf commit 7536246
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/99designs/keyring"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

var (
Expand All @@ -19,6 +20,7 @@ var (

var keyringDefaults = keyring.Config{
FileDir: fmt.Sprintf("~/.%s/keys/", projectName),
FilePasswordFunc: fileKeyringPassphrasePrompt,
ServiceName: projectName,
KeychainName: projectName,
LibSecretCollectionName: projectNameWithoutHyphen,
Expand All @@ -44,6 +46,21 @@ var rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {},
}

// Get passphrase prompt (copied from https://github.com/99designs/aws-vault)
func fileKeyringPassphrasePrompt(prompt string) (string, error) {
if password, ok := os.LookupEnv("CF_VAULT_FILE_PASSPHRASE"); ok {
return password, nil
}

fmt.Fprintf(os.Stderr, "%s: ", prompt)
b, err := terminal.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
}
fmt.Println()
return string(b), nil
}

func init() {
log.SetLevel(log.WarnLevel)

Expand Down

0 comments on commit 7536246

Please sign in to comment.