Skip to content

Commit

Permalink
support custom json serde
Browse files Browse the repository at this point in the history
  • Loading branch information
samu-developments committed Oct 16, 2024
1 parent 6125700 commit e32c990
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ import kotlinx.serialization.json.Json
*/
class AwsSecretsManagerPreprocessor(
private val report: Boolean = false,
private val json: Json,
createClient: () -> SecretsManagerClient = { runBlocking { SecretsManagerClient.fromEnvironment() } }
) : TraversingPrimitivePreprocessor() {

constructor(
report: Boolean = false,
createClient: () -> SecretsManagerClient = { runBlocking { SecretsManagerClient.fromEnvironment() } }
) : this(report, Json.Default, createClient)

private val client by lazy { createClient() }
private val regex1 = "\\$\\{awssecret:(.+?)}".toRegex()
private val regex2 = "secretsmanager://(.+?)".toRegex()
Expand Down Expand Up @@ -87,7 +93,7 @@ class AwsSecretsManagerPreprocessor(
.withMeta(CommonMetadata.RemoteLookup, "AWS '$key'")
.valid()
} else {
val map = runCatching { Json.Default.decodeFromString<Map<String, String>>(secret) }.getOrElse { emptyMap() }
val map = runCatching { json.decodeFromString<Map<String, String>>(secret) }.getOrElse { emptyMap() }
val indexedValue = map[index]
if (indexedValue == null)
ConfigFailure.PreprocessorWarning(
Expand Down

0 comments on commit e32c990

Please sign in to comment.