diff --git a/hoplite-aws-kotlin/src/main/kotlin/com/sksamuel/hoplite/aws/kotlin/AwsSecretsManagerPreprocessor.kt b/hoplite-aws-kotlin/src/main/kotlin/com/sksamuel/hoplite/aws/kotlin/AwsSecretsManagerPreprocessor.kt index 7d93784b..28225e0f 100644 --- a/hoplite-aws-kotlin/src/main/kotlin/com/sksamuel/hoplite/aws/kotlin/AwsSecretsManagerPreprocessor.kt +++ b/hoplite-aws-kotlin/src/main/kotlin/com/sksamuel/hoplite/aws/kotlin/AwsSecretsManagerPreprocessor.kt @@ -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() @@ -87,7 +93,7 @@ class AwsSecretsManagerPreprocessor( .withMeta(CommonMetadata.RemoteLookup, "AWS '$key'") .valid() } else { - val map = runCatching { Json.Default.decodeFromString>(secret) }.getOrElse { emptyMap() } + val map = runCatching { json.decodeFromString>(secret) }.getOrElse { emptyMap() } val indexedValue = map[index] if (indexedValue == null) ConfigFailure.PreprocessorWarning(