-
Notifications
You must be signed in to change notification settings - Fork 638
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
Fix host prefix bug #2200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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.
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.
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.
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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