Skip to content

Commit 3e03cb8

Browse files
committed
Extract AWS built-ins and auth validation
This commit updates the endpoint rule set SPI to provide several components to the implementation, built-in parameters and auth scheme validators in addition to library functions. AWS specific components have been extracted to their own package, and core components are provided through their own extension.
1 parent 2386d15 commit 3e03cb8

File tree

55 files changed

+848
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+848
-475
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rulesengine.aws.language.functions;
7+
8+
import software.amazon.smithy.rulesengine.language.evaluation.value.Value;
9+
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter;
10+
import software.amazon.smithy.rulesengine.language.syntax.parameters.ParameterType;
11+
12+
/**
13+
* AWS-specific built-in parameters for EndpointRules.
14+
*/
15+
public final class AwsBuiltIns {
16+
/**
17+
* Built-in parameter representing the DualStack parameter for SDKs.
18+
*/
19+
public static final Parameter DUALSTACK =
20+
Parameter.builder()
21+
.name("UseDualStack")
22+
.type(ParameterType.BOOLEAN)
23+
.builtIn("AWS::UseDualStack")
24+
.documentation("When true, use the dual-stack endpoint. If the configured endpoint does not "
25+
+ "support dual-stack, dispatching the request MAY return an error.")
26+
.required(true)
27+
.defaultValue(Value.booleanValue(false))
28+
.build();
29+
30+
/**
31+
* Built-in parameter representing whether the endpoint must be FIPS-compliant.
32+
*/
33+
public static final Parameter FIPS =
34+
Parameter.builder()
35+
.name("UseFIPS")
36+
.type(ParameterType.BOOLEAN)
37+
.builtIn("AWS::UseFIPS")
38+
.documentation("When true, send this request to the FIPS-compliant regional endpoint. If the "
39+
+ "configured endpoint does not have a FIPS compliant endpoint, dispatching "
40+
+ "the request will return an error.")
41+
.required(true)
42+
.defaultValue(Value.booleanValue(false))
43+
.build();
44+
45+
/**
46+
* Built-in parameter representing Region eg. `us-east-1`.
47+
*/
48+
public static final Parameter REGION =
49+
Parameter.builder()
50+
.name("Region")
51+
.type(ParameterType.STRING)
52+
.builtIn("AWS::Region")
53+
.documentation("The AWS region used to dispatch the request.")
54+
.build();
55+
56+
/**
57+
* This MUST only be used by the S3 rules.
58+
*/
59+
public static final Parameter S3_ACCELERATE =
60+
Parameter.builder()
61+
.type(ParameterType.BOOLEAN)
62+
.name("Accelerate")
63+
.builtIn("AWS::S3::Accelerate")
64+
.required(true)
65+
.defaultValue(Value.booleanValue(false))
66+
.documentation("When true, use S3 Accelerate. NOTE: Not all regions support S3 accelerate.")
67+
.build();
68+
69+
/**
70+
* This MUST only be used by the S3 rules.
71+
*/
72+
public static final Parameter S3_DISABLE_MRAP =
73+
Parameter.builder()
74+
.type(ParameterType.BOOLEAN)
75+
.name("DisableMultiRegionAccessPoints")
76+
.builtIn("AWS::S3::DisableMultiRegionAccessPoints")
77+
.required(true)
78+
.defaultValue(Value.booleanValue(false))
79+
.documentation("Whether multi-region access points (MRAP) should be disabled.")
80+
.build();
81+
82+
/**
83+
* This MUST only be used by the S3 rules.
84+
*/
85+
public static final Parameter S3_FORCE_PATH_STYLE =
86+
Parameter.builder()
87+
.type(ParameterType.BOOLEAN)
88+
.name("ForcePathStyle")
89+
.builtIn("AWS::S3::ForcePathStyle")
90+
.documentation("When true, force a path-style endpoint to be used where the bucket name is part "
91+
+ "of the path.")
92+
.build();
93+
94+
/**
95+
* This MUST only be used by the S3 rules.
96+
*/
97+
public static final Parameter S3_USE_ARN_REGION =
98+
Parameter.builder()
99+
.type(ParameterType.BOOLEAN)
100+
.name("UseArnRegion")
101+
.builtIn("AWS::S3::UseArnRegion")
102+
.documentation("When an Access Point ARN is provided and this flag is enabled, the SDK MUST use "
103+
+ "the ARN's region when constructing the endpoint instead of the client's "
104+
+ "configured region.")
105+
.build();
106+
107+
/**
108+
* This MUST only be used by the S3 rules.
109+
*/
110+
public static final Parameter S3_USE_GLOBAL_ENDPOINT =
111+
Parameter.builder()
112+
.type(ParameterType.BOOLEAN)
113+
.name("UseGlobalEndpoint")
114+
.builtIn("AWS::S3::UseGlobalEndpoint")
115+
.required(true)
116+
.defaultValue(Value.booleanValue(false))
117+
.documentation("Whether the global endpoint should be used, rather then "
118+
+ "the regional endpoint for us-east-1.")
119+
.build();
120+
121+
/**
122+
* This MUST only be used by the S3Control rules.
123+
*/
124+
public static final Parameter S3_CONTROL_USE_ARN_REGION =
125+
Parameter.builder()
126+
.type(ParameterType.BOOLEAN)
127+
.name("UseArnRegion")
128+
.builtIn("AWS::S3Control::UseArnRegion")
129+
.documentation("When an Access Point ARN is provided and this flag is enabled, the SDK MUST use "
130+
+ "the ARN's region when constructing the endpoint instead of the client's "
131+
+ "configured region.")
132+
.build();
133+
134+
/**
135+
* This MUST only be used by the STS rules.
136+
*/
137+
public static final Parameter STS_USE_GLOBAL_ENDPOINT =
138+
Parameter.builder()
139+
.type(ParameterType.BOOLEAN)
140+
.name("UseGlobalEndpoint")
141+
.builtIn("AWS::STS::UseGlobalEndpoint")
142+
.required(true)
143+
.defaultValue(Value.booleanValue(false))
144+
.documentation("Whether the global endpoint should be used, rather then "
145+
+ "the regional endpoint for us-east-1.")
146+
.build();
147+
148+
private AwsBuiltIns() {}
149+
}

smithy-aws-rules-engine/src/main/java/software/amazon/smithy/rulesengine/aws/language/functions/AwsPartition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ private AwsPartition(FunctionNode functionNode) {
4848
super(DEFINITION, functionNode);
4949
}
5050

51+
/**
52+
* Gets the {@link FunctionDefinition} implementation.
53+
*
54+
* @return the function definition.
55+
*/
56+
public static Definition getDefinition() {
57+
return DEFINITION;
58+
}
59+
5160
@Override
5261
public <T> T accept(ExpressionVisitor<T> visitor) {
5362
return visitor.visitLibraryFunction(DEFINITION, getArguments());
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rulesengine.aws.language.functions;
7+
8+
import java.util.List;
9+
import software.amazon.smithy.rulesengine.language.EndpointRuleSetExtension;
10+
import software.amazon.smithy.rulesengine.language.syntax.expressions.functions.FunctionDefinition;
11+
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter;
12+
import software.amazon.smithy.rulesengine.validators.AuthSchemeValidator;
13+
import software.amazon.smithy.utils.ListUtils;
14+
15+
/**
16+
* AWS-specific extensions to smithy-rules-engine.
17+
*/
18+
public final class AwsRuleSetExtension implements EndpointRuleSetExtension {
19+
@Override
20+
public List<Parameter> getBuiltIns() {
21+
return ListUtils.of(
22+
AwsBuiltIns.DUALSTACK,
23+
AwsBuiltIns.FIPS,
24+
AwsBuiltIns.REGION,
25+
AwsBuiltIns.S3_ACCELERATE,
26+
AwsBuiltIns.S3_DISABLE_MRAP,
27+
AwsBuiltIns.S3_FORCE_PATH_STYLE,
28+
AwsBuiltIns.S3_USE_ARN_REGION,
29+
AwsBuiltIns.S3_USE_GLOBAL_ENDPOINT,
30+
AwsBuiltIns.S3_CONTROL_USE_ARN_REGION,
31+
AwsBuiltIns.STS_USE_GLOBAL_ENDPOINT);
32+
}
33+
34+
@Override
35+
public List<FunctionDefinition> getLibraryFunctions() {
36+
return ListUtils.of(
37+
AwsPartition.getDefinition(),
38+
IsVirtualHostableS3Bucket.getDefinition(),
39+
ParseArn.getDefinition());
40+
}
41+
42+
@Override
43+
public List<AuthSchemeValidator> getAuthSchemeValidators() {
44+
return ListUtils.of(
45+
new EndpointAuthUtils.SigV4SchemeValidator(),
46+
new EndpointAuthUtils.SigV4aSchemeValidator(),
47+
new EndpointAuthUtils.BetaSchemeValidator());
48+
}
49+
}

0 commit comments

Comments
 (0)