Skip to content

Commit

Permalink
work around github.com/tmc/keyring compile error for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Apr 24, 2017
1 parent 9475b4b commit 85298e9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
13 changes: 13 additions & 0 deletions keyring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !windows

package jira

import "github.com/tmc/keyring"

func keyringGet(user string) (string, error) {
return keyring.Get("go-jira", user)
}

func keyringSet(user, passwd string) error {
return keyring.Set("go-jira", user, passwd)
}
11 changes: 11 additions & 0 deletions keyring_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package jira

import "fmt"

func keyringGet(user string) (string, error) {
return "", fmt.Errorf("Keyring is not supported for Windows, see: https://github.com/tmc/keyring")
}

func keyringSet(user, passwd string) error {
return fmt.Errorf("Keyring is not supported for Windows, see: https://github.com/tmc/keyring")
}
9 changes: 6 additions & 3 deletions password.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (
"strings"

"github.com/howeyc/gopass"
"github.com/tmc/keyring"
)

func (c *Cli) GetPass(user string) string {
passwd := ""
if source, ok := c.opts["password-source"].(string); ok {
if source == "keyring" {
passwd, _ = keyring.Get("go-jira", user)
var err error
passwd, err = keyringGet(user)
if err != nil {
panic(err)
}
} else if source == "pass" {
if bin, err := exec.LookPath("pass"); err == nil {
buf := bytes.NewBufferString("")
Expand Down Expand Up @@ -48,7 +51,7 @@ func (c *Cli) SetPass(user, passwd string) error {
log.Debugf("password-source: %s", source)
if source == "keyring" {
// save password in keychain so that it can be used for subsequent http requests
err := keyring.Set("go-jira", user, passwd)
err := keyringSet(user, passwd)
if err != nil {
log.Errorf("Failed to set password in keyring: %s", err)
return err
Expand Down

0 comments on commit 85298e9

Please sign in to comment.