gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: nexus


From: gnunet
Subject: [libeufin] branch master updated: nexus
Date: Fri, 10 Nov 2023 13:20:43 +0100

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 554a3135 nexus
554a3135 is described below

commit 554a31357786dc80cd5db5310b184ca532747566
Author: MS <ms@taler.net>
AuthorDate: Fri Nov 10 13:08:04 2023 +0100

    nexus
    
    - handling write errors to log directories
    - defining EBICS 'reachability' error code
---
 nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt     | 15 ---------------
 nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt |  8 ++------
 .../src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt  | 14 +++++---------
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt       | 17 ++++++++++++++++-
 4 files changed, 23 insertions(+), 31 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt
index d170eee0..7a823624 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt
@@ -7,21 +7,6 @@ import tech.libeufin.util.initializeDatabaseTables
 import tech.libeufin.util.resetDatabaseTables
 import kotlin.system.exitProcess
 
-/**
- * Runs the argument and fails the process, if that throws
- * an exception.
- *
- * @param getLambda function that might return a value.
- * @return the value from getLambda.
- */
-fun <T>doOrFail(getLambda: () -> T): T =
-    try {
-        getLambda()
-    } catch (e: Exception) {
-        logger.error(e.message)
-        exitProcess(1)
-    }
-
 /**
  * This subcommand tries to load the SQL files that define
  * the Nexus DB schema.  Admits the --reset option to delete
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index b08bbede..087a9124 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -272,11 +272,7 @@ fun maybeLogFile(cfg: EbicsSetupConfig, content: 
ByteArray) {
     val subDir = 
"${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}"
     // Creating the combined dir.
     val dirs = Path.of(maybeLogDir, subDir)
-    try { dirs.createDirectories() }
-    catch (e: Exception) {
-        logger.error("Could not create log directory of path: $dirs") // check 
how dirs stringifies.
-        exitProcess(1)
-    }
+    doOrFail { dirs.createDirectories() }
     // Write each ZIP entry in the combined dir.
     content.unzipForEach { fileName, xmlContent ->
         val f  = File(dirs.toString(), "${now.toDbMicros()}_$fileName")
@@ -285,7 +281,7 @@ fun maybeLogFile(cfg: EbicsSetupConfig, content: ByteArray) 
{
             logger.error("Log file exists already at: ${f.path}")
             exitProcess(1)
         }
-        f.writeText(xmlContent)
+        doOrFail { f.writeText(xmlContent) }
     }
 }
 
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
index ed428643..dc7d206d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
@@ -52,7 +52,7 @@ enum class NexusSubmissionStage {
      * They are both considered transient (non-200 responses
      * can be fixed by changing and reloading the configuration).
      */
-    http
+    reachability
 }
 
 /**
@@ -111,7 +111,7 @@ private suspend fun submitInitiatedPayment(
     } catch (early: EbicsSideException) {
         val errorStage = when (early.sideEc) {
             EbicsSideError.HTTP_POST_FAILED ->
-                NexusSubmissionStage.http // transient error
+                NexusSubmissionStage.reachability // transient error
             /**
              * Any other [EbicsSideError] should be treated as permanent,
              * as they involve invalid signatures or an unexpected response
@@ -142,11 +142,7 @@ private suspend fun submitInitiatedPayment(
         val asUtcDate = LocalDate.ofInstant(now, ZoneId.of("UTC"))
         val subDir = 
"${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}"
         val dirs = Path.of(logDir, subDir)
-        try { dirs.createDirectories() }
-        catch (e: Exception) {
-            logger.error("Could not create log directory of path: $dirs")
-            exitProcess(1)
-        }
+        doOrFail { dirs.createDirectories() }
         val f = File(
             dirs.toString(),
             
"${now.toDbMicros()}_requestUid_${initiatedPayment.requestUid}_pain.001.xml"
@@ -156,7 +152,7 @@ private suspend fun submitInitiatedPayment(
             logger.error("pain.001 log file exists already at: $f")
             exitProcess(1)
         }
-        f.writeText(xml)
+        doOrFail { f.writeText(xml) }
     }
 }
 
@@ -254,7 +250,7 @@ private fun submitBatch(
                      * cases, the initiated payment stored in the database may 
still be correct,
                      * therefore we set this error as transient, and it'll be 
retried.
                      */
-                    NexusSubmissionStage.http -> 
DatabaseSubmissionState.transient_failure
+                    NexusSubmissionStage.reachability -> 
DatabaseSubmissionState.transient_failure
                     /**
                      * As in the pain.001 case, there is a fundamental problem 
in the document
                      * being submitted, so it should not be retried.
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 63fe23b4..c0ea4b98 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -51,7 +51,7 @@ import java.security.interfaces.RSAPrivateCrtKey
 import java.security.interfaces.RSAPublicKey
 
 val NEXUS_CONFIG_SOURCE = ConfigSource("libeufin-nexus", "libeufin-nexus")
-val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus.Main")
+val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
 val myJson = Json {
     this.serializersModule = SerializersModule {
         contextual(RSAPrivateCrtKey::class) { RSAPrivateCrtKeySerializer }
@@ -208,6 +208,21 @@ data class BankPublicKeysFile(
     var accepted: Boolean
 )
 
+/**
+ * Runs the argument and fails the process, if that throws
+ * an exception.
+ *
+ * @param getLambda function that might return a value.
+ * @return the value from getLambda.
+ */
+fun <T>doOrFail(getLambda: () -> T): T =
+    try {
+        getLambda()
+    } catch (e: Exception) {
+        logger.error(e.message)
+        exitProcess(1)
+    }
+
 /**
  * Load the bank keys file from disk.
  *

-- 
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]