use password-source-path to allow overriding binary and/or path to binary

This commit is contained in:
Cory Bennett
2019-12-01 20:27:00 -08:00
parent e26fbfcb14
commit d6173ce77d
3 changed files with 18 additions and 23 deletions
+2 -1
View File
@@ -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
+11 -17
View File
@@ -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 {
@@ -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)
@@ -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)