trim newline suffix of gopass secret
This commit is contained in:
parent
fe83442708
commit
0d11749db1
2 changed files with 4 additions and 3 deletions
|
@ -195,11 +195,12 @@ open class Prov protected constructor(
|
|||
* Retrieve a secret by executing the given command.
|
||||
* Returns the result of the command as secret.
|
||||
*/
|
||||
fun getSecret(command: String): Secret? {
|
||||
fun getSecret(command: String, removeNewlineSuffix: Boolean = false): Secret? {
|
||||
val result = cmdNoLog(command)
|
||||
return if (result.success && result.out != null) {
|
||||
addResultToEval(ProvResult(true, getCallingMethodName()))
|
||||
Secret(result.out)
|
||||
val plainSecret = if (removeNewlineSuffix && result.out.takeLast(1) == "\n") result.out.dropLast(1) else result.out
|
||||
Secret(plainSecret)
|
||||
} else {
|
||||
addResultToEval(ProvResult(false, getCallingMethodName(), err = result.err, exception = result.exception))
|
||||
null
|
||||
|
|
|
@ -14,6 +14,6 @@ class GopassSecretSource(path: String) : SecretSource(path) {
|
|||
}
|
||||
override fun secretNullable(): Secret? {
|
||||
val p = Prov.newInstance(name = "GopassSecretSource for $input")
|
||||
return p.getSecret("gopass show -f " + input)
|
||||
return p.getSecret("gopass show -f $input", true)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue