Skip to content

Commit

Permalink
feat!: implement client config overrides (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Jan 25, 2023
1 parent ae2544e commit b8a764d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object AwsRuntimeTypes {
object Credentials : RuntimeTypePackage(AwsKotlinDependency.AWS_CONFIG, "auth.credentials") {
val DefaultChainCredentialsProvider = symbol("DefaultChainCredentialsProvider")
val StaticCredentialsProvider = symbol("StaticCredentialsProvider")
val borrow = symbol("borrow", "auth.credentials.internal")
val manage = symbol("manage", "auth.credentials.internal", isExtension = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,13 @@ class AwsServiceConfigIntegration : KotlinIntegration {

propertyType = ConfigPropertyType.Custom(render = { prop, writer ->
writer.write(
"public val #1L: #2T = builder.#1L?.borrow() ?: #3T(httpClientEngine = httpClientEngine, region = region)",
"public val #1L: #2T = builder.#1L ?: #3T(httpClientEngine = httpClientEngine, region = region).#4T()",
prop.propertyName,
prop.symbol,
AwsRuntimeTypes.Config.Credentials.DefaultChainCredentialsProvider,
AwsRuntimeTypes.Config.Credentials.manage,
)
})

additionalImports = listOf(
AwsRuntimeTypes.Config.Credentials.borrow,
AwsRuntimeTypes.Config.Credentials.DefaultChainCredentialsProvider,
)
}

// FIXME - should fips and dual stack props be defined on one of our AWS SDK client config interfaces (e.g. `AwsSdkConfig`) if they apply to every AWS SDK Kotlin service client generated?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ open class AwsHttpProtocolClientGenerator(
super.render(writer)
}

override fun renderInit(writer: KotlinWriter) {
writer.withBlock("init {", "}") {
write("managedResources.#T(config.httpClientEngine)", RuntimeTypes.IO.addIfManaged)
write("managedResources.#T(config.credentialsProvider)", RuntimeTypes.IO.addIfManaged)
}
}

override fun renderOperationSetup(writer: KotlinWriter, opIndex: OperationIndex, op: OperationShape) {
super.renderOperationSetup(writer, opIndex, op)

Expand Down Expand Up @@ -85,14 +92,4 @@ open class AwsHttpProtocolClientGenerator(
}
}
}

override fun renderClose(writer: KotlinWriter) {
writer.addImport(RuntimeTypes.IO.Closeable)
writer.write("")
.openBlock("override fun close() {")
.write("client.close()")
.write("(config.credentialsProvider as? #T)?.close()", RuntimeTypes.IO.Closeable)
.closeBlock("}")
.write("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AwsServiceConfigIntegrationTest {

val expectedProps = """
override val region: String = requireNotNull(builder.region) { "region is a required configuration property" }
public val credentialsProvider: CredentialsProvider = builder.credentialsProvider?.borrow() ?: DefaultChainCredentialsProvider(httpClientEngine = httpClientEngine, region = region)
public val credentialsProvider: CredentialsProvider = builder.credentialsProvider ?: DefaultChainCredentialsProvider(httpClientEngine = httpClientEngine, region = region).manage()
"""
contents.shouldContainOnlyOnceWithDiff(expectedProps)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,14 @@ class PresignerGeneratorTest {
public companion object {
public inline operator fun invoke(block: Builder.() -> kotlin.Unit): TestPresignConfig = Builder().apply(block).build()
}
public fun toBuilder(): Builder = Builder().apply {
credentialsProvider = [email protected]
endpointProvider = [email protected]
region = [email protected]
signer = [email protected]
}
public class Builder {
/**
* The AWS credentials provider to use for authenticating requests. If not provided a [aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider] instance will be used.
Expand Down

0 comments on commit b8a764d

Please sign in to comment.