libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 4ebe7337a586779b7ae8414523188cdf7e768ed8
parent 43e7d5558e36baac7c74dffce893360d41bf4410
Author: MS <ms@taler.net>
Date:   Tue, 26 May 2020 13:20:43 +0200

admit --db option

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 4++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 14++++++++------
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -269,8 +269,8 @@ class NexusBankConnectionEntity(id: EntityID<String>) : Entity<String>(id) { var owner by NexusUserEntity referencedOn NexusBankConnectionsTable.owner } -fun dbCreateTables() { - Database.connect("jdbc:sqlite:libeufin-nexus.sqlite3", "org.sqlite.JDBC") +fun dbCreateTables(dbName: String) { + Database.connect("jdbc:sqlite:${dbName}", "org.sqlite.JDBC") TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE transaction { addLogger(StdOutSqlLogger) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -32,6 +32,8 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.ProgramResult import com.github.ajalt.clikt.core.subcommands import com.github.ajalt.clikt.parameters.arguments.argument +import com.github.ajalt.clikt.parameters.arguments.default +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 io.ktor.application.ApplicationCall @@ -80,17 +82,18 @@ class NexusCommand : CliktCommand() { } class Serve : CliktCommand("Run nexus HTTP server") { + private val dbName by option().default("libeufin-nexus.sqlite3") override fun run() { - serverMain() + serverMain(dbName) } } - class Superuser : CliktCommand("Add superuser or change pw") { + private val dbName by option().default("libeufin-nexus.sqlite3") private val username by argument() private val password by option().prompt(requireConfirmation = true, hideInput = true) override fun run() { - dbCreateTables() + dbCreateTables(dbName) transaction { val hashedPw = hashpw(password) val user = NexusUserEntity.findById(username) @@ -221,9 +224,8 @@ fun requireBankConnection(call: ApplicationCall, parameterKey: String): NexusBan return conn } - -fun serverMain() { - dbCreateTables() +fun serverMain(dbName: String) { + dbCreateTables(dbName) val client = HttpClient { expectSuccess = false // this way, it does not throw exceptions on != 200 responses. }