Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add support for password via environment variable #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/client/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const rsaKeySize = 2048
const maxPasswordLength = 512

func getUserCreds(userName string) (password []byte, err error) {
// First check for environment variable
if envPass := os.Getenv("KEYMASTER_PASSWORD"); envPass != "" {
return []byte(envPass), nil
}

fmt.Printf("Password for %s: ", userName)

if term.IsTerminal(int(os.Stdin.Fd())) {
Expand Down
16 changes: 16 additions & 0 deletions lib/client/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ func TestGetUserCreds(t *testing.T) {
}
}

func TestGetUserCredsFromEnv(t *testing.T) {
// Set environment variable
const testPassword = "test-password-123"
os.Setenv("KEYMASTER_PASSWORD", testPassword)
defer os.Unsetenv("KEYMASTER_PASSWORD") // Clean up

password, err := getUserCreds("username")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if string(password) != testPassword {
t.Errorf("got password %q, want %q", string(password), testPassword)
}
}

// ------------WARN-------- Next name copied from https://github.com/howeyc/gopass/blob/master/pass_test.go for using
//
// gopass checks
Expand Down
Loading