Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions aws/client/aws-client-rulesengine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ description = "This module provides AWS-Specific client rules engine functionali
extra["displayName"] = "Smithy :: Java :: AWS :: Client :: Rules Engine"
extra["moduleName"] = "software.amazon.smithy.java.aws.client.rulesengine"

// Custom configuration for S3 model - kept separate from main classpath
val s3Model: Configuration by configurations.creating

dependencies {
api(project(":aws:client:aws-client-core"))
api(project(":client:client-rulesengine"))
Expand All @@ -17,9 +20,15 @@ dependencies {
testImplementation(project(":aws:client:aws-client-restxml"))
testImplementation(project(":aws:client:aws-client-restjson"))
testImplementation(project(":client:dynamic-client"))

s3Model("software.amazon.api.models:s3:1.0.12")
}

// Share the S3 model between JMH and tests.
// Add S3 model to test and JMH classpaths
configurations["testImplementation"].extendsFrom(s3Model)
configurations["jmhImplementation"].extendsFrom(s3Model)

// Share the S3 BDD trait between JMH and tests
sourceSets {
val sharedResources = "src/shared-resources"

Expand All @@ -34,9 +43,10 @@ sourceSets {

jmh {
warmupIterations = 3
iterations = 5
iterations = 3
fork = 1
profilers.add("async:output=flamegraph")
// profilers.add("async:output=flamegraph;dir=build/jmh-profiler")
// profilers.add("async:output=collapsed;dir=build/jmh-profiler")
// profilers.add("gc")
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE // don't dump a bunch of warnings.
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.HttpTrait;
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.model.transform.ModelTransformer;

@State(Scope.Benchmark)
Expand All @@ -49,7 +50,7 @@ public class Bench {
public void setup() {
model = Model.assembler()
.discoverModels()
.addImport(ResolverTest.class.getResource("s3.json"))
.addImport(ResolverTest.class.getResource("s3-bdd.smithy"))
.putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true)
.assemble()
.unwrap();
Expand Down Expand Up @@ -83,13 +84,18 @@ public void setup() {
.build();
}

// S3 requires a customization to remove buckets from the path :(
private static Model customizeS3Model(Model m) {
return ModelTransformer.create().mapShapes(m, s -> {
// S3 requires customizations
private static Model customizeS3Model(Model model) {
var transformer = ModelTransformer.create();

// Remove streaming trait - not yet supported
Model m = transformer.removeTraitsIf(model, (shape, trait) -> trait instanceof StreamingTrait);

// Remove buckets from the path
return transformer.mapShapes(m, s -> {
if (s.isOperationShape()) {
var httpTrait = s.getTrait(HttpTrait.class).orElse(null);
if (httpTrait != null && httpTrait.getUri().getLabel("Bucket").isPresent()) {
// Remove the bucket from the URI pattern.
var uriString = httpTrait.getUri().toString().replace("{Bucket}", "");
uriString = uriString.replace("//", "/");
var newUri = UriPattern.parse(uriString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import software.amazon.smithy.java.aws.client.core.settings.EndpointSettings;
import software.amazon.smithy.java.aws.client.core.settings.RegionSetting;
import software.amazon.smithy.java.aws.client.core.settings.S3EndpointSettings;
import software.amazon.smithy.java.aws.client.core.settings.StsEndpointSettings;
import software.amazon.smithy.java.client.rulesengine.RulesExtension;
import software.amazon.smithy.java.client.rulesengine.RulesFunction;
import software.amazon.smithy.java.context.Context;
Expand All @@ -25,6 +29,23 @@ public void putBuiltinProviders(Map<String, Function<Context, Object>> providers
providers.putAll(AwsRulesBuiltin.BUILTINS);
}

@Override
public void putBuiltinKeys(Map<String, Context.Key<?>> keys) {
// Direct key access for simple builtins (avoids Function call overhead)
keys.put("AWS::Region", RegionSetting.REGION);
keys.put("AWS::UseDualStack", EndpointSettings.USE_DUAL_STACK);
keys.put("AWS::UseFIPS", EndpointSettings.USE_FIPS);
keys.put("AWS::Auth::AccountIdEndpointMode", EndpointSettings.ACCOUNT_ID_ENDPOINT_MODE);
keys.put("AWS::S3::Accelerate", S3EndpointSettings.S3_ACCELERATE);
keys.put("AWS::S3::DisableMultiRegionAccessPoints", S3EndpointSettings.S3_DISABLE_MULTI_REGION_ACCESS_POINTS);
keys.put("AWS::S3::ForcePathStyle", S3EndpointSettings.S3_FORCE_PATH_STYLE);
keys.put("AWS::S3::UseArnRegion", S3EndpointSettings.S3_USE_ARN_REGION);
keys.put("AWS::S3::UseGlobalEndpoint", S3EndpointSettings.S3_USE_GLOBAL_ENDPOINT);
keys.put("AWS::S3Control::UseArnRegion", S3EndpointSettings.S3_CONTROL_USE_ARN_REGION);
keys.put("AWS::STS::UseGlobalEndpoint", StsEndpointSettings.STS_USE_GLOBAL_ENDPOINT);
// Note: AWS::Auth::AccountId has fallback logic, so it uses the provider
}

@Override
public Iterable<RulesFunction> getFunctions() {
return Arrays.asList(AwsRulesFunction.values());
Expand Down
Loading
Loading