diff --git a/konfy-ssm/build.gradle.kts b/konfy-ssm/build.gradle.kts index 0ae1fe6..497810c 100644 --- a/konfy-ssm/build.gradle.kts +++ b/konfy-ssm/build.gradle.kts @@ -4,8 +4,8 @@ version = rootProject.version dependencies { api(project(":konfy")) - api("com.amazonaws", "aws-java-sdk-ssm", "1.12.655") - implementation("org.slf4j:slf4j-api:1.7.36") + api("software.amazon.awssdk", "ssm", "2.25.13") + implementation("org.slf4j", "slf4j-api", "1.7.36") testImplementation("org.testng", "testng", "7.9.0") testImplementation("org.assertj", "assertj-core", "3.25.3") diff --git a/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClient.kt b/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClient.kt deleted file mode 100644 index be61da8..0000000 --- a/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClient.kt +++ /dev/null @@ -1,7 +0,0 @@ -package tanvd.konfy.ssm - -import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder - -internal object SsmClient { - val defaultClient by lazy { AWSSimpleSystemsManagementClientBuilder.defaultClient()!! } -} diff --git a/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClientFactory.kt b/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClientFactory.kt new file mode 100644 index 0000000..4acd24f --- /dev/null +++ b/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClientFactory.kt @@ -0,0 +1,8 @@ +package tanvd.konfy.ssm + +import software.amazon.awssdk.services.ssm.SsmClient + + +internal object SsmClientFactory { + val defaultClient by lazy { SsmClient.create()!! } +} diff --git a/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmProvider.kt b/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmProvider.kt index 3e38fc3..49163e5 100644 --- a/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmProvider.kt +++ b/konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmProvider.kt @@ -1,9 +1,9 @@ package tanvd.konfy.ssm -import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement -import com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest -import com.amazonaws.services.simplesystemsmanagement.model.ParameterNotFoundException import org.slf4j.LoggerFactory +import software.amazon.awssdk.services.ssm.SsmClient +import software.amazon.awssdk.services.ssm.model.GetParameterRequest +import software.amazon.awssdk.services.ssm.model.ParameterNotFoundException import tanvd.konfy.conversion.ConversionService import tanvd.konfy.provider.ConfigProvider import java.lang.reflect.Type @@ -18,7 +18,7 @@ private const val KONFY_LOG_KEYS = "KONFY_LOG_KEYS" * @param separator separator used by a client, provider will map it to `/` */ class SsmProvider(private val prefix: String?, private val separator: String, - private val ssm: AWSSimpleSystemsManagement = SsmClient.defaultClient, + private val ssm: SsmClient = SsmClientFactory.defaultClient, private val convert: (String, Type) -> Any? = ConversionService::convert) : ConfigProvider() { private val logger = LoggerFactory.getLogger(SsmProvider::class.java) @@ -36,9 +36,9 @@ class SsmProvider(private val prefix: String?, private val separator: String, log(key) val fullKey = (prefix?.let { "$it/$key" } ?: key).replace(separator, "/") - val request = GetParameterRequest().withName(fullKey).withWithDecryption(true) + val request = GetParameterRequest.builder().name(fullKey).withDecryption(true).build() return try { - ssm.getParameter(request)?.parameter?.value?.let { convert(it, type) as N } + ssm.getParameter(request)?.parameter()?.value()?.let { convert(it, type) as N } } catch (e: ParameterNotFoundException) { null } diff --git a/konfy-ssm/src/test/kotlin/SsmProviderTest.kt b/konfy-ssm/src/test/kotlin/SsmProviderTest.kt index 78f5d09..799a85a 100644 --- a/konfy-ssm/src/test/kotlin/SsmProviderTest.kt +++ b/konfy-ssm/src/test/kotlin/SsmProviderTest.kt @@ -1,7 +1,7 @@ -import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement import io.mockk.mockk import org.testng.Assert.assertTrue import org.testng.annotations.Test +import software.amazon.awssdk.services.ssm.SsmClient import tanvd.konfy.ssm.SsmProvider import java.io.ByteArrayOutputStream import java.io.PrintStream @@ -13,23 +13,25 @@ class SsmProviderTest { val oldOut = System.out val konfyLogKeysParam = "KONFY_LOG_KEYS" try { + //setup + val consoleOutput = ByteArrayOutputStream() + val ps = PrintStream(consoleOutput) + System.setOut(ps) + //given val key = "testKey" System.setProperty(konfyLogKeysParam, key) val logMessage = "Fetching parameter with key: $key \n Stack trace:" - val management: AWSSimpleSystemsManagement = mockk(relaxed = true) - val provider = SsmProvider(null, ".", management) - - val consoleOutput = ByteArrayOutputStream() - val ps = PrintStream(consoleOutput) - System.setOut(ps) + val ssmClient: SsmClient = mockk(relaxed = true) + val provider = SsmProvider(null, ".", ssmClient) //when provider.fetch(key, String::class.java) - assertTrue(consoleOutput.toString().contains(logMessage)) //then + assertTrue(consoleOutput.toString().contains(logMessage)) } finally { + //cleanup System.clearProperty(konfyLogKeysParam) System.setOut(oldOut) }