Skip to content

Commit

Permalink
Fix S3Control endpoint customization tests (#2195)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahvita committed Jul 31, 2023
1 parent 3215621 commit 3fe6736
Show file tree
Hide file tree
Showing 177 changed files with 3,907 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class AwsGoDependency {
null, Versions.SERVICE_INTERNAL_CHECKSUM, "internalChecksum");
public static final GoDependency INTERNAL_SIGV4A = awsModuleDep("internal/v4a",
null, Versions.INTERNAL_SIGV4A, "v4a");
public static final GoDependency S3_INTERNAL_ARN = aws("service/internal/s3shared/arn", "s3arn");
public static final GoDependency AWS_ARN = aws("aws/arn", "awsarn");


public static final GoDependency REGEXP = SmithyGoDependency.stdlib("regexp");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package software.amazon.smithy.aws.go.codegen.customization;

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.GoIntegration;
import software.amazon.smithy.model.Model;

public class DisableEndpointHostPrefix implements GoIntegration {
@Override
public void renderPostEndpointResolutionHook(GoSettings settings, GoWriter writer, Model model) {
writer.write(
"""
ctx = $T(ctx, true)
""",
SymbolUtils.createPointableSymbolBuilder("DisableEndpointHostPrefix", SmithyGoDependency.SMITHY_HTTP_TRANSPORT).build()
);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package software.amazon.smithy.aws.go.codegen.customization;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import software.amazon.smithy.codegen.core.CodegenException;
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.SymbolUtils;
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.knowledge.TopDownIndex;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SetUtils;

/**
* Implements the arnable interface on all relevant S3/S3Control outposts operations.
*/
public class S3UpdateOutpostArn implements GoIntegration {

private final Set<String> LIST_ACCESSPOINT_ARN_INPUT = SetUtils.of(
"GetAccessPoint", "DeleteAccessPoint", "PutAccessPointPolicy",
"GetAccessPointPolicy", "DeleteAccessPointPolicy"
);

private final MiddlewareRegistrar middlewareAdder =
MiddlewareRegistrar.builder()
.resolvedFunction(SymbolUtils.createValueSymbolBuilder("AddUpdateOutpostARN", AwsCustomGoDependency.S3CONTROL_CUSTOMIZATION).build())
.build();

@Override
public List<RuntimeClientPlugin> getClientPlugins() {
return ListUtils.of(
RuntimeClientPlugin.builder()
.servicePredicate(S3ModelUtils::isServiceS3Control)
.registerMiddleware(middlewareAdder)
.build()
);
}

public void writeAdditionalFiles(GoSettings settings, Model model, SymbolProvider symbolProvider, GoDelegator goDelegator) {
ServiceShape service = settings.getService(model);
if (!S3ModelUtils.isServiceS3Control(model, service)) return;

for (OperationShape operation : TopDownIndex.of(model).getContainedOperations(service)) {
goDelegator.useShapeWriter(operation, writer -> {
writeARNHelper(settings, writer, model, symbolProvider, operation);
});
}
}

private void writeARNHelper(
GoSettings settings, GoWriter writer,
Model model, SymbolProvider symbolProvider, OperationShape operation
) {
ServiceShape service = settings.getService(model);

String arnType = LIST_ACCESSPOINT_ARN_INPUT.contains(
operation.getId().getName(service)
) ? "AccessPointName" : "BucketName";

StructureShape input = model.expectShape(operation.getInput().get(), StructureShape.class);
List<MemberShape> listOfARNMembers = input.getAllMembers().values().stream()
.filter(m -> m.getTarget().getName(service).equals(arnType))
.collect(Collectors.toList());
if (listOfARNMembers.size() > 1) {
throw new CodegenException(arnType + " shape should be targeted by only one input member, found " +
listOfARNMembers.size() + " for Input shape: " + input.getId());
}

if (listOfARNMembers.isEmpty()) {
return;
}

String inputName = symbolProvider.toSymbol(input).getName();
String memberName = listOfARNMembers.get(0).getMemberName();

writer.write(
"""
func (m *$1L) GetARNMember() (*string, bool) {
if m.$2L == nil {
return nil, false
}
return m.$2L, true
}
""",
inputName,
memberName
);


writer.write(
"""
func (m *$1L) SetARNMember(v string) error {
m.$2L = &v
return nil
}
""",
inputName,
memberName
);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ software.amazon.smithy.aws.go.codegen.customization.LambdaRecursionDetection
software.amazon.smithy.aws.go.codegen.customization.SQSCustomizations
software.amazon.smithy.aws.go.codegen.AwsEndpointResolverInitializerGenerator
software.amazon.smithy.aws.go.codegen.AwsEndpointResolverBuiltInGenerator
software.amazon.smithy.aws.go.codegen.customization.S3ControlHostPrefixAccountIdFilterIntegration
software.amazon.smithy.aws.go.codegen.customization.S3HttpPathBucketFilterIntegration
software.amazon.smithy.aws.go.codegen.customization.S3HttpLabelBucketFilterIntegration
software.amazon.smithy.aws.go.codegen.customization.DisableEndpointHostPrefix
software.amazon.smithy.aws.go.codegen.AwsEndpointAuthSchemeGenerator
software.amazon.smithy.aws.go.codegen.EndpointDisableHttps
software.amazon.smithy.aws.go.codegen.customization.S3Bucketer
software.amazon.smithy.aws.go.codegen.customization.S3SerializeImmutableHostnameBucket
software.amazon.smithy.aws.go.codegen.customization.S3UpdateOutpostArn
software.amazon.smithy.aws.go.codegen.LegacyEndpointContextSetter

This file was deleted.

32 changes: 32 additions & 0 deletions service/internal/s3shared/arn/arn_member.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package arn

import "fmt"

// arnable is implemented by the relevant S3/S3Control
// operations which have members that may need ARN
// processing.
type arnable interface {
SetARNMember(string) error
GetARNMember() (*string, bool)
}

// GetARNField would be called during middleware execution
// to retrieve a member value that is an ARN in need of
// processing.
func GetARNField(input interface{}) (*string, bool) {
v, ok := input.(arnable)
if !ok {
return nil, false
}
return v.GetARNMember()
}

// SetARNField would called during middleware exeuction
// to set a member value that required ARN processing.
func SetARNField(input interface{}, v string) error {
params, ok := input.(arnable)
if !ok {
return fmt.Errorf("Params does not contain arn field member")
}
return params.SetARNMember(v)
}
5 changes: 0 additions & 5 deletions service/internal/s3shared/arn_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/smithy-go/middleware"

"github.com/aws/aws-sdk-go-v2/aws/arn"
Expand All @@ -29,10 +28,6 @@ func (m *ARNLookup) ID() string {
func (m *ARNLookup) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
if !awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
return next.HandleInitialize(ctx, in)
}

// check if GetARNValue is supported
if m.GetARNValue == nil {
return next.HandleInitialize(ctx, in)
Expand Down
2 changes: 2 additions & 0 deletions service/s3/api_op_AbortMultipartUpload.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_CompleteMultipartUpload.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_CopyObject.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_CreateBucket.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_CreateMultipartUpload.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_DeleteBucket.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_DeleteBucketAnalyticsConfiguration.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_DeleteBucketCors.go

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

2 changes: 2 additions & 0 deletions service/s3/api_op_DeleteBucketEncryption.go

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

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

Loading

0 comments on commit 3fe6736

Please sign in to comment.