Skip to content

Commit

Permalink
Update endpoint rules engine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kstich committed Sep 29, 2023
1 parent 27878c2 commit 64316e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 339 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
smithyVersion=1.37.0
smithyVersion=1.39.0
smithyGradleVersion=0.6.0
355 changes: 21 additions & 334 deletions smithy-typescript-codegen-test/model/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -467,342 +467,29 @@ structure Message {
@protocolDefinition
structure fakeProtocol {}

apply Weather @smithy.rules#endpointRuleSet( {
"version": "1.0",
"parameters": {
apply Weather @smithy.rules#endpointRuleSet({
"version": "1.3",
"parameters": {
"Region": {
"builtIn": "AWS::Region",
"required": false,
"documentation": "The AWS region used to dispatch the request.",
"type": "String"
},
"UseDualStack": {
"builtIn": "AWS::UseDualStack",
"required": true,
"default": false,
"documentation": "When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.",
"type": "Boolean"
},
"UseFIPS": {
"builtIn": "AWS::UseFIPS",
"required": true,
"default": false,
"documentation": "When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.",
"type": "Boolean"
},
"Endpoint": {
"builtIn": "SDK::Endpoint",
"required": false,
"documentation": "Override the endpoint used to send this request",
"type": "String"
"required": true,
"type": "String",
"documentation": "docs"
}
},
"rules": [
},
"rules": [
{
"conditions": [
{
"fn": "isSet",
"argv": [
{
"ref": "Endpoint"
}
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseFIPS"
},
true
]
}
],
"error": "Invalid Configuration: FIPS and custom endpoint are not supported",
"type": "error"
},
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseDualStack"
},
true
]
}
],
"error": "Invalid Configuration: Dualstack and custom endpoint are not supported",
"type": "error"
},
{
"conditions": [],
"endpoint": {
"url": {
"ref": "Endpoint"
},
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
},
{
"conditions": [
{
"fn": "isSet",
"argv": [
{
"ref": "Region"
}
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "aws.partition",
"argv": [
{
"ref": "Region"
}
],
"assign": "PartitionResult"
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseFIPS"
},
true
]
},
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseDualStack"
},
true
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
true,
{
"fn": "getAttr",
"argv": [
{
"ref": "PartitionResult"
},
"supportsFIPS"
]
}
]
},
{
"fn": "booleanEquals",
"argv": [
true,
{
"fn": "getAttr",
"argv": [
{
"ref": "PartitionResult"
},
"supportsDualStack"
]
}
]
}
],
"type": "tree",
"rules": [
{
"conditions": [],
"endpoint": {
"url": "https://weather-fips.{Region}.{PartitionResult#dualStackDnsSuffix}",
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
},
{
"conditions": [],
"error": "FIPS and DualStack are enabled, but this partition does not support one or both",
"type": "error"
}
]
},
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseFIPS"
},
true
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
true,
{
"fn": "getAttr",
"argv": [
{
"ref": "PartitionResult"
},
"supportsFIPS"
]
}
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "stringEquals",
"argv": [
"aws-us-gov",
{
"fn": "getAttr",
"argv": [
{
"ref": "PartitionResult"
},
"name"
]
}
]
}
],
"endpoint": {
"url": "https://weather.{Region}.amazonaws.com",
"properties": {},
"headers": {}
},
"type": "endpoint"
},
{
"conditions": [],
"endpoint": {
"url": "https://weather-fips.{Region}.{PartitionResult#dnsSuffix}",
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
},
{
"conditions": [],
"error": "FIPS is enabled but this partition does not support FIPS",
"type": "error"
}
]
},
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
{
"ref": "UseDualStack"
},
true
]
}
],
"type": "tree",
"rules": [
{
"conditions": [
{
"fn": "booleanEquals",
"argv": [
true,
{
"fn": "getAttr",
"argv": [
{
"ref": "PartitionResult"
},
"supportsDualStack"
]
}
]
}
],
"type": "tree",
"rules": [
{
"conditions": [],
"endpoint": {
"url": "https://weather.{Region}.{PartitionResult#dualStackDnsSuffix}",
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
},
{
"conditions": [],
"error": "DualStack is enabled but this partition does not support DualStack",
"type": "error"
}
]
},
{
"conditions": [],
"endpoint": {
"url": "https://weather.{Region}.{PartitionResult#dnsSuffix}",
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
}
]
},
{
"conditions": [],
"error": "Invalid Configuration: Missing Region",
"type": "error"
"conditions": [],
"documentation": "base rule",
"endpoint": {
"url": "https://{Region}.amazonaws.com",
"properties": {},
"headers": {}
},
"type": "endpoint"
}
]
]
})

apply Weather @smithy.rules#clientContextParams(
Region: {type: "string", documentation: "docs"}
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ public void containsExtraContextParameter() {
assertThat(endpointParameters, containsString(
" return {\n" +
" ...options,\n" +
" region: options.region ?? \"us-east-1\",\n" +
" stage: options.stage ?? \"production\",\n" +
" defaultSigningName: \"\",\n" +
" }\n"));
assertThat(endpointParameters, containsString(
"export interface ClientInputEndpointParameters {\n" +
" region?: string|Provider<string>;\n" +
" stage?: string|Provider<string>;\n" +
" endpoint?:"));
}

private MockManifest testEndpoints(String filename) {
Expand Down
Loading

0 comments on commit 64316e7

Please sign in to comment.