commit 9d87533ef9e43679ec5e84188042afb6f42283fb
parent cecb1db5d4b8fc64a6762a5c0d1e69f45c2a7acc
Author: MS <ms@taler.net>
Date: Wed, 28 Sep 2022 20:22:11 +0200
Optionally listen to all interfaces.
Diffstat:
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -21,9 +21,6 @@ package tech.libeufin.nexus
import com.github.ajalt.clikt.output.CliktHelpFormatter
import com.github.ajalt.clikt.parameters.arguments.argument
-import com.github.ajalt.clikt.parameters.options.default
-import com.github.ajalt.clikt.parameters.options.option
-import com.github.ajalt.clikt.parameters.options.prompt
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@@ -33,7 +30,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.ajalt.clikt.parameters.types.int
import execThrowableOrTerminate
import com.github.ajalt.clikt.core.*
-import com.github.ajalt.clikt.parameters.options.versionOption
+import com.github.ajalt.clikt.parameters.options.*
import startServer
import tech.libeufin.nexus.iso20022.parseCamtMessage
import tech.libeufin.nexus.server.client
@@ -58,6 +55,10 @@ class Serve : CliktCommand("Run nexus HTTP server") {
helpFormatter = CliktHelpFormatter(showDefaultValues = true)
}
}
+ private val localhostOnly by option(
+ "--localhost-only",
+ help = "Bind only to localhost. On all interfaces otherwise"
+ ).flag("--no-localhost-only", default = true)
// Prevent IPv6 mode:
// private val host by option().default("127.0.0.1")
private val port by option().int().default(5001)
@@ -79,7 +80,7 @@ class Serve : CliktCommand("Run nexus HTTP server") {
)
exitProcess(0)
}
- serverMain(port)
+ serverMain(port, localhostOnly)
}
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -1051,17 +1051,17 @@ val nexusApp: Application.() -> Unit = {
}
}
}
-fun serverMain(port: Int) {
+fun serverMain(port: Int, localhostOnly: Boolean) {
val server = embeddedServer(
Netty,
environment = applicationEngineEnvironment {
connector {
this.port = port
- this.host = "127.0.0.1"
+ this.host = if (localhostOnly) "127.0.0.1" else "0.0.0.0"
}
connector {
this.port = port
- this.host = "[::1]"
+ this.host = if (localhostOnly) "[::1]" else "[::]"
}
module(nexusApp)
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -335,6 +335,10 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
"--auth",
help = "Disable authentication."
).flag("--no-auth", default = true)
+ private val localhostOnly by option(
+ "--localhost-only",
+ help = "Bind only to localhost. On all interfaces otherwise"
+ ).flag("--no-localhost-only", default = true)
private val logLevel by option()
private val port by option().int().default(5000)
private val withUnixSocket by option(
@@ -364,7 +368,7 @@ class Serve : CliktCommand("Run sandbox HTTP server") {
)
exitProcess(0)
}
- serverMain(port)
+ serverMain(port, localhostOnly)
}
}
@@ -1594,17 +1598,17 @@ val sandboxApp: Application.() -> Unit = {
}
}
-fun serverMain(port: Int) {
+fun serverMain(port: Int, localhostOnly: Boolean) {
val server = embeddedServer(
Netty,
environment = applicationEngineEnvironment{
connector {
this.port = port
- this.host = "127.0.0.1"
+ this.host = if (localhostOnly) "127.0.0.1" else "0.0.0.0"
}
connector {
this.port = port
- this.host = "[::1]"
+ this.host = if (localhostOnly) "[::1]" else "[::]"
}
parentCoroutineContext = Dispatchers.Main
module(sandboxApp)