Skip to content

Commit

Permalink
add extra event id subparts to ClientEndpointDiscovery
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Oct 23, 2023
1 parent 27f019e commit 7cbae1d
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
@SmithyInternalApi
public final class ClientEndpointDiscoveryValidator extends AbstractValidator {
private static final Set<String> VALID_INPUT_MEMBERS = SetUtils.of("Operation", "Identifiers");
private static final String MISSING_ERROR_DEFINITION = "MissingErrorDefinition";
private static final String UNBOUND_OPERATION = "UnboundOperation";
private static final String NO_OPERATIONS = "NoOperations";

@Override
public List<ValidationEvent> validate(Model model) {
Expand Down Expand Up @@ -73,7 +76,8 @@ public List<ValidationEvent> validate(Model model) {
private List<ValidationEvent> validateTrait(ServiceShape service, ClientEndpointDiscoveryTrait trait) {
if (!trait.getOptionalError().isPresent()) {
return ListUtils.of(danger(service, trait,
"Services SHOULD define an error which indicates an endpoint is invalid."));
"Services SHOULD define an error which indicates an endpoint is invalid.",
MISSING_ERROR_DEFINITION));
}
return Collections.emptyList();
}
Expand All @@ -86,8 +90,9 @@ private List<ValidationEvent> validateServices(
.filter(pair -> !pair.getKey().getAllOperations().contains(pair.getValue().getOperation()))
.map(pair -> error(pair.getKey(), String.format(
"The operation `%s` must be bound to the service `%s` to use it as the endpoint operation.",
pair.getValue().getOperation(), pair.getKey()
)))
pair.getValue().getOperation(), pair.getKey()),
UNBOUND_OPERATION, pair.getValue().getOperation().getName()
))
.collect(Collectors.toList());

validationEvents.addAll(endpointDiscoveryServices.keySet().stream()
Expand All @@ -96,8 +101,9 @@ private List<ValidationEvent> validateServices(
"The service `%s` is configured to use endpoint discovery, but has no operations bound with "
+ "the `%s` trait.",
service.getId().toString(),
ClientDiscoveredEndpointTrait.ID.toString()
)))
ClientDiscoveredEndpointTrait.ID.toString()),
NO_OPERATIONS
))
.collect(Collectors.toList()));
return validationEvents;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[DANGER] ns.foo#FooService: Services SHOULD define an error which indicates an endpoint is invalid. | ClientEndpointDiscovery
[DANGER] ns.foo#FooService: Services SHOULD define an error which indicates an endpoint is invalid. | ClientEndpointDiscovery.MissingErrorDefinition
[ERROR] ns.foo#GetObject: The operation `ns.foo#GetObject` is marked with `aws.api#clientDiscoveredEndpoint` and is bound to the service `ns.foo#BarService` but does not have the required error `ns.foo#InvalidEndpointError`. | ClientEndpointDiscovery
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[WARNING] ns.foo#BazService: The service `ns.foo#BazService` is configured to use endpoint discovery, but has no operations bound with the `aws.api#clientDiscoveredEndpoint` trait. | ClientEndpointDiscovery.NoOperations
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
$version: "2.0"

namespace ns.foo

use aws.api#clientEndpointDiscovery
use aws.api#clientDiscoveredEndpoint

@clientEndpointDiscovery(
operation: DescribeEndpoints,
error: InvalidEndpointError,
)
service BazService {
version: "2021-06-29",
operations: [DescribeEndpoints, GetObjectWithEndpointError],
}

operation DescribeEndpoints {
input: DescribeEndpointsInput,
output: DescribeEndpointsOutput,
}

@input
structure DescribeEndpointsInput {
Operation: String,
Identifiers: Identifiers,
}

map Identifiers {
key: String,
value: String,
}

@output
structure DescribeEndpointsOutput {
Endpoints: Endpoints,
}

list Endpoints {
member: Endpoint,
}

structure Endpoint {
Address: String,
CachePeriodInMinutes: Long,
}

operation GetObjectWithEndpointError {
input: GetObjectWithEndpointErrorInput,
output: GetObjectWithEndpointErrorOutput,
errors: [InvalidEndpointError],
}

@input
structure GetObjectWithEndpointErrorInput {
@required
Id: String,
}

@output
structure GetObjectWithEndpointErrorOutput {
Object: Blob,
}

@error("client")
@httpError(421)
structure InvalidEndpointError {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ERROR] ns.foo#GetObject: The operation `ns.foo#GetObject` is marked with `aws.api#clientDiscoveredEndpoint` and is bound to the service `ns.foo#BarService` but does not have the required error `ns.foo#InvalidEndpointError`. | ClientEndpointDiscovery
[ERROR] ns.foo#BarService: The operation `ns.foo#DescribeEndpoints` must be bound to the service `(service: `ns.foo#BarService`)` to use it as the endpoint operation. | ClientEndpointDiscovery.UnboundOperation.DescribeEndpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
$version: "2.0"

namespace ns.foo

use aws.api#clientEndpointDiscovery
use aws.api#clientDiscoveredEndpoint

// This DOES have an error, but it's not bound to the operations. This should
// result in an ERROR.
@clientEndpointDiscovery(
operation: DescribeEndpoints,
error: InvalidEndpointError,
)
service BarService {
version: "2021-06-29",
operations: [GetObject],
}

// This DOES have an error, and it IS bound to the operations. This should
// not produce any validation events.
@clientEndpointDiscovery(
operation: DescribeEndpoints,
error: InvalidEndpointError,
)
service BazService {
version: "2021-06-29",
operations: [DescribeEndpoints, GetObjectWithEndpointError],
}

operation DescribeEndpoints {
input: DescribeEndpointsInput,
output: DescribeEndpointsOutput,
}

@input
structure DescribeEndpointsInput {
Operation: String,
Identifiers: Identifiers,
}

map Identifiers {
key: String,
value: String,
}

@output
structure DescribeEndpointsOutput {
Endpoints: Endpoints,
}

list Endpoints {
member: Endpoint,
}

structure Endpoint {
Address: String,
CachePeriodInMinutes: Long,
}

@clientDiscoveredEndpoint(required: true)
operation GetObject {
input: GetObjectInput,
output: GetObjectOutput,
}

@input
structure GetObjectInput {
@required
Id: String,
}

@output
structure GetObjectOutput {
Object: Blob,
}

@clientDiscoveredEndpoint(required: true)
operation GetObjectWithEndpointError {
input: GetObjectWithEndpointErrorInput,
output: GetObjectWithEndpointErrorOutput,
errors: [InvalidEndpointError],
}

@input
structure GetObjectWithEndpointErrorInput {
@required
Id: String,
}

@output
structure GetObjectWithEndpointErrorOutput {
Object: Blob,
}

@error("client")
@httpError(421)
structure InvalidEndpointError {}

0 comments on commit 7cbae1d

Please sign in to comment.