Skip to content

Commit

Permalink
Add declarative endpoints traits
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFossAWS committed Sep 29, 2023
1 parent 2d062d0 commit b56906f
Show file tree
Hide file tree
Showing 32 changed files with 1,223 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rulesengine.aws.language.functions.endpoints;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.AnnotationTrait;

/**
* An endpoints modifier trait that indicates that a service has only dual stack endpoints,
* does not support IPV4 only endpoints, and should not have the useDualStackEndpoint endpoint parameter.
*/
public class DualStackOnlyEndpointsTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.endpoints#dualStackOnlyEndpoints");

public DualStackOnlyEndpointsTrait(ObjectNode node) {
super(ID, node);
}

public DualStackOnlyEndpointsTrait() {
this(Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<DualStackOnlyEndpointsTrait> {
public Provider() {
super(ID, DualStackOnlyEndpointsTrait::new);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rulesengine.aws.language.functions.endpoints;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.AnnotationTrait;

/**
* meta-trait that marks a trait as an endpoint modifier.
*
* Traits that are marked with this trait are applied to service shapes or operation shapes to
* indicate how a client can resolve endpoints for that service or operation.
*/
public class EndpointModifierTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.endpoints#endpointsModifier");

public EndpointModifierTrait(ObjectNode node) {
super(ID, node);
}

public EndpointModifierTrait() {
this(Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<EndpointModifierTrait> {
public Provider() {
super(ID, EndpointModifierTrait::new);
}
}
}
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.rulesengine.aws.language.functions.endpoints;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.StringNode;

/**
* The pattern type to use for the partition endpoint.
*/
public enum EndpointPatternType {

SERVICE_DNSSUFFIX("service_dnsSuffix"),
SERVICE_REGION_DNSSUFFI("service_region_dnsSuffix");

private final String name;

EndpointPatternType(String name) {
this.name = name;
}

public String getName() {
return name;
}

public static EndpointPatternType fromNode(Node node) {
StringNode value = node.expectStringNode();
for (EndpointPatternType type: EndpointPatternType.values()) {
if (type.name.equals(value.getValue())) {
return type;
}
}
throw new RuntimeException(String.format(
"Unable to find EndpointPatternType enum with value [%s]", value.getValue()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rulesengine.aws.language.functions.endpoints;

import java.util.Objects;
import software.amazon.smithy.model.FromSourceLocation;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.ToNode;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.ToSmithyBuilder;

/**
* A special case that do not follow the services standard patterns
* or are located in a region other than the partition's defaultGlobalRegion.
*/
public final class PartitionEndpointSpecialCase
implements FromSourceLocation, ToNode, ToSmithyBuilder<PartitionEndpointSpecialCase> {

private static final String ENDPOINT = "endpoint";
private static final String REGION = "region";
private static final String DUAL_STACK = "dualStack";
private static final String FIPS = "fips";
private final String endpoint;
private final String region;
private final Boolean dualStack;
private final Boolean fips;
private final SourceLocation sourceLocation;

private PartitionEndpointSpecialCase(Builder builder) {
this.endpoint = builder.endpoint;
this.region = builder.region;
this.dualStack = builder.dualStack;
this.fips = builder.fips;
this.sourceLocation = Objects.requireNonNull(builder.sourceLocation);
}

@Override
public Node toNode() {
return Node.objectNodeBuilder()
.withMember(ENDPOINT, endpoint)
.withMember(REGION, region)
.withMember(DUAL_STACK, dualStack.toString())
.withMember(FIPS, fips.toString())
.build();
}

@Override
public SmithyBuilder<PartitionEndpointSpecialCase> toBuilder() {
return new Builder()
.endpoint(endpoint)
.region(region)
.dualStack(dualStack)
.fips(fips)
.sourceLocation(sourceLocation);
}

@Override
public SourceLocation getSourceLocation() {
return FromSourceLocation.super.getSourceLocation();
}

public static PartitionEndpointSpecialCase fromNode(Node node) {
ObjectNode objectNode = node.expectObjectNode();
return builder()
.sourceLocation(objectNode.getSourceLocation())
.endpoint(objectNode.expectStringMember(ENDPOINT).getValue())
.region(objectNode.expectStringMember(REGION).getValue())
.dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null))
.fips(objectNode.getBooleanMemberOrDefault(FIPS, null))
.build();
}

public static Builder builder() {
return new Builder();
}

public static final class Builder implements SmithyBuilder<PartitionEndpointSpecialCase> {
private String endpoint;
private String region;
private Boolean dualStack;
private Boolean fips;
private SourceLocation sourceLocation = SourceLocation.none();

@Override
public PartitionEndpointSpecialCase build() {
return new PartitionEndpointSpecialCase(this);
}

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

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

public Builder dualStack(Boolean dualStack) {
this.dualStack = dualStack;
return this;
}

public Builder fips(Boolean fips) {
this.fips = fips;
return this;
}

Builder sourceLocation(SourceLocation sourceLocation) {
this.sourceLocation = sourceLocation;
return this;
}

}

public String getEndpoint() {
return endpoint;
}

public Boolean getDualStack() {
return dualStack;
}

public Boolean getFips() {
return fips;
}

public String getRegion() {
return region;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rulesengine.aws.language.functions.endpoints;

import java.util.Objects;
import software.amazon.smithy.model.FromSourceLocation;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.ToNode;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.ToSmithyBuilder;

/**
* A special case where endpoints for a partition that do not follow the standard patterns.
*/
public final class PartitionSpecialCase implements FromSourceLocation, ToNode, ToSmithyBuilder<PartitionSpecialCase> {

private static final String ENDPOINT = "endpoint";
private static final String DUAL_STACK = "dualStack";
private static final String FIPS = "fips";
private final String endpoint;
private final Boolean dualStack;
private final Boolean fips;
private final SourceLocation sourceLocation;

private PartitionSpecialCase(Builder builder) {
this.endpoint = builder.endpoint;
this.dualStack = builder.dualStack;
this.fips = builder.fips;
this.sourceLocation = Objects.requireNonNull(builder.sourceLocation);
}

public String getEndpoint() {
return endpoint;
}

public Boolean getDualStack() {
return dualStack;
}

public Boolean getFips() {
return fips;
}

@Override
public Node toNode() {
return Node.objectNodeBuilder()
.withMember(ENDPOINT, endpoint)
.withMember(DUAL_STACK, dualStack.toString())
.withMember(FIPS, fips.toString())
.build();
}

@Override
public SmithyBuilder<PartitionSpecialCase> toBuilder() {
return new Builder()
.dualStack(dualStack)
.endpoint(endpoint)
.fips(fips)
.sourceLocation(sourceLocation);
}

@Override
public SourceLocation getSourceLocation() {
return FromSourceLocation.super.getSourceLocation();
}

public static PartitionSpecialCase fromNode(Node node) {
ObjectNode objectNode = node.expectObjectNode();
return builder()
.sourceLocation(objectNode.getSourceLocation())
.endpoint(objectNode.expectStringMember(ENDPOINT).getValue())
.dualStack(objectNode.getBooleanMemberOrDefault(DUAL_STACK, null))
.fips(objectNode.getBooleanMemberOrDefault(FIPS, null))
.build();
}

public static Builder builder() {
return new Builder();
}

public static final class Builder implements SmithyBuilder<PartitionSpecialCase> {
private String endpoint;
private Boolean dualStack;
private Boolean fips;
private SourceLocation sourceLocation = SourceLocation.none();

@Override
public PartitionSpecialCase build() {
return new PartitionSpecialCase(this);
}

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

public Builder dualStack(Boolean dualStack) {
this.dualStack = dualStack;
return this;
}

public Builder fips(Boolean fips) {
this.fips = fips;
return this;
}

Builder sourceLocation(SourceLocation sourceLocation) {
this.sourceLocation = sourceLocation;
return this;
}

}
}
Loading

0 comments on commit b56906f

Please sign in to comment.