diff options
author | Antoine A <> | 2024-02-20 16:55:15 +0100 |
---|---|---|
committer | Antoine A <> | 2024-02-20 16:55:15 +0100 |
commit | f76e262a38c99bbb2834eb9e6d95d6683cd2bf7a (patch) | |
tree | 6025b9660ae67855f677a5efbfcaee2016133bc7 | |
parent | d87355ed5f7876dee4534ca9a7e8af3cb429bc2f (diff) | |
download | libeufin-f76e262a38c99bbb2834eb9e6d95d6683cd2bf7a.tar.gz libeufin-f76e262a38c99bbb2834eb9e6d95d6683cd2bf7a.tar.bz2 libeufin-f76e262a38c99bbb2834eb9e6d95d6683cd2bf7a.zip |
Improve bank keys prompt and env config value format
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/Config.kt | 23 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt | 3 |
2 files changed, 17 insertions, 9 deletions
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt index 8bceb104..6400d5d6 100644 --- a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt +++ b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -97,13 +97,7 @@ fun TalerConfig.loadBankConfig(): BankConfig { val tanChannels = buildMap { for (channel in TanChannel.entries) { lookupPath("libeufin-bank", "tan_$channel")?.let { - val variables = lookupString("libeufin-bank", "tan_${channel}_env")?.let { env -> - env.split(' ').map { variable -> - variable.splitOnce("=") ?: - throw TalerConfigError.invalid("environment variables", "libeufin-bank", "tan_${channel}_env", "expected NAME=VALUE got '$variable'") - }.toMap() - } ?: mapOf() - put(channel, Pair(it, variables)) + put(channel, Pair(it, jsonMap("libeufin-bank", "tan_${channel}_env") ?: mapOf())) } } } @@ -171,9 +165,22 @@ private fun TalerConfig.loadCurrencySpecification(section: String): CurrencySpec num_fractional_input_digits = requireNumber(section, "fractional_input_digits"), num_fractional_normal_digits = requireNumber(section, "fractional_normal_digits"), num_fractional_trailing_zero_digits = requireNumber(section, "fractional_trailing_zero_digits"), - alt_unit_names = Json.decodeFromString(requireString(section, "alt_unit_names")) + alt_unit_names = requireJsonMap(section, "alt_unit_names") ) } + +private fun TalerConfig.jsonMap(section: String, option: String): Map<String, String>? { + val raw = lookupString(section, option) ?: return null + try { + return Json.decodeFromString(raw) + } catch (e: Exception) { + throw TalerConfigError.invalid("json key/value map", section, option, "'$raw' is malformed") + } +} + +private fun TalerConfig.requireJsonMap(section: String, option: String): Map<String, String> + = jsonMap(section, option) ?: throw TalerConfigError.missing("json key/value map", section, option) + private fun TalerConfig.amount(section: String, option: String, currency: String): TalerAmount? { val raw = lookupString(section, option) ?: return null val amount = try { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt index cbecaa81..df2f8f15 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt @@ -83,9 +83,10 @@ fun String.spaceEachTwo() = private fun askUserToAcceptKeys(bankKeys: BankPublicKeysFile): Boolean { val encHash = CryptoUtil.getEbicsPublicKeyHash(bankKeys.bank_encryption_public_key).toHexString() val authHash = CryptoUtil.getEbicsPublicKeyHash(bankKeys.bank_authentication_public_key).toHexString() - println("The bank has the following keys, type 'yes, accept' to accept them..\n") + println("The bank has the following keys:") println("Encryption key: ${encHash.spaceEachTwo()}") println("Authentication key: ${authHash.spaceEachTwo()}") + print("type 'yes, accept' to accept them: ") val userResponse: String? = readlnOrNull() return userResponse == "yes, accept" } |