Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd committed Nov 16, 2023
1 parent aeb854e commit bd9c411
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .changes/873fb1ab-bfbb-4110-89cd-bf7ac352bc86.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "873fb1ab-bfbb-4110-89cd-bf7ac352bc86",
"type": "feature",
"description": "⚠️ **IMPORTANT**: Enable account ID based endpoint routing for services that use it",
"description": "⚠️ **IMPORTANT**: Enable account ID based endpoint routing for services that support it",
"requiresMinorVersionBump": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ internal enum class ArnResourceTypeSeparator(public val separator: String) {
;

public companion object {
public fun fromValue(value: String): ArnResourceTypeSeparator = when (value) {
"/" -> SLASH
":" -> COLON
else -> error("unknown ARN resource type separator `$value`, expected one of ${values().map { it.separator }}")
}
public fun fromValue(value: String): ArnResourceTypeSeparator =
checkNotNull(entries.find { it.separator == value }) {
"unknown ARN resource type separator `$value`, expected one of ${entries.map { it.separator }}"
}
}
}

Expand Down Expand Up @@ -186,14 +185,8 @@ internal class ArnResource(
}
}

override fun toString(): String = buildString {
if (type != null) {
append("$type")
append(resourceTypeSeparator.separator)
}

append(id)
}
override fun toString(): String =
listOfNotNull(type, id).joinToString(resourceTypeSeparator.separator)

override fun hashCode(): Int {
var result = id.hashCode()
Expand All @@ -205,6 +198,7 @@ internal class ArnResource(
if (this === other) return true
if (other !is ArnResource) return false
if (id != other.id) return false
if (resourceTypeSeparator != other.resourceTypeSeparator) return false
return type == other.type
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ package aws.sdk.kotlin.runtime.config.endpoints
*/
public enum class AccountIdEndpointMode {
/**
* Endpoint parameters are populated on a best effort basis. This is the default when not
* explicitly set.
* Endpoint parameters are populated on a best effort basis.
*/
PREFERRED,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class ArnTest {
},
)

tests.forEach { test ->
val parsed = Arn.parse(test.first)
assertEquals(test.second, parsed)
tests.forEach { (arnString, arnExpected) ->
val parsed = Arn.parse(arnString)
assertEquals(arnExpected, parsed)
// test round trip
assertEquals(test.first, parsed.toString())
assertEquals(arnString, parsed.toString())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import aws.smithy.kotlin.runtime.time.TimestampFormat
import aws.smithy.kotlin.runtime.util.TestPlatformProvider
import io.kotest.matchers.string.shouldContain
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand All @@ -44,9 +46,9 @@ class EcsCredentialsProviderTest {
)

private fun ecsResponse(accountId: String? = null): HttpResponse {
val kvp = buildMap {
val payload = buildJsonObject {
put("Code", "Success")
put("LastUpdated", "2021-09-17T20to57to08Z")
put("LastUpdated", "2021-09-17T20:57:08Z")
put("Type", "AWS-HMAC")
put("AccessKeyId", "AKID")
put("SecretAccessKey", "test-secret")
Expand All @@ -55,11 +57,7 @@ class EcsCredentialsProviderTest {
if (accountId != null) {
put("AccountId", accountId)
}
}

val payload = kvp.entries.joinToString(prefix = "{", postfix = "}", separator = ",") {
"\"${it.key}\":\"${it.value}\""
}.encodeToByteArray()
}.toString().encodeToByteArray()

return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(payload))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package aws.sdk.kotlin.codegen.customization

import aws.sdk.kotlin.codegen.AwsRuntimeTypes
import aws.sdk.kotlin.codegen.protocols.endpoints.AwsBuiltins
import software.amazon.smithy.kotlin.codegen.KotlinSettings
import software.amazon.smithy.kotlin.codegen.core.CodegenContext
import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter
Expand All @@ -28,15 +29,16 @@ class AccountIdEndpointBuiltinCustomization : KotlinIntegration {
name = "accountIdEndpointMode"
symbol = AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode
documentation = """
Control the way account ID is bound to the endpoint resolver parameters.
Control the way account ID is bound to the endpoint resolver parameters.
Defaults to [AccountIdEndpointMode.PREFERRED].
""".trimIndent()
propertyType = ConfigPropertyType.RequiredWithDefault("AccountIdEndpointMode.PREFERRED")
}
}

override fun enabledForService(model: Model, settings: KotlinSettings): Boolean {
val rules = model.expectShape<ServiceShape>(settings.service).getEndpointRules()
return rules?.parameters?.find { it.isBuiltIn && it.builtIn.get() == "AWS::Auth::AccountId" } != null
return rules?.parameters?.find { it.isBuiltIn && it.builtIn.get() == AwsBuiltins.ACCOUNT_ID } != null
}

override val sectionWriters: List<SectionWriterBinding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ fun renderBindAwsBuiltins(ctx: ProtocolGenerator.GenerationContext, writer: Kotl
) {
builtinParams.forEach {
when (it.builtIn.get()) {
"AWS::Region" -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.RegionProp.propertyName)
"AWS::UseFIPS" -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseFipsProp.propertyName)
"AWS::UseDualStack" -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseDualStackProp.propertyName)
AwsBuiltins.REGION -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.RegionProp.propertyName)
AwsBuiltins.USE_FIPS -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseFipsProp.propertyName)
AwsBuiltins.USE_DUAL_STACK -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseDualStackProp.propertyName)

"AWS::S3::Accelerate" -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.EnableAccelerateProp.propertyName)
"AWS::S3::ForcePathStyle" -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.ForcePathStyleProp.propertyName)
"AWS::S3::DisableMultiRegionAccessPoints" -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.DisableMrapProp.propertyName)
"AWS::S3::UseArnRegion" -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.UseArnRegionProp.propertyName)
"AWS::S3Control::UseArnRegion" -> renderBasicConfigBinding(writer, it, S3ControlClientConfigIntegration.UseArnRegionProp.propertyName)
AwsBuiltins.S3_ACCELERATE -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.EnableAccelerateProp.propertyName)
AwsBuiltins.S3_FORCE_PATH_STYLE -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.ForcePathStyleProp.propertyName)
AwsBuiltins.S3_DISABLE_MRAP -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.DisableMrapProp.propertyName)
AwsBuiltins.S3_USE_ARN_REGION -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.UseArnRegionProp.propertyName)
AwsBuiltins.S3_CONTROL_USE_ARN_REGION -> renderBasicConfigBinding(writer, it, S3ControlClientConfigIntegration.UseArnRegionProp.propertyName)

"SDK::Endpoint" ->
AwsBuiltins.SDK_ENDPOINT ->
writer.write("#L = config.#L?.toString()", it.defaultName(), AwsServiceConfigIntegration.EndpointUrlProp.propertyName)

// as a newer SDK we do NOT support these values, they are always false
"AWS::S3::UseGlobalEndpoint", "AWS::STS::UseGlobalEndpoint" ->
AwsBuiltins.S3_USE_GLOBAL_ENDPOINT, AwsBuiltins.STS_USE_GLOBAL_ENDPOINT ->
writer.write("#L = false", it.defaultName())

"AWS::Auth::AccountId" ->
AwsBuiltins.ACCOUNT_ID ->
writer.write(
"#L = #T(config.#L, request.identity.attributes)",
it.defaultName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.codegen.protocols.endpoints

object AwsBuiltins {
const val ACCOUNT_ID = "AWS::Auth::AccountId"
const val REGION = "AWS::Region"
const val USE_FIPS = "AWS::UseFIPS"
const val USE_DUAL_STACK = "AWS::UseDualStack"
const val SDK_ENDPOINT = "SDK::Endpoint"
const val S3_ACCELERATE = "AWS::S3::Accelerate"
const val S3_FORCE_PATH_STYLE = "AWS::S3::ForcePathStyle"
const val S3_DISABLE_MRAP = "AWS::S3::DisableMultiRegionAccessPoints"
const val S3_USE_ARN_REGION = "AWS::S3::UseArnRegion"
const val S3_CONTROL_USE_ARN_REGION = "AWS::S3Control::UseArnRegion"
const val S3_USE_GLOBAL_ENDPOINT = "AWS::S3::UseGlobalEndpoint"
const val STS_USE_GLOBAL_ENDPOINT = "AWS::STS::UseGlobalEndpoint"
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ coroutines-version = "1.7.3"
atomicfu-version = "0.22.0"

# smithy-kotlin codegen and runtime are versioned separately
smithy-kotlin-runtime-version = "0.29.0-SNAPSHOT"
smithy-kotlin-codegen-version = "0.29.0-SNAPSHOT"
smithy-kotlin-runtime-version = "0.28.3-SNAPSHOT"
smithy-kotlin-codegen-version = "0.28.3-SNAPSHOT"

# codegen
smithy-version = "1.41.0"
Expand Down

0 comments on commit bd9c411

Please sign in to comment.