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

Fix host prefix bug #2200

Merged
merged 2 commits into from
Jul 21, 2023
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
Expand Up @@ -25,6 +25,7 @@
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;


Expand All @@ -36,7 +37,9 @@
public class AwsEndpointAuthSchemeGenerator implements GoIntegration {

@Override
public void renderPostEndpointResolutionHook(GoSettings settings, GoWriter writer, Model model) {
public void renderPostEndpointResolutionHook(
GoSettings settings, GoWriter writer, Model model, Optional<OperationShape> operation
) {
ServiceShape serviceShape = settings.getService(model);
writer.write(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class EndpointDisableHttps implements GoIntegration {

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

public static final String MIDDLEWARE_ID = "EndpointDisableHTTPSMiddleware";
public static final String MIDDLEWARE_ID = "endpointDisableHTTPSMiddleware";
public static final String MIDDLEWARE_ADDER = String.format("add%s", MIDDLEWARE_ID);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LegacyEndpointContextSetter implements GoIntegration {

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

public static final String MIDDLEWARE_ID = "LegacyEndpointContextSetter";
public static final String MIDDLEWARE_ID = "legacyEndpointContextSetter";
public static final String MIDDLEWARE_ADDER = String.format("add%s", MIDDLEWARE_ID);

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

import java.util.Optional;


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;
import software.amazon.smithy.model.pattern.SmithyPattern.Segment;
import software.amazon.smithy.model.traits.EndpointTrait;
import software.amazon.smithy.model.shapes.OperationShape;


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()
);
public void renderPostEndpointResolutionHook(
GoSettings settings, GoWriter writer, Model model, Optional<OperationShape> operation
) {
if (!S3ModelUtils.isServiceS3Control(model, settings.getService(model))) {
return;
}

if (operation.isPresent() && operation.get().getTrait(EndpointTrait.class).isPresent()) {
EndpointTrait endpointTrait = operation.get().getTrait(EndpointTrait.class).get();
boolean written = false;
for (Segment segment : endpointTrait.getHostPrefix().getLabels()) {
if (segment.isLabel() && segment.getContent().equals("AccountId") && !written) {
writer.write(
"""
ctx = $T(ctx, true)
""",
SymbolUtils.createPointableSymbolBuilder(
"DisableEndpointHostPrefix", SmithyGoDependency.SMITHY_HTTP_TRANSPORT).build()
);
// we only want the content above written ONCE per operation.
written = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Then just write it and break out of the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, will do, in next PR -- artifact left over from my previous logic. a break is more straightforward

}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ software.amazon.smithy.aws.go.codegen.AwsEndpointResolverInitializerGenerator
software.amazon.smithy.aws.go.codegen.AwsEndpointResolverBuiltInGenerator
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
software.amazon.smithy.aws.go.codegen.customization.DisableEndpointHostPrefix

24 changes: 12 additions & 12 deletions service/eventbridge/api_client.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_ActivateEventSource.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CancelReplay.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreateApiDestination.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreateArchive.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreateConnection.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreateEndpoint.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreateEventBus.go

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

6 changes: 2 additions & 4 deletions service/eventbridge/api_op_CreatePartnerEventSource.go

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

Loading
Loading