From 1dd3dee0bbff5d774bf95eff0ccab4b23c2bd3db Mon Sep 17 00:00:00 2001 From: Manu Kesava Date: Thu, 13 Jun 2024 17:33:03 -0400 Subject: [PATCH] Added code to check for base64 encoded before writing to DeadLetter Cosmos container --- .../gov/cdc/ocio/processingstatusapi/ReportManager.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pstatus-report-sink-ktor/src/main/kotlin/gov/cdc/ocio/processingstatusapi/ReportManager.kt b/pstatus-report-sink-ktor/src/main/kotlin/gov/cdc/ocio/processingstatusapi/ReportManager.kt index e08e7bef..f272eae2 100644 --- a/pstatus-report-sink-ktor/src/main/kotlin/gov/cdc/ocio/processingstatusapi/ReportManager.kt +++ b/pstatus-report-sink-ktor/src/main/kotlin/gov/cdc/ocio/processingstatusapi/ReportManager.kt @@ -230,7 +230,7 @@ class ReportManager: KoinComponent { this.dispositionType= dispositionType.toString() this.contentType = contentType this.deadLetterReasons= deadLetterReasons - if (contentType?.lowercase() == "json" && !isNullOrEmpty(content)) { + if (contentType?.lowercase() == "json" && !isNullOrEmpty(content) && !isBase64Encoded(content.toString())) { val typeObject = object : TypeToken?>() {}.type val jsonMap: Map = gson.fromJson(Gson().toJson(content, MutableMap::class.java).toString(), typeObject) this.content = jsonMap @@ -260,6 +260,11 @@ class ReportManager: KoinComponent { } } + private fun isBase64Encoded(value: String): Boolean { + val base64Pattern = "^[A-Za-z0-9+/]+={0,2}$" + return value.matches(base64Pattern.toRegex()) + } + fun createReportItem(uploadId: String?, reportId:String, reportType:Any) : String{ var responseReportId = ""