-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2490 from aws/feat-aid-endpoints
Support aws account id in endpoint2.0 routing
- Loading branch information
Showing
1,593 changed files
with
21,682 additions
and
5,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "783a73b9-7a98-43d9-91c0-55e06537c43c", | ||
"type": "feature", | ||
"description": "Support accountID-based endpoint routing.", | ||
"modules": [ | ||
"." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package aws | ||
|
||
// AccountIDEndpointMode controls how a resolved AWS account ID is handled for endpoint routing. | ||
type AccountIDEndpointMode string | ||
|
||
const ( | ||
// AccountIDEndpointModeUnset indicates the AWS account ID will not be used for endpoint routing | ||
AccountIDEndpointModeUnset AccountIDEndpointMode = "" | ||
|
||
// AccountIDEndpointModePreferred indicates the AWS account ID will be used for endpoint routing if present | ||
AccountIDEndpointModePreferred = "preferred" | ||
|
||
// AccountIDEndpointModeRequired indicates an error will be returned if the AWS account ID is not resolved from identity | ||
AccountIDEndpointModeRequired = "required" | ||
|
||
// AccountIDEndpointModeDisabled indicates the AWS account ID will be ignored during endpoint routing | ||
AccountIDEndpointModeDisabled = "disabled" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...in/java/software/amazon/smithy/aws/go/codegen/customization/AccountIDEndpointRouting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package software.amazon.smithy.aws.go.codegen.customization; | ||
|
||
import software.amazon.smithy.aws.go.codegen.SdkGoTypes; | ||
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.GoStdlibTypes; | ||
import software.amazon.smithy.go.codegen.GoWriter; | ||
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.rulesengine.traits.EndpointRuleSetTrait; | ||
import software.amazon.smithy.utils.MapUtils; | ||
|
||
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; | ||
|
||
public class AccountIDEndpointRouting implements GoIntegration { | ||
@Override | ||
public void renderPreEndpointResolutionHook(GoSettings settings, GoWriter writer, Model model) { | ||
writer.write(""" | ||
if err := checkAccountID(getIdentity(ctx), m.options.AccountIDEndpointMode); err != nil { | ||
return out, metadata, $T("invalid accountID set: %w", err) | ||
} | ||
""", | ||
GoStdlibTypes.Fmt.Errorf); | ||
} | ||
|
||
@Override | ||
public void writeAdditionalFiles( | ||
GoSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
GoDelegator goDelegator | ||
) { | ||
if (!settings.getService(model).hasTrait(EndpointRuleSetTrait.class)) { | ||
return; | ||
} | ||
goDelegator.useShapeWriter(settings.getService(model), goTemplate(""" | ||
func checkAccountID(identity $auth:T, mode $accountIDEndpointMode:T) error { | ||
switch mode { | ||
case $aidModeUnset:T: | ||
case $aidModePreferred:T: | ||
case $aidModeDisabled:T: | ||
case $aidModeRequired:T: | ||
if ca, ok := identity.(*$credentialsAdapter:T); !ok { | ||
return $errorf:T("accountID is required but not set") | ||
} else if ca.Credentials.AccountID == "" { | ||
return $errorf:T("accountID is required but not set") | ||
} | ||
// default check in case invalid mode is configured through request config | ||
default: | ||
return $errorf:T("invalid accountID endpoint mode %s, must be preferred/required/disabled", mode) | ||
} | ||
return nil | ||
} | ||
""", | ||
MapUtils.of( | ||
"auth", SmithyGoTypes.Auth.Identity, | ||
"accountIDEndpointMode", SdkGoTypes.Aws.AccountIDEndpointMode, | ||
"credentialsAdapter", SdkGoTypes.Internal.Auth.Smithy.CredentialsAdapter, | ||
"aidModePreferred", SdkGoTypes.Aws.AccountIDEndpointModePreferred, | ||
"aidModeRequired", SdkGoTypes.Aws.AccountIDEndpointModeRequired, | ||
"aidModeUnset", SdkGoTypes.Aws.AccountIDEndpointModeUnset, | ||
"aidModeDisabled", SdkGoTypes.Aws.AccountIDEndpointModeDisabled, | ||
"errorf", GoStdlibTypes.Fmt.Errorf | ||
) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.