Skip to content

Commit

Permalink
use password-source-path to allow overriding binary and/or path to …
Browse files Browse the repository at this point in the history
…binary
  • Loading branch information
coryb committed Dec 2, 2019
1 parent e26fbfc commit d6173ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,18 @@ When `password-source` is set to `stdin`, the `jira login` command will read fro
$ ./password-generator | jira login --endpoint=https://my.jira.endpoint.com --user=USERNAME
```

#### Switch binary used for password source
For `gopass` and `pass` it is possible to switch the binary used for retrieval of the password. This can be accomplised
by setting the `password-source-binary` option in the configuration file.
#### Switch path used for password source
For `gopass` and `pass` it is possible to specify the full path for the `password-source` tool used for retrieval of the password. This can be accomplised
by setting the `password-source-path` option in the configuration file.

E.g.
```yaml
password-source: gopass
password-name: jira.example.com/myuser
password-source-binary: my-special-gopass
password-source-path: /path/to/my-special-gopass
```

This will cause go-jira to use the `gopass` style cli interaction with the `my-special-gopass` binary.

If you ommit the `password-source-binary` option, either `gopass` (for `gopass`) or `pass` (for `pass`)
If you ommit the `password-source-path` option, either `gopass` (for `gopass`) or `pass` (for `pass`)
will be used.
3 changes: 2 additions & 1 deletion jiracli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ type GlobalOptions struct {
// location using the `pass` tool, if missing prompt the user and store in the PasswordDirectory
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`

PasswordSourceBinary figtree.StringOption `yaml:"password-source-binary,omitempty" json:"password-source-binary,omitempty"`
// PasswordSourcePath can be used to specify the path to the PasswordSource binary to use.
PasswordSourcePath figtree.StringOption `yaml:"password-source-path,omitempty" json:"password-source-path,omitempty"`

// PasswordDirectory is only used for the "pass" PasswordSource. It is the location for the encrypted password
// files used by `pass`. Effectively this overrides the "PASSWORD_STORE_DIR" environment variable
Expand Down
28 changes: 11 additions & 17 deletions jiracli/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ func (o *GlobalOptions) keyName() string {
return user
}

func (o *GlobalOptions) GetPasswordBinary() string {
binary := o.PasswordSourceBinary.Value

if binary == "" {
if o.PasswordSource.Value == "gopass" {
return "gopass"
} else if o.PasswordSource.Value == "pass" {
return "pass"
}
}

return binary
func (o *GlobalOptions) GetPasswordPath() string {
// if no password source path then just default
// to the password source name
if o.PasswordSourcePath.Value == "" {
return o.PasswordSource.Value
}
return o.PasswordSourcePath.Value
}

func (o *GlobalOptions) GetPass() string {
Expand All @@ -66,9 +61,8 @@ func (o *GlobalOptions) GetPass() string {
if err != nil {
panic(err)
}
} else if o.PasswordSource.Value == "gopass" && o.GetPasswordBinary() != "" {
binary := o.GetPasswordBinary()

} else if o.PasswordSource.Value == "gopass" {
binary := o.GetPasswordPath()
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
log.Debugf("using password-directory: %s", o.PasswordDirectory)
Expand All @@ -92,8 +86,8 @@ func (o *GlobalOptions) GetPass() string {
} else {
log.Warning("Gopass binary was not found! Fallback to default password behaviour!")
}
} else if o.PasswordSource.Value == "pass" && o.GetPasswordBinary() != "" {
binary := o.GetPasswordBinary()
} else if o.PasswordSource.Value == "pass" {
binary := o.GetPasswordPath()
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
log.Debugf("using password-directory: %s", o.PasswordDirectory)
Expand Down

0 comments on commit d6173ce

Please sign in to comment.