diff options
author | Antoine A <> | 2024-05-01 13:47:06 +0900 |
---|---|---|
committer | Antoine A <> | 2024-05-01 13:47:06 +0900 |
commit | a09b84c636f6332b219480ca620060eb6ca13758 (patch) | |
tree | 45c12f894b4297215814ada6d3aa3e43d9f2fdd3 /nexus | |
parent | 15ab519ed54c0d5ca5840c175f9aa0642a6ccf87 (diff) | |
download | libeufin-a09b84c636f6332b219480ca620060eb6ca13758.tar.gz libeufin-a09b84c636f6332b219480ca620060eb6ca13758.tar.bz2 libeufin-a09b84c636f6332b219480ca620060eb6ca13758.zip |
nexus: add libeufin-nexus-httpd service
Diffstat (limited to 'nexus')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 24 | ||||
-rw-r--r-- | nexus/src/test/kotlin/CliTest.kt | 13 |
2 files changed, 37 insertions, 0 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index c8b46008..b301f555 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -27,6 +27,7 @@ package tech.libeufin.nexus import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.subcommands +import com.github.ajalt.clikt.core.ProgramResult import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.convert import com.github.ajalt.clikt.parameters.groups.provideDelegate @@ -148,9 +149,32 @@ class InitiatePayment: CliktCommand("Initiate an outgoing payment") { class Serve : CliktCommand("Run libeufin-nexus HTTP server", name = "serve") { private val common by CommonOption() + private val check by option().flag() override fun run() = cliCmd(logger, common.log) { val cfg = loadNexusConfig(common.config) + + if (check) { + // Check if the server is to be started + val apis = listOf( + cfg.wireGatewayApiCfg to "Wire Gateway API", + cfg.revenueApiCfg to "Revenue API" + ) + var startServer = false + for ((api, name) in apis) { + if (api != null) { + startServer = true + logger.info("$name is enabled: starting the server") + } + } + if (!startServer) { + logger.info("All APIs are disabled: not starting the server") + throw ProgramResult(1) + } else { + throw ProgramResult(0) + } + } + val dbCfg = cfg.config.dbConfig() val serverCfg = cfg.config.loadServerConfig("nexus-httpd") Database(dbCfg, cfg.currency).use { db -> diff --git a/nexus/src/test/kotlin/CliTest.kt b/nexus/src/test/kotlin/CliTest.kt index 19bc0853..8cc8c59b 100644 --- a/nexus/src/test/kotlin/CliTest.kt +++ b/nexus/src/test/kotlin/CliTest.kt @@ -118,4 +118,17 @@ class CliTest { nexusCmd.testErr("ebics-setup -c $conf", "Could not write client private keys at '$clientKeysPath': permission denied on '${clientKeysPath.parent}'") } } + + /** Test server check */ + @Test + fun serveCheck() { + val confs = listOf( + "mini" to 1, + "test" to 0 + ) + for ((conf, statusCode) in confs) { + val result = nexusCmd.test("serve --check -c conf/$conf.conf") + assertEquals(statusCode, result.statusCode) + } + } }
\ No newline at end of file |