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

CKFVS Fix #2452

Merged
merged 10 commits into from
Jan 16, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package software.amazon.smithy.aws.go.codegen.customization;

import java.util.List;
import java.util.ArrayList;
import software.amazon.smithy.aws.go.codegen.AddAwsConfigFields;
import software.amazon.smithy.aws.go.codegen.AwsGoDependency;
import software.amazon.smithy.aws.go.codegen.AwsSignatureVersion4;
import software.amazon.smithy.aws.go.codegen.AwsSignatureVersion4aUtils;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.aws.traits.auth.SigV4ATrait;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.GoDelegator;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.integration.ConfigField;
import software.amazon.smithy.go.codegen.integration.ConfigFieldResolver;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar;
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.traits.AuthTrait;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SetUtils;

/**
* This integration configures the CloudFront Key Value Store client for Signature Version 4a
*/
public class CloudFrontKVSSigV4a implements GoIntegration {
/**
* Return true if service is CFKVS.
*
* @param model is the generation model.
* @param service is the service shape being audited.
*/
private static boolean isCFKVSService(Model model, ServiceShape service) {
final String sdkId = service.expectTrait(ServiceTrait.class).getSdkId();
final String serviceId = sdkId.replace("-", "").replace(" ", "").toLowerCase();
return serviceId.equalsIgnoreCase("cloudfrontkeyvaluestore");
}

private final List<RuntimeClientPlugin> runtimeClientPlugins = new ArrayList<>();


@Override
public List<RuntimeClientPlugin> getClientPlugins() {
return runtimeClientPlugins;
}

@Override
public Model preprocessModel(Model model, GoSettings settings) {
ServiceShape service = settings.getService(model);
if (!isCFKVSService(model, service)) {
return model;
}

if (settings.getService(model).hasTrait(SigV4ATrait.class)) {
return model;
}

var v4a = SigV4ATrait.builder()
.name(service.expectTrait(SigV4Trait.class).getName())
.build();

return model.toBuilder()
.addShape(
service.toBuilder()
.addTrait(v4a)
// FUTURE: https://github.com/aws/smithy-go/issues/493
// we are keeping sigv4 at the end of this list (it will never be selected)
// as a stopgap to drive codegen of payload checksum routines
.addTrait(new AuthTrait(SetUtils.of(SigV4ATrait.ID, SigV4Trait.ID)))
.build()
)
.build();
}

@Override
public void processFinalizedModel(GoSettings settings, Model model) {
if (!isCFKVSService(model, settings.getService(model))) {
return;
}
runtimeClientPlugins.add(
RuntimeClientPlugin.builder()
.configFields(
ListUtils.of(
ConfigField.builder()
.name(AwsSignatureVersion4aUtils.V4A_SIGNER_INTERFACE_NAME)
.type(SymbolUtils.buildPackageSymbol(
AwsSignatureVersion4aUtils.V4A_SIGNER_INTERFACE_NAME)
)
.documentation("Signature Version 4a (SigV4a) Signer")
.build()
)
)
.build());
runtimeClientPlugins.add(
RuntimeClientPlugin.builder()
.servicePredicate(CloudFrontKVSSigV4a::isCFKVSService)
.addConfigFieldResolver(
ConfigFieldResolver.builder()
.location(ConfigFieldResolver.Location.CLIENT)
.target(ConfigFieldResolver.Target.INITIALIZATION)
.resolver(SymbolUtils.createValueSymbolBuilder(
AwsSignatureVersion4aUtils.SIGNER_RESOLVER).build())
.build())
.build());
}

@Override
public void writeAdditionalFiles(
GoSettings settings,
Model model,
SymbolProvider symbolProvider,
GoDelegator goDelegator
) {

if (!isCFKVSService(model, model.expectShape(settings.getService(), ServiceShape.class))) {
isaiahvita marked this conversation as resolved.
Show resolved Hide resolved
return;
}

ServiceShape serviceShape = settings.getService(model);
goDelegator.useShapeWriter(serviceShape, writer -> {
writerSignerInterface(writer);
writerConfigFieldResolver(writer, serviceShape);
writeNewV4ASignerFunc(writer, serviceShape);
});

}


private void writerSignerInterface(GoWriter writer) {
AwsSignatureVersion4aUtils.writerSignerInterface(writer);
}

private void writeNewV4ASignerFunc(GoWriter writer, ServiceShape serviceShape) {
AwsSignatureVersion4aUtils.writeNewV4ASignerFunc(writer, serviceShape);
}

private void writerConfigFieldResolver(GoWriter writer, ServiceShape serviceShape) {
AwsSignatureVersion4aUtils.writerConfigFieldResolver(writer, serviceShape);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public Model preprocessModel(Model model, GoSettings settings) {
return model;
}

if (settings.getService(model).hasTrait(SigV4ATrait.class)) {
return model;
}

var v4a = SigV4ATrait.builder()
.name(service.expectTrait(SigV4Trait.class).getName())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ software.amazon.smithy.aws.go.codegen.customization.auth.S3ExpressAuthScheme
software.amazon.smithy.aws.go.codegen.customization.S3BucketContext
software.amazon.smithy.aws.go.codegen.customization.s3.ExpressDefaultChecksum
software.amazon.smithy.aws.go.codegen.customization.auth.GlobalAnonymousOption
software.amazon.smithy.aws.go.codegen.customization.CloudFrontKVSSigV4a
29 changes: 29 additions & 0 deletions service/cloudfrontkeyvaluestore/api_client.go

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

10 changes: 10 additions & 0 deletions service/cloudfrontkeyvaluestore/auth.go

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

1 change: 1 addition & 0 deletions service/cloudfrontkeyvaluestore/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"github.com/aws/aws-sdk-go-v2": "v1.4.0",
"github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000",
"github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000",
"github.com/aws/aws-sdk-go-v2/internal/v4a": "v0.0.0-00010101000000-000000000000",
"github.com/aws/smithy-go": "v1.4.0",
"github.com/google/go-cmp": "v0.5.4"
},
Expand Down
3 changes: 3 additions & 0 deletions service/cloudfrontkeyvaluestore/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.24.1
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.10
github.com/aws/smithy-go v1.19.0
github.com/google/go-cmp v0.5.8
)
Expand All @@ -15,3 +16,5 @@ replace github.com/aws/aws-sdk-go-v2 => ../../
replace github.com/aws/aws-sdk-go-v2/internal/configsources => ../../internal/configsources/

replace github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 => ../../internal/endpoints/v2/

replace github.com/aws/aws-sdk-go-v2/internal/v4a => ../../internal/v4a/
48 changes: 48 additions & 0 deletions service/cloudfrontkeyvaluestore/options.go

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

Loading