Skip to content

Commit

Permalink
BREAKFIX: Only generate AccountIDEndpointMode config for services tha…
Browse files Browse the repository at this point in the history
…t use it (#2795)
  • Loading branch information
lucix-aws authored Sep 17, 2024
1 parent 0d08ea0 commit 6a28d22
Show file tree
Hide file tree
Showing 1,174 changed files with 3,890 additions and 13,892 deletions.
401 changes: 401 additions & 0 deletions .changelog/28f542b4288d47b982b4261b8f5f6530.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.BiPredicate;
import java.util.logging.Logger;

import software.amazon.smithy.aws.go.codegen.customization.AccountIDEndpointRouting;
import software.amazon.smithy.aws.go.codegen.customization.auth.AwsHttpBearerAuthScheme;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
Expand Down Expand Up @@ -242,6 +243,7 @@ public class AddAwsConfigFields implements GoIntegration {
.name(SDK_ACCOUNTID_ENDPOINT_MODE)
.type(SdkGoTypes.Aws.AccountIDEndpointMode)
.documentation("Indicates how aws account ID is applied in endpoint2.0 routing")
.servicePredicate(AccountIDEndpointRouting::hasAccountIdEndpoints)
.build()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.SmithyGoTypes;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.rulesengine.language.syntax.Identifier;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.utils.MapUtils;

Expand All @@ -17,6 +19,10 @@
public class AccountIDEndpointRouting implements GoIntegration {
@Override
public void renderPreEndpointResolutionHook(GoSettings settings, GoWriter writer, Model model) {
if (!hasAccountIdEndpoints(model, settings.getService(model))) {
return;
}

writer.write("""
if err := checkAccountID(getIdentity(ctx), m.options.AccountIDEndpointMode); err != nil {
return out, metadata, $T("invalid accountID set: %w", err)
Expand All @@ -32,9 +38,10 @@ public void writeAdditionalFiles(
SymbolProvider symbolProvider,
GoDelegator goDelegator
) {
if (!settings.getService(model).hasTrait(EndpointRuleSetTrait.class)) {
if (!hasAccountIdEndpoints(model, settings.getService(model))) {
return;
}

goDelegator.useShapeWriter(settings.getService(model), goTemplate("""
func checkAccountID(identity $auth:T, mode $accountIDEndpointMode:T) error {
switch mode {
Expand Down Expand Up @@ -67,4 +74,19 @@ func checkAccountID(identity $auth:T, mode $accountIDEndpointMode:T) error {
)
));
}

public static boolean hasAccountIdEndpoints(Model model, ServiceShape service) {
if (!service.hasTrait(EndpointRuleSetTrait.class)) {
return false;
}

var rules = service.expectTrait(EndpointRuleSetTrait.class).getEndpointRuleSet();
for (var param : rules.getParameters()) {
if (param.getBuiltIn().orElse("").equals("AWS::Auth::AccountId")) {
return true;
}
}

return false;
}
}
1 change: 0 additions & 1 deletion internal/protocoltest/awsrestjson/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/awsrestjson/options.go

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

1 change: 0 additions & 1 deletion internal/protocoltest/ec2query/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/ec2query/options.go

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

1 change: 0 additions & 1 deletion internal/protocoltest/jsonrpc/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/jsonrpc/options.go

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

1 change: 0 additions & 1 deletion internal/protocoltest/jsonrpc10/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/jsonrpc10/options.go

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

1 change: 0 additions & 1 deletion internal/protocoltest/query/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/query/options.go

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

1 change: 0 additions & 1 deletion internal/protocoltest/restxml/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/restxml/options.go

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

19 changes: 9 additions & 10 deletions internal/protocoltest/restxmlwithnamespace/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/restxmlwithnamespace/options.go

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

17 changes: 8 additions & 9 deletions internal/protocoltest/smithyrpcv2cbor/api_client.go

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

3 changes: 0 additions & 3 deletions internal/protocoltest/smithyrpcv2cbor/options.go

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

38 changes: 9 additions & 29 deletions service/accessanalyzer/api_client.go

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

4 changes: 0 additions & 4 deletions service/accessanalyzer/endpoints.go

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

3 changes: 0 additions & 3 deletions service/accessanalyzer/options.go

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

38 changes: 9 additions & 29 deletions service/account/api_client.go

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

4 changes: 0 additions & 4 deletions service/account/endpoints.go

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

3 changes: 0 additions & 3 deletions service/account/options.go

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

Loading

0 comments on commit 6a28d22

Please sign in to comment.