diff options
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index 8a51c766..b9582976 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -55,80 +55,6 @@ data class IbanAccountMetadata( val name: String ) -/** - * Contains the frequency of submit or fetch iterations. - */ -data class NexusFrequency( - /** - * Value in seconds of the FREQUENCY configuration - * value, found either under [nexus-fetch] or [nexus-submit] - */ - val inSeconds: Int, - /** - * Copy of the value found in the configuration. Used - * for logging. - */ - val fromConfig: String -) - -/** - * Converts human-readable duration in how many seconds. Supports - * the suffixes 's' (seconds), 'm' (minute), 'h' (hours). A valid - * duration is therefore, for example, Nm, where N is the number of - * minutes. - * - * @param trimmed duration - * @return how many seconds is the duration input, or null if the input - * is not valid. - */ -fun getFrequencyInSeconds(humanFormat: String): Int? { - val trimmed = humanFormat.trim() - if (trimmed.isEmpty()) { - logger.error("Input was empty") - return null - } - val howManySeconds: Int = when (val lastChar = trimmed.last()) { - 's' -> {1} - 'm' -> {60} - 'h' -> {60 * 60} - else -> { - logger.error("Duration symbol not one of s, m, h. '$lastChar' was found instead") - return null - } - } - val maybeNumber = trimmed.dropLast(1) - val howMany = try { - maybeNumber.trimEnd().toInt() - } catch (e: Exception) { - logger.error("Prefix was not a valid input: '$maybeNumber'") - return null - } - if (howMany == 0) return 0 - val ret = howMany * howManySeconds - if (howMany != ret / howManySeconds) { - logger.error("Result overflew") - return null - } - return ret -} - -/** - * Sanity-checks the frequency found in the configuration and - * either returns it or fails the process. Note: the returned - * value is also guaranteed to be non-negative. - * - * @param foundInConfig frequency value as found in the configuration. - * @return the duration in seconds of the value found in the configuration. - */ -fun checkFrequency(foundInConfig: String): Int { - val frequencySeconds = getFrequencyInSeconds(foundInConfig) - ?: throw Exception("Invalid frequency value in config section nexus-submit: $foundInConfig") - if (frequencySeconds < 0) { - throw Exception("Configuration error: cannot operate with a negative submit frequency ($foundInConfig)") - } - return frequencySeconds -} - fun Instant.fmtDate(): String = DateTimeFormatter.ISO_LOCAL_DATE.withZone(ZoneId.of("UTC")).format(this) |