-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix s3 control by adding transformer
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3control/S3ControlDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters