diff --git a/.changelog/account-id-endpoint-built-ins.md b/.changelog/account-id-endpoint-built-ins.md new file mode 100644 index 0000000000000000000000000000000000000000..855b4755ea790087e6d383314cb3929f278ef95b --- /dev/null +++ b/.changelog/account-id-endpoint-built-ins.md @@ -0,0 +1,10 @@ +--- +applies_to: ["aws-sdk-rust"] +authors: ["landonxjames"] +references: ["smithy-rs#3792"] +breaking: false +new_feature: false +bug_fix: false +--- + +Add minimal support for `AWS::Auth::AccountId` and `AWS::Auth::AccountIdEndpointMode` endpoint built-ins diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt index b2407859b516a630fc11128cf0c0b9349181782c..c23e2a6b86ca79e640aee45b4fd3c895d3ebb700 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecorator.kt @@ -127,11 +127,14 @@ fun Model.sdkConfigSetter( /** * Create a client codegen decorator that creates bindings for a builtIn parameter. Optionally, you can provide - * [clientParam.Builder] which allows control over the config parameter that will be generated. + * [clientParam.Builder] which allows control over the config parameter that will be generated. You can also opt + * to exclude including the extra sections that set the builtIn value on the SdkConfig. This is useful for builtIns + * that are only minimally supported, like accountId and accountIdEndpointMode. */ fun decoratorForBuiltIn( builtIn: Parameter, clientParamBuilder: ConfigParam.Builder? = null, + includeSdkConfigSetter: Boolean = true, ): ClientCodegenDecorator { val nameOverride = clientParamBuilder?.name val name = nameOverride ?: builtIn.name.rustName() @@ -143,9 +146,17 @@ fun decoratorForBuiltIn( codegenContext.getBuiltIn(builtIn) != null override fun extraSections(codegenContext: ClientCodegenContext): List { - return listOfNotNull( - codegenContext.model.sdkConfigSetter(codegenContext.serviceShape.id, builtIn, clientParamBuilder?.name), - ) + if (includeSdkConfigSetter) { + return listOfNotNull( + codegenContext.model.sdkConfigSetter( + codegenContext.serviceShape.id, + builtIn, + clientParamBuilder?.name, + ), + ) + } else { + return listOf() + } } override fun configCustomizations( @@ -236,4 +247,6 @@ val PromotedBuiltInsDecorators = .type(RuntimeType.String.toSymbol()) .setterDocs(endpointUrlDocs), ), + decoratorForBuiltIn(AwsBuiltIns.ACCOUNT_ID_ENDPOINT_MODE, null, false), + decoratorForBuiltIn(AwsBuiltIns.ACCOUNT_ID, null, false), ).toTypedArray() diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/OperationInputTestGenerator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/OperationInputTestGenerator.kt index 5bcc870ae5bcf1d833e90d7b6de136ace1611543..489aef1d4efc0232c72a011268ce62ed600f6bb6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/OperationInputTestGenerator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/OperationInputTestGenerator.kt @@ -132,6 +132,7 @@ class OperationInputTestGenerator(_ctx: ClientCodegenContext, private val test: tokioTest(safeName("operation_input_test_$operationName")) { rustTemplate( """ + /* documentation: ${test.documentation.orElse("No docs :(")} */ /* builtIns: ${escape(Node.prettyPrintJson(testOperationInput.builtInParams))} */ /* clientParams: ${escape(Node.prettyPrintJson(testOperationInput.clientParams))} */ let (http_client, rcvr) = #{capture_request}(None); @@ -211,6 +212,10 @@ class OperationInputTestGenerator(_ctx: ClientCodegenContext, private val test: Logger.getLogger("OperationTestGenerator").warning("No provider for ${builtIn.value}") } } + // If the test contains Endpoint built-ins and does not contain an AWS::Region then we set one + if (!operationInput.builtInParams.isEmpty && !operationInput.builtInParams.containsMember("AWS::Region")) { + rust("let builder = builder.region(::aws_types::region::Region::new(\"us-east-1\"));") + } rust("builder.build()") } } diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecoratorTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecoratorTest.kt index c5dd5581600f3e07c7a32f9406d703a2ebeb7d9b..61e83179194b4cb16560678560ad44925d417a58 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecoratorTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecoratorTest.kt @@ -21,23 +21,38 @@ class EndpointBuiltInsDecoratorTest { use aws.auth#sigv4 use aws.protocols#restJson1 use smithy.rules#endpointRuleSet + use smithy.rules#staticContextParams @service(sdkId: "dontcare") @restJson1 @sigv4(name: "dontcare") @auth([sigv4]) + @suppress(["RuleSetAwsBuiltIn.AWS::Auth::AccountId", "RuleSetAwsBuiltIn.AWS::Auth::AccountIdEndpointMode"]) @endpointRuleSet({ "version": "1.0" "parameters": { "endpoint": { "required": false, "type": "string", "builtIn": "SDK::Endpoint" }, "region": { "required": false, "type": "String", "builtIn": "AWS::Region" }, + "accountId": { "required": false, "type": "String", "builtIn": "AWS::Auth::AccountId" }, + "accountIdEndpointMode": { "required": false, "type": "String", "builtIn": "AWS::Auth::AccountIdEndpointMode" }, } "rules": [ { "type": "endpoint" "conditions": [ {"fn": "isSet", "argv": [{"ref": "endpoint"}]}, - {"fn": "isSet", "argv": [{"ref": "region"}]} + {"fn": "isSet", "argv": [{"ref": "region"}]}, + { + "fn": "not", + "argv": [ + { + "fn": "isSet", + "argv": [ + {"ref": "accountId"} + ] + } + ] + } ], "endpoint": { "url": "{endpoint}" @@ -72,6 +87,11 @@ class EndpointBuiltInsDecoratorTest { @http(uri: "/SomeOperation", method: "GET") @optionalAuth + @staticContextParams( + accountIdEndpointMode: { + value: "some value" + } + ) operation SomeOperation { output: SomeOutput }