Skip to content

Commit

Permalink
codegen endpoint resolver helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Jan 20, 2021
1 parent a55d57f commit 10bc32d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
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.0";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ 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 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 +372,24 @@ 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. "
+ "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, () -> {
writer.write("e := $T{ URL : url, }", AWS_ENDPOINT);
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";
}
}

0 comments on commit 10bc32d

Please sign in to comment.