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

Adds endpoint resolver helpers #1066

Merged
merged 4 commits into from
Jan 23, 2021
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ public class AddAwsConfigFields implements GoIntegration {
.build()
);

/**
* Gets the sort order of the customization from -128 to 127, with lowest
* executed first.
*
* @return Returns the sort order, defaults to -50.
*/
@Override
public byte getOrder() {
return -50;
}

private static Symbol getAwsCoreSymbol(String symbolName) {
return SymbolUtils.createValueSymbolBuilder(symbolName,
AwsGoDependency.AWS_CORE).build();
Expand All @@ -139,6 +128,17 @@ private static Symbol getAwsRetrySymbol(String symbolName) {
AwsGoDependency.AWS_RETRY).build();
}

/**
* Gets the sort order of the customization from -128 to 127, with lowest
* executed first.
*
* @return Returns the sort order, defaults to -50.
*/
@Override
public byte getOrder() {
return -50;
}

@Override
public void writeAdditionalFiles(
GoSettings settings,
Expand Down Expand Up @@ -178,7 +178,8 @@ private void writeHttpClientResolver(GoWriter writer) {
writer.openBlock("func $L(o *Options) {", "}", RESOLVE_HTTP_CLIENT, () -> {
writer.openBlock("if o.$L != nil {", "}", HTTP_CLIENT_CONFIG_NAME, () -> writer.write("return"));
writer.write("o.$L = $T()", HTTP_CLIENT_CONFIG_NAME,
SymbolUtils.createValueSymbolBuilder("NewBuildableClient", AwsGoDependency.AWS_HTTP_TRANSPORT).build());
SymbolUtils.createValueSymbolBuilder("NewBuildableClient",
AwsGoDependency.AWS_HTTP_TRANSPORT).build());
});
writer.write("");
}
Expand Down Expand Up @@ -305,6 +306,14 @@ private Builder() {
super();
}

/**
* This sets the Config field on Client Options structure. By default this is true.
* If set to false, this field won't be generated on the Client options, but will be used by
* the NewFromConfig (to copy values from the aws config to client options).
*
* @param generatedOnClient bool indicating config field generation on client option structure
* @return
*/
public Builder generatedOnClient(boolean generatedOnClient) {
this.generatedOnClient = generatedOnClient;
return this;
Expand Down Expand Up @@ -347,6 +356,18 @@ public Builder documentation(String documentation) {
super.documentation(documentation);
return this;
}

@Override
public Builder withHelper(Boolean withHelper) {
super.withHelper(withHelper);
return this;
}

@Override
public Builder withHelper() {
super.withHelper();
return this;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Generates an endpoint resolver from endpoints.json.
*/
public final class AwsEndpointGenerator implements GoIntegration {
public static final String ENDPOINT_RESOLVER_CONFIG_NAME = "EndpointResolver";

@Override
public void writeAdditionalFiles(
Expand All @@ -49,10 +50,11 @@ public List<RuntimeClientPlugin> getClientPlugins() {
return ListUtils.of(RuntimeClientPlugin.builder()
.configFields(SetUtils.of(
ConfigField.builder()
.name("EndpointResolver")
.name(ENDPOINT_RESOLVER_CONFIG_NAME)
.type(SymbolUtils.createValueSymbolBuilder(EndpointGenerator.RESOLVER_INTERFACE_NAME)
.build())
.documentation("The service endpoint resolver.")
.withHelper(true)
.build(),
ConfigField.builder()
.name("EndpointOptions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ protected static GoDependency module(
}

private static final class Versions {
private static final String AWS_SDK = "v0.31.1-0.20210108204630-4822f3195720";
private static final String AWS_SDK = "v1.0.1-0.20210122214637-6cf9ad2f8e2f";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class EndpointGenerator implements Runnable {
public static final String CLIENT_CONFIG_RESOLVER = "resolveDefaultEndpointConfiguration";
public static final String RESOLVER_CONSTRUCTOR_NAME = "NewDefaultEndpointResolver";
public static final String AWS_ENDPOINT_RESOLVER_HELPER = "withEndpointResolver";
private static final String EndpointResolverFromURL = "EndpointResolverFromURL";
private static final String ENDPOINT_SOURCE_CUSTOM = "EndpointSourceCustom";
private static final Symbol AWS_ENDPOINT = SymbolUtils.createPointableSymbolBuilder(
"Endpoint", AwsGoDependency.AWS_CORE).build();

private static final int ENDPOINT_MODEL_VERSION = 3;
private static final String INTERNAL_ENDPOINT_PACKAGE = "internal/endpoints";
Expand Down Expand Up @@ -369,6 +373,28 @@ private void generatePublicResolverTypes(GoWriter writer) {
writer.openBlock("if o.EndpointResolver != nil {", "}", () -> writer.write("return"));
writer.write("o.EndpointResolver = $L()", RESOLVER_CONSTRUCTOR_NAME);
});

// Generate EndpointResolverFromURL helper
writer.writeDocs(String.format("%s returns an EndpointResolver configured using the provided endpoint url. "
+ "By default, the resolved endpoint resolver uses the client region as signing region, and "
+ "the endpoint source is set to EndpointSourceCustom."
+ "You can provide functional options to configure endpoint values for the resolved endpoint.",
EndpointResolverFromURL));
writer.openBlock("func $L(url string, optFns ...func($P)) EndpointResolver {", "}",
EndpointResolverFromURL, AWS_ENDPOINT, () -> {
Symbol customEndpointSource = SymbolUtils.createValueSymbolBuilder(
ENDPOINT_SOURCE_CUSTOM, AwsGoDependency.AWS_CORE
).build();
writer.write("e := $T{ URL : url, Source : $T }", AWS_ENDPOINT, customEndpointSource);
writer.write("for _, fn := range optFns { fn(&e) }");
writer.write("");

writer.openBlock("return $T(", ")", resolverFuncSymbol, () -> {
writer.write("func(region string, options $L) ($T, error) {", RESOLVER_OPTIONS, AWS_ENDPOINT);
writer.write("if len(e.SigningRegion) == 0 { e.SigningRegion = region }");
writer.write("return e, nil },");
});
});
}

private void writeExternalResolveEndpointImplementation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ private AwsCustomGoDependency() {
}

private static final class Versions {
private static final String INTERNAL_S3SHARED = "v0.4.1-0.20210108204630-4822f3195720";
private static final String INTERNAL_ACCEPTENCODING = "v0.4.1-0.20210108204630-4822f3195720";
private static final String INTERNAL_PRESIGNURL = "v0.2.1-0.20210108204630-4822f3195720";
private static final String INTERNAL_S3SHARED = "v1.0.0";
private static final String INTERNAL_ACCEPTENCODING = "v1.0.0";
private static final String INTERNAL_PRESIGNURL = "v1.0.0";
}
}
3 changes: 1 addition & 2 deletions config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ module github.com/aws/aws-sdk-go-v2/config
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/credentials v1.0.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0
github.com/aws/smithy-go v1.0.0
github.com/google/go-cmp v0.5.4
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0
)

replace (
Expand Down
3 changes: 1 addition & 2 deletions credentials/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module github.com/aws/aws-sdk-go-v2/credentials
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0
github.com/aws/smithy-go v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0
)

replace (
Expand Down
7 changes: 0 additions & 7 deletions example/service/s3/listObjects/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ go 1.15
require (
github.com/aws/aws-sdk-go-v2/config v1.0.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2/credentials v1.0.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.0
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0
)

replace github.com/aws/aws-sdk-go-v2/config => ../../../../config/
Expand Down
2 changes: 0 additions & 2 deletions example/service/s3/listObjects/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e h1:CBuNt8z4Dh3Vf1q5BgoJgAidIDS585A/f/gpaGO45yk=
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
3 changes: 1 addition & 2 deletions feature/dynamodb/attributevalue/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.0.0
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.0.0
github.com/google/go-cmp v0.5.4
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0
)

replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/
Expand Down
2 changes: 0 additions & 2 deletions feature/dynamodb/attributevalue/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e h1:CBuNt8z4Dh3Vf1q5BgoJgAidIDS585A/f/gpaGO45yk=
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
4 changes: 1 addition & 3 deletions feature/dynamodb/expression/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ module github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.0.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.0.0
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0
)

replace (
Expand Down
2 changes: 0 additions & 2 deletions feature/dynamodb/expression/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e h1:CBuNt8z4Dh3Vf1q5BgoJgAidIDS585A/f/gpaGO45yk=
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
3 changes: 1 addition & 2 deletions feature/dynamodbstreams/attributevalue/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module github.com/aws/aws-sdk-go-v2/feature/dynamodbstreams/attributevalue
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.0.0
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.0.0
github.com/google/go-cmp v0.5.4
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0
)

replace github.com/aws/aws-sdk-go-v2/service/dynamodb => ../../../service/dynamodb/
Expand Down
2 changes: 0 additions & 2 deletions feature/dynamodbstreams/attributevalue/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e h1:CBuNt8z4Dh3Vf1q5BgoJgAidIDS585A/f/gpaGO45yk=
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
8 changes: 1 addition & 7 deletions feature/s3/manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ module github.com/aws/aws-sdk-go-v2/feature/s3/manager
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/aws-sdk-go-v2/config v1.0.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0
github.com/aws/smithy-go v1.0.0
github.com/google/go-cmp v0.5.4
github.com/aws/aws-sdk-go-v2/credentials v1.0.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.0
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0
)

replace github.com/aws/aws-sdk-go-v2 => ../../../
Expand Down
2 changes: 0 additions & 2 deletions feature/s3/manager/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e h1:CBuNt8z4Dh3Vf1q5BgoJgAidIDS585A/f/gpaGO45yk=
github.com/aws/smithy-go v0.5.1-0.20210115041537-09631dea532e/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
8 changes: 8 additions & 0 deletions internal/protocoltest/awsrestjson/api_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions internal/protocoltest/awsrestjson/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/protocoltest/awsrestjson/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/smithy-go v1.0.0
github.com/google/go-cmp v0.5.4
)
Expand Down
8 changes: 8 additions & 0 deletions internal/protocoltest/ec2query/api_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions internal/protocoltest/ec2query/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/protocoltest/ec2query/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2 v1.0.1-0.20210122214637-6cf9ad2f8e2f
github.com/aws/smithy-go v1.0.0
github.com/google/go-cmp v0.5.4
)
Expand Down
Loading