gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/06: storing pain.001 as log file


From: gnunet
Subject: [libeufin] 01/06: storing pain.001 as log file
Date: Thu, 09 Nov 2023 11:55:59 +0100

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

ms pushed a commit to branch master
in repository libeufin.

commit 26c237198c053efb21fc29bf2e422fa1726a47ee
Author: MS <ms@taler.net>
AuthorDate: Thu Nov 9 11:48:39 2023 +0100

    storing pain.001 as log file
---
 .../main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
index 554de068..ba713ae2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
@@ -29,10 +29,19 @@ import tech.libeufin.nexus.ebics.EbicsEarlyException
 import tech.libeufin.nexus.ebics.EbicsUploadException
 import tech.libeufin.nexus.ebics.submitPain001
 import tech.libeufin.util.parsePayto
+import tech.libeufin.util.toDbMicros
+import java.io.File
+import java.nio.file.Path
+import java.text.DateFormat
 import java.time.Instant
+import java.time.LocalDate
+import java.time.ZoneId
 import java.util.*
 import javax.xml.crypto.Data
 import kotlin.concurrent.fixedRateTimer
+import kotlin.io.path.createDirectories
+import kotlin.io.path.createParentDirectories
+import kotlin.math.log
 import kotlin.system.exitProcess
 
 /**
@@ -127,6 +136,31 @@ private suspend fun submitInitiatedPayment(
             cause = permanent
         )
     }
+    // Submission succeeded, storing the pain.001 to file.
+    val logDir: String? = cfg.config.lookupString(
+        "[neuxs-submit]",
+        "SUBMISSIONS_LOG_DIRECTORY"
+    )
+    if (logDir != null) {
+        try { Path.of(logDir).createDirectories() }
+        catch (e: Exception) {
+            logger.error("Could not create log directory of path: $logDir")
+            exitProcess(1)
+        }
+        val now = Instant.now()
+        val asUtcDate = LocalDate.ofInstant(now, ZoneId.of("UTC"))
+        val f = Path.of(
+            
"${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}",
+            
"${now.toDbMicros()}_requestUid_${initiatedPayment.requestUid}_pain.001.xml"
+        ).toFile()
+        val completePath = Path.of(logDir, f.path)
+        // Very rare: same pain.001 should not be submitted twice in the same 
microsecond.
+        if (f.exists()) {
+            logger.error("pain.001 log file exists already at: $completePath")
+            exitProcess(1)
+        }
+        completePath.toFile().writeText(xml)
+    }
 }
 
 /**

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