Skip to content

Commit

Permalink
fallback to v2 instead of v1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahvita committed Jul 25, 2023
1 parent 8026d94 commit a13092d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,12 @@ private void writeAwsConfigEndpointResolver(GoWriter writer) {
writer.putContext("wrapperHelper", EndpointGenerator.AWS_ENDPOINT_RESOLVER_HELPER);
writer.putContext("awsResolver", ENDPOINT_RESOLVER_CONFIG_NAME);
writer.putContext("awsResolverWithOptions", AWS_ENDPOINT_RESOLVER_WITH_OPTIONS);
writer.putContext("newResolver", EndpointGenerator.RESOLVER_CONSTRUCTOR_NAME);
writer.write("""
func $resolverName:L(cfg aws.Config, o *Options) {
if cfg.$awsResolver:L == nil && cfg.$awsResolverWithOptions:L == nil {
return
}
o.$clientOption:L = $wrapperHelper:L(cfg.$awsResolver:L, cfg.$awsResolverWithOptions:L, $newResolver:L())
o.$clientOption:L = $wrapperHelper:L(cfg.$awsResolver:L, cfg.$awsResolverWithOptions:L)
}
""");
writer.popState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,33 +394,26 @@ private void generateAwsEndpointResolverWrapper(GoWriter writer) {
writer.write("""
type $T struct {
awsResolver $T
resolver $T
}
""", wrappedResolverSymbol, endpointResolverWithOptions, resolverInterface);
""", wrappedResolverSymbol, endpointResolverWithOptions);
var endpointNotFoundError = SymbolUtils.createValueSymbolBuilder("EndpointNotFoundError",
AwsGoDependency.AWS_CORE).build();

writeExternalResolveEndpointImplementation(writer, wrappedResolverSymbol, "w", () -> {
var endpointNotFoundError = SymbolUtils.createValueSymbolBuilder("EndpointNotFoundError",
AwsGoDependency.AWS_CORE).build();
var errorf = SymbolUtils.createValueSymbolBuilder("Errorf",
SmithyGoDependency.FMT).build();
writer.write("""
if w.awsResolver == nil {
goto fallback
}
endpoint, err = w.awsResolver.ResolveEndpoint(ServiceID, region, options)
if err == nil {
return endpoint, nil
}
if nf := (&$T{}); !errors.As(err, &nf) {
return endpoint, err
if nf := (&$T{}); errors.As(err, &nf) {
return endpoint, nil
}
fallback:
if w.resolver == nil {
return endpoint, $T("default endpoint resolver provided was nil")
}
return w.resolver.ResolveEndpoint(region, options)""", endpointNotFoundError, errorf);
return endpoint, err
""", endpointNotFoundError);

writer.addUseImports(SmithyGoDependency.ERRORS);
});
Expand All @@ -441,28 +434,30 @@ private void generateAwsEndpointResolverWrapper(GoWriter writer) {
// Generate exported helper for constructing a wrapper around the AWS EndpointResolver type that is compatible
// with the clients EndpointResolver interface.
writer.write("""
// $L returns an EndpointResolver that first delegates endpoint resolution to the awsResolver.
// If awsResolver returns aws.EndpointNotFoundError error, the resolver will use the the provided
// fallbackResolver for resolution.
// $1L returns an $3T that first delegates endpoint resolution to the awsResolver.
// If awsResolver returns $7T error, the resolver will swallow the error, such
// that fallback will occur when $8L is invoked via its middleware.
//
// fallbackResolver must not be nil
func $L(awsResolver $T, awsResolverWithOptions $T, fallbackResolver $T) $T {
var resolver $T
// If another error (besides $7T) is returned, then that error will be propagated.
func $1L(awsResolver $2T, awsResolverWithOptions $3T) $6L {
var resolver $3T
if awsResolverWithOptions != nil {
resolver = awsResolverWithOptions
} else if awsResolver != nil {
resolver = $L(awsResolver.ResolveEndpoint)
resolver = $4L(awsResolver.ResolveEndpoint)
}
return &$T{
return &$5T{
awsResolver: resolver,
resolver: fallbackResolver,
}
}
""", AWS_ENDPOINT_RESOLVER_HELPER, AWS_ENDPOINT_RESOLVER_HELPER,
endpointResolver, endpointResolverWithOptions, resolverInterface,
resolverInterface, endpointResolverWithOptions, AWS_ENDPOINT_RESOLVER_ADAPTOR, wrappedResolverSymbol);
""", AWS_ENDPOINT_RESOLVER_HELPER,
endpointResolver, endpointResolverWithOptions,
AWS_ENDPOINT_RESOLVER_ADAPTOR, wrappedResolverSymbol,
resolverInterface, endpointNotFoundError,
EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME
);
}

private void generateMiddleware(GoWriter writer) {
Expand Down

0 comments on commit a13092d

Please sign in to comment.