Skip to content

Commit e2107d7

Browse files
committed
AWS & S3 vendor params support
1 parent 578350b commit e2107d7

File tree

6 files changed

+179
-53
lines changed

6 files changed

+179
-53
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package aws.sdk.kotlin.codegen.smoketests
2+
3+
import aws.sdk.kotlin.codegen.AwsRuntimeTypes
4+
import software.amazon.smithy.kotlin.codegen.KotlinSettings
5+
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
6+
import software.amazon.smithy.kotlin.codegen.core.getContextValue
7+
import software.amazon.smithy.kotlin.codegen.core.withBlock
8+
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
9+
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding
10+
import software.amazon.smithy.kotlin.codegen.model.hasTrait
11+
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.*
12+
import software.amazon.smithy.kotlin.codegen.utils.topDownOperations
13+
import software.amazon.smithy.model.Model
14+
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
15+
16+
/**
17+
* Adds support for AWS specific client config during smoke tests code generation.
18+
*/
19+
class SmokeTestAwsVendorParamsIntegration : KotlinIntegration {
20+
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
21+
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() }
22+
23+
override val sectionWriters: List<SectionWriterBinding>
24+
get() =
25+
dualStackSectionWriters +
26+
sigv4aRegionSetSectionWriters +
27+
uriSectionWriters +
28+
accountIdEndpointSectionWriters +
29+
regionSectionWriters +
30+
useAccelerateSectionWriters +
31+
useMultiRegionAccessPointsSectionWriters +
32+
useGlobalEndpointSectionWriters
33+
}
34+
35+
/**
36+
* Uses the AWS Kotlin SDK specific name for the dual stack config option i.e. `useDualstack` -> `useDualStack`
37+
*/
38+
private val dualStackSectionWriters = listOf(
39+
SectionWriterBinding(SmokeTestUseDualStackKey) { writer, _ -> writer.writeInline("useDualStack") },
40+
)
41+
42+
/**
43+
* Uses the AWS Kotlin SDK specific name for the sigV4a signing region set option i.e.
44+
* `sigv4aRegionSet` -> `sigV4aSigningRegionSet`.
45+
*
46+
* Converts the modeled sigV4a signing region set from a list to a set.
47+
*
48+
* Adds additional config needed for the SDK to make sigV4a calls
49+
*/
50+
private val sigv4aRegionSetSectionWriters = listOf(
51+
SectionWriterBinding(SmokeTestSigv4aRegionSetKey) { writer, _ -> writer.writeInline("sigV4aSigningRegionSet") },
52+
SectionWriterBinding(SmokeTestSigv4aRegionSetValue) { writer, value ->
53+
writer.write("#L.toSet()", value)
54+
// TODO: Remove once sigV4a is supported for default signer.
55+
writer.write(
56+
"authSchemes = listOf(#T(#T))",
57+
RuntimeTypes.Auth.HttpAuthAws.SigV4AsymmetricAuthScheme,
58+
RuntimeTypes.Auth.AwsSigningCrt.CrtAwsSigner,
59+
)
60+
},
61+
)
62+
63+
/**
64+
* Ensures we use the provided URI
65+
*/
66+
private val uriSectionWriters = listOf(
67+
SectionWriterBinding(SmokeTestUriKey) { writer, _ -> writer.writeInline("endpointProvider") },
68+
SectionWriterBinding(SmokeTestUriValue) { writer, value ->
69+
val endpointProvider = writer.getContextValue(SmokeTestUriValue.EndpointProvider)
70+
val endpointParameters = writer.getContextValue(SmokeTestUriValue.EndpointParameters)
71+
writer.withBlock("object : #T {", "}", endpointProvider) {
72+
write(
73+
"override suspend fun resolveEndpoint(params: #T): #T = #T(#L)",
74+
endpointParameters,
75+
RuntimeTypes.SmithyClient.Endpoints.Endpoint,
76+
RuntimeTypes.SmithyClient.Endpoints.Endpoint,
77+
value,
78+
)
79+
}
80+
},
81+
)
82+
83+
/**
84+
* Uses the AWS Kotlin SDK specific way of configuring `accountIdEndpointMode`
85+
*/
86+
private val accountIdEndpointSectionWriters = listOf(
87+
SectionWriterBinding(SmokeTestAccountIdBasedRoutingKey) { writer, _ -> writer.writeInline("accountIdEndpointMode") },
88+
SectionWriterBinding(SmokeTestAccountIdBasedRoutingValue) { writer, value ->
89+
when (value) {
90+
"true" -> writer.write("#T.REQUIRED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode)
91+
"false" -> writer.write("#T.DISABLED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode)
92+
}
93+
},
94+
)
95+
96+
/**
97+
* Gets region override environment variable.
98+
*
99+
* Sets region override as default.
100+
*
101+
* Sets region override as default client config if no other client config is modelled.
102+
*/
103+
private val regionSectionWriters = listOf(
104+
SectionWriterBinding(SmokeTestAdditionalEnvVars) { writer, _ ->
105+
writer.write(
106+
"private val regionOverride = #T.System.getenv(#S)",
107+
RuntimeTypes.Core.Utils.PlatformProvider,
108+
"AWS_SMOKE_TEST_REGION",
109+
)
110+
},
111+
SectionWriterBinding(SmokeTestRegionDefault) { writer, _ ->
112+
writer.writeInline("regionOverride ?: ")
113+
},
114+
SectionWriterBinding(SmokeTestDefaultConfig) { writer, _ -> writer.write("region = regionOverride") },
115+
)
116+
117+
/**
118+
* Uses the AWS Kotlin SDK specific name for the S3 accelerate config option i.e. `useAccelerate` -> `enableAccelerate`
119+
*/
120+
private val useAccelerateSectionWriters = listOf(
121+
SectionWriterBinding(SmokeTestUseAccelerateKey) { writer, _ -> writer.writeInline("enableAccelerate") },
122+
)
123+
124+
/**
125+
* Uses the AWS Kotlin SDK specific name for the S3 multi region access points (MRAP) config option i.e.
126+
* `useMultiRegionAccessPoints` -> `disableMrap`.
127+
*
128+
* Our config option is opt out while the modeled config is opt in so we invert the boolean values.
129+
*/
130+
private val useMultiRegionAccessPointsSectionWriters = listOf(
131+
SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsKey) { writer, _ -> writer.writeInline("disableMrap") },
132+
SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsValue) { writer, value ->
133+
when (value) {
134+
"true" -> writer.write("false")
135+
"false" -> writer.write("true")
136+
}
137+
},
138+
)
139+
140+
/**
141+
* Leaves a comment in the client config whenever the use of the `useGlobalEndpoint` S3 config option is modeled.
142+
*
143+
* The SDK does not support this config option.
144+
* See `BindAwsEndpointBuiltins` & `S3_USE_GLOBAL_ENDPOINT`
145+
*/
146+
private val useGlobalEndpointSectionWriters = listOf(
147+
SectionWriterBinding(SmokeTestUseGlobalEndpoint) { writer, _ ->
148+
writer.write("// Smoke tests modeled the use of `useGlobalEndpoint` config, but it's not supported by the SDK")
149+
},
150+
)

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt

Lines changed: 0 additions & 45 deletions
This file was deleted.

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SmokeTestsDenyListIntegration : KotlinIntegration {
2222
)
2323

2424
private val smokeTestDenyListSectionWriter = SectionWriter { writer, _ ->
25-
writer.write("// Smoke tests for service deny listed until model is fixed")
25+
writer.write("// Smoke tests for service deny listed")
2626
}
2727
}
2828

codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration
4444
aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration
4545
aws.sdk.kotlin.codegen.BusinessMetricsIntegration
4646
aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration
47-
aws.sdk.kotlin.codegen.smoketests.SmokeTestsCodegenRegionIntegration
47+
aws.sdk.kotlin.codegen.smoketests.SmokeTestAwsVendorParamsIntegration
4848
aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestSuccessHttpEngineIntegration
4949
aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestFailHttpEngineIntegration

tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ service FailureService {
4141
vendorParamsShape: AwsVendorParams,
4242
vendorParams: {
4343
region: "eu-central-1"
44+
uri: "https://failure.amazonaws.com"
45+
useFips: false
46+
useDualstack: false
4447
}
4548
}
4649
]
@@ -57,6 +60,12 @@ operation TestOperation {
5760
@error("client")
5861
structure InvalidMessageError {}
5962

60-
structure AwsVendorParams {
61-
region: String
62-
}
63+
@mixin
64+
structure BaseAwsVendorParams {
65+
region: String = "us-west-2"
66+
uri: String
67+
useFips: Boolean = false
68+
useDualstack: Boolean = false
69+
}
70+
71+
structure AwsVendorParams with [BaseAwsVendorParams] {}

tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ service SuccessService {
4141
vendorParamsShape: AwsVendorParams,
4242
vendorParams: {
4343
region: "eu-central-1"
44+
uri: "https://success.amazonaws.com"
45+
useFips: false
46+
useDualstack: false
4447
}
4548
},
4649
{
@@ -55,6 +58,9 @@ service SuccessService {
5558
vendorParamsShape: AwsVendorParams,
5659
vendorParams: {
5760
region: "eu-central-1"
61+
uri: "https://success.amazonaws.com"
62+
useFips: false
63+
useDualstack: false
5864
}
5965
}
6066
]
@@ -71,6 +77,12 @@ operation TestOperation {
7177
@error("client")
7278
structure InvalidMessageError {}
7379

74-
structure AwsVendorParams {
75-
region: String
76-
}
80+
@mixin
81+
structure BaseAwsVendorParams {
82+
region: String = "us-west-2"
83+
uri: String
84+
useFips: Boolean = false
85+
useDualstack: Boolean = false
86+
}
87+
88+
structure AwsVendorParams with [BaseAwsVendorParams] {}

0 commit comments

Comments
 (0)