Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImplicitGlobalRegion to Partition Output #1921

Merged
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
3 changes: 3 additions & 0 deletions docs/source-2.0/aws/rules-engine/library-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ properties:
* - supportsDualStack
- ``bool``
- Indicates whether the partition supports dual-stack endpoints.
* - implicitGlobalRegion
- ``string``
- The region used by partitional (non-regionalized/global) services for signing.


.. _rules-engine-aws-library-awsParseArn:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class AwsPartition extends LibraryFunction {
public static final Identifier DUAL_STACK_DNS_SUFFIX = Identifier.of("dualStackDnsSuffix");
public static final Identifier SUPPORTS_FIPS = Identifier.of("supportsFIPS");
public static final Identifier SUPPORTS_DUAL_STACK = Identifier.of("supportsDualStack");
public static final Identifier IMPLICIT_GLOBAL_REGION = Identifier.of("implicitGlobalRegion");
public static final Identifier INFERRED = Identifier.of("inferred");

private static final Definition DEFINITION = new Definition();
Expand Down Expand Up @@ -95,6 +96,7 @@ private Definition() {
type.put(DUAL_STACK_DNS_SUFFIX, Type.stringType());
type.put(SUPPORTS_DUAL_STACK, Type.booleanType());
type.put(SUPPORTS_FIPS, Type.booleanType());
type.put(IMPLICIT_GLOBAL_REGION, Type.stringType());
returnType = Type.optionalType(Type.recordType(type));
}

Expand Down Expand Up @@ -154,7 +156,8 @@ public Value evaluate(List<Value> arguments) {
DUAL_STACK_DNS_SUFFIX, Value.stringValue(matchedPartitionOutputs.getDualStackDnsSuffix()),
SUPPORTS_FIPS, Value.booleanValue(matchedPartitionOutputs.supportsFips()),
SUPPORTS_DUAL_STACK, Value.booleanValue(matchedPartitionOutputs.supportsDualStack()),
INFERRED, Value.booleanValue(inferred)));
INFERRED, Value.booleanValue(inferred),
IMPLICIT_GLOBAL_REGION, Value.stringValue(matchedPartitionOutputs.getImplicitGlobalRegion())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ public final class PartitionOutputs implements ToSmithyBuilder<PartitionOutputs>
private static final String DUAL_STACK_DNS_SUFFIX = "dualStackDnsSuffix";
private static final String SUPPORTS_FIPS = "supportsFIPS";
private static final String SUPPORTS_DUAL_STACK = "supportsDualStack";
private static final String IMPLICIT_GLOBAL_REGION = "implicitGlobalRegion";
private static final List<String> PROPERTIES = ListUtils.of(NAME, DNS_SUFFIX, DUAL_STACK_DNS_SUFFIX,
SUPPORTS_FIPS, SUPPORTS_DUAL_STACK);
SUPPORTS_FIPS, SUPPORTS_DUAL_STACK, IMPLICIT_GLOBAL_REGION);

private final String name;
private final String dnsSuffix;
private final String dualStackDnsSuffix;
private final boolean supportsFips;
private final boolean supportsDualStack;
private final String implicitGlobalRegion;
private final SourceLocation sourceLocation;

private PartitionOutputs(Builder builder) {
Expand All @@ -46,6 +48,7 @@ private PartitionOutputs(Builder builder) {
dualStackDnsSuffix = builder.dualStackDnsSuffix;
supportsFips = builder.supportsFips;
supportsDualStack = builder.supportsDualStack;
implicitGlobalRegion = builder.implicitGlobalRegion;
}

/**
Expand Down Expand Up @@ -73,6 +76,7 @@ public static PartitionOutputs fromNode(Node node) {
objectNode.getStringMember(DUAL_STACK_DNS_SUFFIX, builder::dualStackDnsSuffix);
objectNode.getBooleanMember(SUPPORTS_FIPS, builder::supportsFips);
objectNode.getBooleanMember(SUPPORTS_DUAL_STACK, builder::supportsDualStack);
objectNode.getStringMember(IMPLICIT_GLOBAL_REGION, builder::implicitGlobalRegion);

return builder.build();
}
Expand Down Expand Up @@ -122,6 +126,16 @@ public boolean supportsDualStack() {
return supportsDualStack;
}

/**
* Gets this partition's implicit global region: the region that
* non-regionalized (global) services should use for signing.
*
* @return returns the partition's implicit global region.
*/
public String getImplicitGlobalRegion() {
return implicitGlobalRegion;
}

@Override
public SourceLocation getSourceLocation() {
return sourceLocation;
Expand All @@ -134,7 +148,8 @@ public SmithyBuilder<PartitionOutputs> toBuilder() {
.dnsSuffix(dnsSuffix)
.dualStackDnsSuffix(dualStackDnsSuffix)
.supportsFips(supportsFips)
.supportsDualStack(supportsDualStack);
.supportsDualStack(supportsDualStack)
.implicitGlobalRegion(implicitGlobalRegion);
}

@Override
Expand All @@ -143,7 +158,8 @@ public Node toNode() {
.withMember(DNS_SUFFIX, dnsSuffix)
.withMember(DUAL_STACK_DNS_SUFFIX, dualStackDnsSuffix)
.withMember(SUPPORTS_FIPS, supportsFips)
.withMember(SUPPORTS_DUAL_STACK, supportsDualStack);
.withMember(SUPPORTS_DUAL_STACK, supportsDualStack)
.withMember(IMPLICIT_GLOBAL_REGION, implicitGlobalRegion);

if (name != null) {
builder.withMember(NAME, name);
Expand All @@ -163,12 +179,15 @@ public boolean equals(Object o) {
return supportsFips == partitionOutputs.supportsFips && supportsDualStack == partitionOutputs.supportsDualStack
&& Objects.equals(name, partitionOutputs.name)
&& Objects.equals(dnsSuffix, partitionOutputs.dnsSuffix)
&& Objects.equals(dualStackDnsSuffix, partitionOutputs.dualStackDnsSuffix);
&& Objects.equals(dualStackDnsSuffix, partitionOutputs.dualStackDnsSuffix)
&& Objects.equals(implicitGlobalRegion, partitionOutputs.implicitGlobalRegion);

}

@Override
public int hashCode() {
return Objects.hash(name, dnsSuffix, dualStackDnsSuffix, supportsFips, supportsDualStack);
return Objects.hash(name, dnsSuffix, dualStackDnsSuffix,
supportsFips, supportsDualStack, implicitGlobalRegion);
}

/**
Expand All @@ -180,6 +199,7 @@ public static class Builder extends RulesComponentBuilder<Builder, PartitionOutp
private String dualStackDnsSuffix;
private boolean supportsFips;
private boolean supportsDualStack;
private String implicitGlobalRegion;

public Builder(FromSourceLocation sourceLocation) {
super(sourceLocation);
Expand Down Expand Up @@ -210,6 +230,11 @@ public Builder supportsDualStack(boolean supportsDualStack) {
return this;
}

public Builder implicitGlobalRegion(String implicitGlobalRegion) {
this.implicitGlobalRegion = implicitGlobalRegion;
return this;
}

@Override
public PartitionOutputs build() {
return new PartitionOutputs(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
"supportsDualStack": true
"supportsDualStack": true,
"implicitGlobalRegion": "us-east-1"
}
},
{
Expand All @@ -51,7 +52,8 @@
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
"supportsDualStack": true
"supportsDualStack": true,
"implicitGlobalRegion": "us-gov-west-1"
}
},
{
Expand All @@ -67,7 +69,8 @@
"dnsSuffix": "amazonaws.com.cn",
"dualStackDnsSuffix": "api.amazonwebservices.com.cn",
"supportsFIPS": true,
"supportsDualStack": true
"supportsDualStack": true,
"implicitGlobalRegion": "cn-northwest-1"
}
},
{
Expand All @@ -78,7 +81,8 @@
"dnsSuffix": "c2s.ic.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "c2s.ic.gov"
"dualStackDnsSuffix": "c2s.ic.gov",
"implicitGlobalRegion": "us-iso-east-1"
},
"regions": {
"us-iso-east-1": {},
Expand All @@ -94,7 +98,8 @@
"dnsSuffix": "sc2s.sgov.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "sc2s.sgov.gov"
"dualStackDnsSuffix": "sc2s.sgov.gov",
"implicitGlobalRegion": "us-isob-east-1"
},
"regions": {
"us-isob-east-1": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void eval() {
assertThat(result.get(AwsPartition.DUAL_STACK_DNS_SUFFIX).expectStringValue().getValue(), not(equalTo("")));
assertThat(result.get(AwsPartition.SUPPORTS_FIPS).expectBooleanValue().getValue(), equalTo(true));
assertThat(result.get(AwsPartition.SUPPORTS_DUAL_STACK).expectBooleanValue().getValue(), equalTo(true));
assertThat(result.get(AwsPartition.IMPLICIT_GLOBAL_REGION).expectStringValue().getValue(), not(equalTo("")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void roundtripsPartitions() {
.dualStackDnsSuffix("api.aws")
.supportsFips(true)
.supportsDualStack(true)
.implicitGlobalRegion("us-east-1")
.build())
.build())
.addPartition(Partition.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
"supportsDualStack": true
"supportsDualStack": true,
"implicitGlobalRegion": "us-east-1"
}
},
{
Expand Down