diff options
author | Antoine A <> | 2024-04-30 13:19:45 +0900 |
---|---|---|
committer | Antoine A <> | 2024-04-30 13:19:45 +0900 |
commit | 15ab519ed54c0d5ca5840c175f9aa0642a6ccf87 (patch) | |
tree | 91ca961f29f1510cf9b04146fd378e8683d7c5ed /nexus/src/main/kotlin | |
parent | 602a3b6e8afa3462a4f34cd6bb92005fec84c90b (diff) | |
download | libeufin-15ab519ed54c0d5ca5840c175f9aa0642a6ccf87.tar.gz libeufin-15ab519ed54c0d5ca5840c175f9aa0642a6ccf87.tar.bz2 libeufin-15ab519ed54c0d5ca5840c175f9aa0642a6ccf87.zip |
nexus: add libeufin-nexus serve
Diffstat (limited to 'nexus/src/main/kotlin')
4 files changed, 21 insertions, 6 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt index 8e876f20..43cef8ca 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -364,7 +364,7 @@ class EbicsFetch: CliktCommand("Fetches EBICS files") { * mode when no flags are passed to the invocation. */ override fun run() = cliCmd(logger, common.log) { - val cfg = extractEbicsConfig(common.config) + val cfg = loadNexusConfig(common.config) val dbCfg = cfg.config.dbConfig() Database(dbCfg, cfg.currency).use { db -> diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt index 1c9ea902..7da7da07 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSetup.kt @@ -155,7 +155,7 @@ suspend fun doKeysRequestAndUpdateState( * @param configFile location of the configuration entry point. * @return internal representation of the configuration. */ -fun extractEbicsConfig(configFile: Path?): NexusConfig { +fun loadNexusConfig(configFile: Path?): NexusConfig { val config = loadConfig(configFile) return NexusConfig(config) } @@ -197,8 +197,8 @@ class EbicsSetup: CliktCommand("Set up the EBICS subscriber") { * This function collects the main steps of setting up an EBICS access. */ override fun run() = cliCmd(logger, common.log) { - val cfg = extractEbicsConfig(common.config) - val client = HttpClient { + val cfg = loadNexusConfig(common.config) + val client = HttpClient { install(HttpTimeout) { // It can take a lot of time for the bank to generate documents socketTimeoutMillis = 5 * 60 * 1000 diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt index 947ecab6..c6a6ceef 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt @@ -147,7 +147,7 @@ class EbicsSubmit : CliktCommand("Submits any initiated payment found in the dat * FIXME: reduce code duplication with the fetch subcommand. */ override fun run() = cliCmd(logger, common.log) { - val cfg = extractEbicsConfig(common.config) + val cfg = loadNexusConfig(common.config) val dbCfg = cfg.config.dbConfig() val (clientKeys, bankKeys) = expectFullKeys(cfg) val ctx = SubmissionContext( diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index d4f133bd..c8b46008 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -146,6 +146,21 @@ class InitiatePayment: CliktCommand("Initiate an outgoing payment") { } } +class Serve : CliktCommand("Run libeufin-nexus HTTP server", name = "serve") { + private val common by CommonOption() + + override fun run() = cliCmd(logger, common.log) { + val cfg = loadNexusConfig(common.config) + val dbCfg = cfg.config.dbConfig() + val serverCfg = cfg.config.loadServerConfig("nexus-httpd") + Database(dbCfg, cfg.currency).use { db -> + serve(serverCfg) { + nexusApi(db, cfg) + } + } + } +} + class ConvertBackup: CliktCommand("Convert an old backup to the new config format") { private val backupPath by argument( "backup", @@ -302,7 +317,7 @@ class TestingCmd : CliktCommand("Testing helper commands", name = "testing") { class LibeufinNexusCommand : CliktCommand() { init { versionOption(getVersion()) - subcommands(EbicsSetup(), DbInit(), EbicsSubmit(), EbicsFetch(), InitiatePayment(), CliConfigCmd(NEXUS_CONFIG_SOURCE), TestingCmd()) + subcommands(EbicsSetup(), DbInit(), Serve(), EbicsSubmit(), EbicsFetch(), InitiatePayment(), CliConfigCmd(NEXUS_CONFIG_SOURCE), TestingCmd()) } override fun run() = Unit } |