trim newline suffix of gopass secret

This commit is contained in:
az 2022-11-08 18:49:56 +01:00
parent fe83442708
commit 0d11749db1
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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)
}
}