Skip to content

Commit

Permalink
changed ssm version to 2+, fixed code to support new API
Browse files Browse the repository at this point in the history
Merge-request: KONFY-MR-3
Merged-by: Dinn Diallo <[email protected]>
  • Loading branch information
Dinn Diallo authored and qodana-bot committed Apr 9, 2024
1 parent cba1e9b commit 499a27e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import tanvd.kosogor.proxy.publishJar

group = "tanvd.konfy"
version = "0.1.27"
version = "0.1.28"

plugins {
id("tanvd.kosogor") version "1.0.18" apply false
id("io.gitlab.arturbosch.detekt") version ("1.22.0") apply true
kotlin("jvm") version "1.9.21" apply false
kotlin("jvm") version "1.9.22" apply false
`kotlin-dsl`
`maven-publish`
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
4 changes: 2 additions & 2 deletions konfy-ssm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 0 additions & 7 deletions konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClient.kt

This file was deleted.

8 changes: 8 additions & 0 deletions konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmClientFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tanvd.konfy.ssm

import software.amazon.awssdk.services.ssm.SsmClient


internal object SsmClientFactory {
val defaultClient by lazy { SsmClient.create()!! }
}
12 changes: 6 additions & 6 deletions konfy-ssm/src/main/kotlin/tanvd/konfy/ssm/SsmProvider.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
18 changes: 10 additions & 8 deletions konfy-ssm/src/test/kotlin/SsmProviderTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<String>(key, String::class.java)
assertTrue(consoleOutput.toString().contains(logMessage))

//then
assertTrue(consoleOutput.toString().contains(logMessage))
} finally {
//cleanup
System.clearProperty(konfyLogKeysParam)
System.setOut(oldOut)
}
Expand Down

0 comments on commit 499a27e

Please sign in to comment.