From 0d11749db16ff77ff79df70d4b95be9a74b245c2 Mon Sep 17 00:00:00 2001 From: az Date: Tue, 8 Nov 2022 18:49:56 +0100 Subject: [PATCH] trim newline suffix of gopass secret --- .../domaindrivenarchitecture/provs/framework/core/Prov.kt | 5 +++-- .../ubuntu/secret/secretSources/GopassSecretSource.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt index 6420ccb..87a88c8 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -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 diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/secretSources/GopassSecretSource.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/secretSources/GopassSecretSource.kt index 5a6cb76..65ae378 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/secretSources/GopassSecretSource.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/secretSources/GopassSecretSource.kt @@ -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) } } \ No newline at end of file