Skip to content

Commit

Permalink
address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Sep 5, 2023
1 parent 4108f2f commit 6aabcb3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public abstract class AbstractAwsSdkClientFactory<
config.retryStrategy = resolveRetryStrategy(profile = profile)
}

if (block != null) {
config.apply(block)
}
block?.let(config::apply)

config.logMode = config.logMode ?: ClientSettings.LogMode.resolve(platform = PlatformProvider.System)
config.region = config.region ?: resolveRegion(profile = profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public object AwsSdkSetting {
/**
* Resolves an endpoint url for a given service.
*/
@InternalSdkApi
public fun AwsSdkSetting.resolveEndpointUrl(
provider: PlatformProvider,
sysPropSuffix: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,4 @@ internal fun AwsProfile.getUrlOrNull(key: String, subKey: String? = null): Url?
}

private fun buildKeyString(key: String, subKey: String? = null): String =
buildString {
append(key)
subKey?.let { append(".$it") }
}
listOfNotNull(key, subKey).joinToString(".")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package aws.sdk.kotlin.codegen

private val whitespaceRegex = Regex("\\s")

/**
* Implements a single standardized sdkId transform.
*/
Expand Down Expand Up @@ -56,4 +58,4 @@ object SdkIdTransform {
*/
fun String.withTransform(transformer: SdkIdTransformer): String = transformer.transform(this)

private fun String.replaceWhitespace(replacement: String) = replace(Regex("\\s"), replacement)
private fun String.replaceWhitespace(replacement: String) = replace(whitespaceRegex, replacement)
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,16 @@ internal data class EndpointUrlConfigNames(
)

internal fun String.toEndpointUrlConfigNames(): EndpointUrlConfigNames = EndpointUrlConfigNames(
withTransform(JVMSystemPropertySuffix),
withTransform(JvmSystemPropertySuffix),
withTransform(SdkIdTransform.UpperSnakeCase),
withTransform(SdkIdTransform.LowerSnakeCase),
)

// JVM system property names follow those used by the Java SDK, which for service-specific endpoint URL config uses the
// pattern "aws.endpointUrl${BaseClientName}"
//
// this is an arbitrary sdkId transform to replicate the derivation of BaseClientName - see
// https://github.com/aws/aws-sdk-java-v2/blob/master/codegen/src/main/java/software/amazon/awssdk/codegen/naming/DefaultNamingStrategy.java#L116
private object JVMSystemPropertySuffix : SdkIdTransformer {
// JVM system property names follow the pattern "aws.endpointUrl${BaseClientName}"
// where BaseClientName is the PascalCased sdk ID with any forbidden suffixes dropped - this is the same as what we use
// for our client names
// e.g. sdkId "Elasticsearch Service" -> client name "ElasticsearchClient", prop "aws.endpointUrlElasticsearch"
private object JvmSystemPropertySuffix : SdkIdTransformer {
override fun transform(id: String): String =
id.toPascalCase().removePrefix("Amazon").removePrefix("Aws").removeSuffix("Service")
id.toPascalCase().removeSuffix("Service")
}

0 comments on commit 6aabcb3

Please sign in to comment.