Skip to content

Commit

Permalink
Added configuration options for sigv4a signing region set
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Feb 27, 2024
1 parent 4ff7c81 commit b40f92e
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting {
public final fun getAwsSecretAccessKey ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsSessionToken ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsSharedCredentialsFile ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsSigv4aSigningRegionSet ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsUseDualStackEndpoint ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsUseFipsEndpoint ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsWebIdentityTokenFile ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
Expand Down Expand Up @@ -472,6 +473,7 @@ public final class aws/sdk/kotlin/runtime/config/profile/AwsProfileKt {
public static final fun getRoleArn (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getSdkUserAgentAppId (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getServicesSection (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getSigv4aSigningRegionSet (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getSourceProfile (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getUseDualStack (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
public static final fun getUseFips (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Boolean;
Expand Down Expand Up @@ -506,6 +508,11 @@ public final class aws/sdk/kotlin/runtime/config/retries/ResolveRetryStrategyKt
public static synthetic fun resolveRetryStrategy$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/config/sigv4a/ResolveSigningRegionSetKt {
public static final fun resolveSigningRegionSet (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveSigningRegionSet$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/config/useragent/ResolveUserAgentKt {
public static final fun resolveUserAgentAppId (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveUserAgentAppId$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.AwsSharedConfig
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.config.retries.resolveRetryStrategy
import aws.sdk.kotlin.runtime.config.sigv4a.resolveSigningRegionSet
import aws.sdk.kotlin.runtime.config.useragent.resolveUserAgentAppId
import aws.sdk.kotlin.runtime.region.resolveRegion
import aws.smithy.kotlin.runtime.ExperimentalApi
Expand Down Expand Up @@ -79,6 +80,7 @@ public abstract class AbstractAwsSdkClientFactory<
config.useFips = config.useFips ?: resolveUseFips(profile = profile)
config.useDualStack = config.useDualStack ?: resolveUseDualStack(profile = profile)
config.applicationId = config.applicationId ?: resolveUserAgentAppId(platform, profile)
config.sigv4aSigningRegionSet = config.sigv4aSigningRegionSet ?: resolveSigningRegionSet(platform, profile)

if (config is CompressionClientConfig.Builder) {
config.requestCompression.disableRequestCompression =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ public object AwsSdkSetting {
*/
public val AwsRequestMinCompressionSizeBytes: EnvironmentSetting<Long> =
longEnvSetting("aws.requestMinCompressionSizeBytes", "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES")

/**
* The set of regions to use when signing a request with sigV4a.
*/
public val AwsSigv4aSigningRegionSet: EnvironmentSetting<String> =
strEnvSetting("aws.sigv4aSigningRegionSet", "AWS_SIGV4A_SIGNING_REGION_SET")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ public val AwsProfile.disableRequestCompression: Boolean?
public val AwsProfile.requestMinCompressionSizeBytes: Long?
get() = getLongOrNull("request_min_compression_size_bytes")

/**
* The set of regions to use when signing a request with sigV4a.
*/
@InternalSdkApi
public val AwsProfile.sigv4aSigningRegionSet: String?
get() = getOrNull("sigv4a_signing_region_set")

/**
* Parse a config value as a boolean, ignoring case.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.runtime.config.sigv4a

import aws.sdk.kotlin.runtime.InternalSdkApi
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.sigv4aSigningRegionSet
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider

/**
* Attempts to resolve sigv4aSigningRegionSet from specified sources.
* @return The sigv4aSigningRegionSet if found, null if not
*/
@InternalSdkApi
public suspend fun resolveSigningRegionSet(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): List<String>? {
val rawString = AwsSdkSetting.AwsSigv4aSigningRegionSet.resolve(platform) ?: profile.get().sigv4aSigningRegionSet
return rawString?.let {
check(isValidListFormat(it)) { "Config setting sigv4aSigningRegionSet is not formatted as a list of strings" }
it.split(",")
}
}

/**
* Makes sure that a string can be parsed into a list of non-empty strings
*/
internal fun isValidListFormat(input: String): Boolean =
Regex("^\\s*([^,\\s]+\\s*,\\s*)*[^,\\s]+\\s*\$").matches(input)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.runtime.config.sigv4a

import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class IsValidListFormatTest {
@Test
fun regexWorks() {
assertTrue(isValidListFormat("apple"))
assertTrue(isValidListFormat("apple,banana,orange"))
assertTrue(isValidListFormat("apple, banana, orange"))
assertTrue(isValidListFormat("apple, banana, orange "))

assertFalse(isValidListFormat(""))
assertFalse(isValidListFormat(" "))
assertFalse(isValidListFormat("apple, , orange"))
assertFalse(isValidListFormat("apple banana"))
assertFalse(isValidListFormat("apple,banana,orange,"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private interface TestClient : SdkClient {
override var useFips: Boolean = builder.useFips ?: false
override var useDualStack: Boolean = builder.useDualStack ?: false
override val applicationId: String? = builder.applicationId
override val sigv4aSigningRegionSet: List<String>? = builder.sigv4aSigningRegionSet

// new: inherits builder equivalents for Config base classes
class Builder : AwsSdkClientConfig.Builder, SdkClientConfig.Builder<Config>, RetryStrategyClientConfig.Builder by RetryStrategyClientConfigImpl.BuilderImpl() {
Expand All @@ -138,6 +139,7 @@ private interface TestClient : SdkClient {
override var useFips: Boolean? = null
override var useDualStack: Boolean? = null
override var applicationId: String? = null
override var sigv4aSigningRegionSet: List<String>? = null
override fun build(): Config = Config(this)
}
}
Expand Down
3 changes: 3 additions & 0 deletions aws-runtime/aws-core/api/aws-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ public final class aws/sdk/kotlin/runtime/client/AwsClientOption {
public abstract interface class aws/sdk/kotlin/runtime/client/AwsSdkClientConfig : aws/smithy/kotlin/runtime/client/SdkClientConfig {
public abstract fun getApplicationId ()Ljava/lang/String;
public abstract fun getRegion ()Ljava/lang/String;
public abstract fun getSigv4aSigningRegionSet ()Ljava/util/List;
public abstract fun getUseDualStack ()Z
public abstract fun getUseFips ()Z
}

public abstract interface class aws/sdk/kotlin/runtime/client/AwsSdkClientConfig$Builder {
public abstract fun getApplicationId ()Ljava/lang/String;
public abstract fun getRegion ()Ljava/lang/String;
public abstract fun getSigv4aSigningRegionSet ()Ljava/util/List;
public abstract fun getUseDualStack ()Ljava/lang/Boolean;
public abstract fun getUseFips ()Ljava/lang/Boolean;
public abstract fun setApplicationId (Ljava/lang/String;)V
public abstract fun setRegion (Ljava/lang/String;)V
public abstract fun setSigv4aSigningRegionSet (Ljava/util/List;)V
public abstract fun setUseDualStack (Ljava/lang/Boolean;)V
public abstract fun setUseFips (Ljava/lang/Boolean;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public interface AwsSdkClientConfig : SdkClientConfig {
*/
public val applicationId: String?

/**
* The set of regions to use when signing a request with sigV4a. If provided it will override endpoints metadata.
*/
public val sigv4aSigningRegionSet: List<String>?

public interface Builder {
/**
* The AWS region (e.g. `us-west-2`) to make requests to. See about AWS
Expand Down Expand Up @@ -80,5 +85,10 @@ public interface AwsSdkClientConfig : SdkClientConfig {
* reference for more information on environment variables and shared config settings.
*/
public var applicationId: String?

/**
* The set of regions to use when signing a request with sigV4a. If provided it will override endpoints metadata.
*/
public var sigv4aSigningRegionSet: List<String>?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ class AwsServiceConfigIntegration : KotlinIntegration {
},
)
}

val Sigv4aSigningRegionSet: ConfigProperty = ConfigProperty {
name = "sigv4aSigningRegionSet"
symbol = KotlinTypes.Collections.list(KotlinTypes.String).asNullable()
baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig
useNestedBuilderBaseClass()
documentation = """
The set of regions to use when signing a request with sigV4a. If not provided this will automatically be set by the SDK.
""".trimIndent()
order = 100
}
}

override val sectionWriters: List<SectionWriterBinding> =
Expand All @@ -139,5 +150,6 @@ class AwsServiceConfigIntegration : KotlinIntegration {

add(AwsRetryPolicy)
add(UserAgentAppId)
add(Sigv4aSigningRegionSet)
}
}

0 comments on commit b40f92e

Please sign in to comment.