commit 786b70a1327066bc5670aa6ccc0c5f4f2ec6ed1c
parent 5b881469b7e92b39fc0d745ee48c43d4e533aeb9
Author: ms <ms@taler.net>
Date: Tue, 29 Jun 2021 13:50:16 +0200
helper that returns a bank configuration, given the hostname.
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -92,6 +92,7 @@ object SandboxConfigsTable : LongIdTable() {
val allowRegistrations = bool("allowRegistrations")
val bankDebtLimit = integer("bankDebtLimit")
val usersDebtLimit = integer("usersDebtLimit")
+ val hostname = text("hostname")
}
class SandboxConfigEntity(id: EntityID<Long>) : LongEntity(id) {
@@ -100,6 +101,7 @@ class SandboxConfigEntity(id: EntityID<Long>) : LongEntity(id) {
var allowRegistrations by SandboxConfigsTable.allowRegistrations
var bankDebtLimit by SandboxConfigsTable.bankDebtLimit
var usersDebtLimit by SandboxConfigsTable.usersDebtLimit
+ var name by SandboxConfigsTable.hostname
}
object SandboxUsersTable : LongIdTable() {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -75,6 +75,27 @@ fun getBankAccountFromSubscriber(subscriber: EbicsSubscriberEntity): BankAccount
)
}
}
+
+/**
+ * Fetch a configuration for Sandbox, corresponding to the host that runs the service.
+ */
+fun getSandboxConfig(hostname: String?): SandboxConfigEntity {
+ var ret: SandboxConfigEntity? = transaction {
+ if (hostname == null) {
+ SandboxConfigEntity.all().firstOrNull()
+ } else {
+ SandboxConfigEntity.find {
+ SandboxConfigsTable.hostname eq hostname
+ }.firstOrNull()
+ }
+ }
+ if (ret == null) throw SandboxError(
+ HttpStatusCode.InternalServerError,
+ "Serving from a non configured host"
+ )
+ return ret
+}
+
fun getEbicsSubscriberFromDetails(userID: String, partnerID: String, hostID: String): EbicsSubscriberEntity {
return transaction {
EbicsSubscriberEntity.find {