gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: sandbox uses clikt


From: gnunet
Subject: [libeufin] branch master updated: sandbox uses clikt
Date: Thu, 04 Jun 2020 22:26:34 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 4ebc2ee  sandbox uses clikt
4ebc2ee is described below

commit 4ebc2ee35e0014e7bf1702666e17c873729beb7d
Author: MS <ms@taler.net>
AuthorDate: Thu Jun 4 22:26:11 2020 +0200

    sandbox uses clikt
---
 sandbox/build.gradle                               |  2 +-
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    |  4 +--
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 36 ++++++++++++++++------
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/sandbox/build.gradle b/sandbox/build.gradle
index 19bcb51..59f33dc 100644
--- a/sandbox/build.gradle
+++ b/sandbox/build.gradle
@@ -55,7 +55,7 @@ dependencies {
     implementation group: 'org.bouncycastle', name: 'bcprov-jdk16', version: 
'1.45'
     implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
     implementation group: 'org.apache.commons', name: 'commons-compress', 
version: '1.20'
-
+    implementation("com.github.ajalt:clikt:2.7.0")
     implementation "org.jetbrains.exposed:exposed-core:$exposed_version"
     implementation "org.jetbrains.exposed:exposed-dao:$exposed_version"
     implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version"
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 8b8ce34..13b92ab 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -299,8 +299,8 @@ class BankAccountEntity(id: EntityID<Int>) : IntEntity(id) {
     var subscriber by EbicsSubscriberEntity referencedOn 
BankAccountsTable.subscriber
 }
 
-fun dbCreateTables() {
-    Database.connect("jdbc:sqlite:libeufin-sandbox.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/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 48e899e..8f77187 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -49,21 +49,21 @@ import tech.libeufin.util.RawPayment
 import java.lang.ArithmeticException
 import java.math.BigDecimal
 import java.security.interfaces.RSAPublicKey
-import java.text.DateFormat
 import javax.xml.bind.JAXBContext
 import com.fasterxml.jackson.core.util.DefaultIndenter
 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
-import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.SerializationFeature
-import com.fasterxml.jackson.databind.exc.MismatchedInputException
 import com.fasterxml.jackson.module.kotlin.KotlinModule
-import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
-import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import io.ktor.http.toHttpDateString
 import org.jetbrains.exposed.sql.statements.api.ExposedBlob
 import java.time.Instant
-import java.time.LocalDate
-import java.time.LocalDateTime
+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.options.default
+import com.github.ajalt.clikt.parameters.options.option
+import com.github.ajalt.clikt.parameters.options.prompt
 
 class CustomerNotFound(id: String?) : Exception("Customer ${id} not found")
 class BadInputData(inputData: String?) : Exception("Customer provided invalid 
input data: ${inputData}")
@@ -77,6 +77,17 @@ data class SandboxError(
     val reason: String
 ) : java.lang.Exception()
 
+class SandboxCommand : CliktCommand() {
+    override fun run() = Unit
+}
+
+class Serve : CliktCommand("Run sandbox HTTP server") {
+    private val dbName by option().default("libeufin-sandbox.sqlite3")
+    override fun run() {
+        serverMain(dbName)
+    }
+}
+
 fun findEbicsSubscriber(partnerID: String, userID: String, systemID: String?): 
EbicsSubscriberEntity? {
     return if (systemID == null) {
         EbicsSubscriberEntity.find {
@@ -117,13 +128,18 @@ inline fun <reified T> Document.toObject(): T {
 }
 
 fun BigDecimal.signToString(): String {
-
     return if (this.signum() > 0) "+" else ""
     // minus sign is added by default already.
 }
 
-fun main() {
-    dbCreateTables()
+fun main(args: Array<String>) {
+    SandboxCommand()
+        .subcommands(Serve())
+        .main(args)
+}
+
+fun serverMain(dbName: String) {
+    dbCreateTables(dbName)
     val server = embeddedServer(Netty, port = 5000) {
         install(CallLogging) {
             this.level = Level.DEBUG

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]