Skip to content

Commit

Permalink
Fix s3 control by adding transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Dec 14, 2022
1 parent 819c5e2 commit 7536a50
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import software.amazon.smithy.rustsdk.customize.ec2.Ec2Decorator
import software.amazon.smithy.rustsdk.customize.glacier.GlacierDecorator
import software.amazon.smithy.rustsdk.customize.route53.Route53Decorator
import software.amazon.smithy.rustsdk.customize.s3.S3Decorator
import software.amazon.smithy.rustsdk.customize.s3control.S3ControlDecorator
import software.amazon.smithy.rustsdk.customize.sts.STSDecorator

val DECORATORS = listOf(
Expand Down Expand Up @@ -45,6 +46,7 @@ val DECORATORS = listOf(
GlacierDecorator(),
Route53Decorator(),
S3Decorator(),
S3ControlDecorator(),
STSDecorator(),

// Only build docs-rs for linux to reduce load on docs.rs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rustsdk.customize.s3control

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.EndpointTrait
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext

class S3ControlDecorator : RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext> {
override val name: String = "S3Control"
override val order: Byte = 0
override fun supportsCodegenContext(clazz: Class<out CodegenContext>): Boolean {
return clazz.isAssignableFrom(ClientCodegenContext::class.java)
}

private fun applies(service: ServiceShape) =
service.id == ShapeId.from("com.amazonaws.s3control#AWSS3ControlServiceV20180820")

override fun transformModel(service: ServiceShape, model: Model): Model {
if (!applies(service)) {
return model
}
return ModelTransformer.create()
.removeTraitsIf(model) { _, trait ->
trait is EndpointTrait && trait.hostPrefix.labels.any {
it.isLabel && it.content == "AccountId"
}
}
}
}
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-client/src/test_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub struct ValidateRequest {
impl ValidateRequest {
pub fn assert_matches(&self, ignore_headers: &[HeaderName]) {
let (actual, expected) = (&self.actual, &self.expected);
assert_eq!(actual.uri(), expected.uri());
for (name, value) in expected.headers() {
if !ignore_headers.contains(name) {
let actual_header = actual
Expand Down Expand Up @@ -146,7 +147,6 @@ impl ValidateRequest {
(Ok(actual), Ok(expected)) => assert_ok(validate_body(actual, expected, media_type)),
_ => assert_eq!(actual.body().bytes(), expected.body().bytes()),
};
assert_eq!(actual.uri(), expected.uri());
}
}

Expand Down

0 comments on commit 7536a50

Please sign in to comment.