Skip to content

Commit

Permalink
Add gopass support
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Pichler committed Oct 3, 2019
1 parent 9676023 commit 3c0a62e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions jiracli/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func (o *GlobalOptions) keyName() string {
}
return fmt.Sprintf("GoJira/%s", user)
}

if o.PasswordSource.Value == "gopass" {
if o.PasswordName.Value != "" {
return o.PasswordName.Value
}
return fmt.Sprintf("GoJira/%s", user)
}
return user
}

Expand All @@ -43,6 +50,25 @@ func (o *GlobalOptions) GetPass() string {
if err != nil {
panic(err)
}
} else if o.PasswordSource.Value == "gopass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("gopass"); err == nil {
buf := bytes.NewBufferString("")
cmd := exec.Command(bin, "show", "-o", o.keyName())
cmd.Stdout = buf
cmd.Stderr = buf
if err := cmd.Run(); err == nil {
passwd = strings.TrimSpace(buf.String())
} else {
panic(err)
}
} else {
log.Warning("Gopass binary was not found! Fallback to default password behaviour!")
}
} else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
Expand Down Expand Up @@ -109,6 +135,34 @@ func (o *GlobalOptions) SetPass(passwd string) error {
log.Errorf("Failed to set password in keyring: %s", err)
return err
}
} else if o.PasswordSource.Value == "gopass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("gopass"); err == nil {
log.Debugf("using %s", bin)
passName := o.keyName()
if passwd != "" {
in := bytes.NewBufferString(fmt.Sprintf("%s\n", passwd))
out := bytes.NewBufferString("")
cmd := exec.Command(bin, "insert", "--force", passName)
cmd.Stdin = in
cmd.Stdout = out
cmd.Stderr = out
if err := cmd.Run(); err != nil {
return fmt.Errorf("Failed to insert password: %s", out.String())
}
} else {
// clear the `pass` entry on empty password
if err := exec.Command(bin, "rm", "--force", passName).Run(); err != nil {
return fmt.Errorf("Failed to clear password for %s", passName)
}
}
} else {
return fmt.Errorf("Gopass binary not found!")
}
} else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
Expand Down

0 comments on commit 3c0a62e

Please sign in to comment.