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

Add accountID endpoint builtin and accountID endpoint mode config #2479

Merged
merged 11 commits into from
Feb 12, 2024

Conversation

wty-Bryant
Copy link
Contributor

Merge accountID into endpoint rules codegen as an endpoint param builtin retrieved from credentials, add accountIDEndpoint mode config to opt in/out accountID based endpoint routing

@wty-Bryant wty-Bryant requested a review from a team as a code owner February 2, 2024 19:46
@@ -0,0 +1,41 @@
package accountid
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need a new package for this. It can go in the base aws package.

@@ -0,0 +1,29 @@
package mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, base package.

Copy link
Contributor

Choose a reason for hiding this comment

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

AccountIDEndpointMode. aid is fine for a development branch name but as a consumer-facing identifier we have to be clearer.


// enums of valid AIDMode
const (
Preferred AIDMode = "preferred"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's idiomatic in go to prepend the variants of each enum value with the enum's name.

e.g. AccountIDEndpointModePreferred.

@@ -25,10 +25,35 @@
{
"id": "Service",
"namespace": "*"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove all the model changes in the commit. They should only be present locally for testing purposes.


// enums of valid AIDMode
const (
Preferred AIDMode = "preferred"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a none/unset sentinel i.e. AccountIDEndpointModeUnset (which is just the empty string).

)

// SetFromString converts config string to corresponding AIDMode or reports error if the value is not enumerated
func (mode *AIDMode) SetFromString(s string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no real reason to expose this, since sourcing the value from config is an implementation detail for us, let's keep it that way.

@@ -63,7 +64,13 @@ public void renderPreEndpointResolutionHook(GoSettings settings, GoWriter writer
if $T(ctx) {
return next.HandleFinalize(ctx, in)
}
""", SdkGoTypes.Aws.Middleware.GetRequiresLegacyEndpoints);
if err := $T(getIdentity(ctx), m.options.AccountIDEndpointMode); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't really belong in this "legacy context" integration, it should have its own entity in codegen that generates it.

.build(),
AwsConfigField.builder()
.name(SDK_AID_ENDPOINT_MODE)
.type(getAwsAccountIDModeSymbol("AIDMode"))
Copy link
Contributor

@lucix-aws lucix-aws Feb 5, 2024

Choose a reason for hiding this comment

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

Add and use SdkGoTypes.Aws.AccountIDEndpointMode (once you've moved the enum there) instead.

@@ -489,7 +490,7 @@ type endpointParamsBinder interface {
bindEndpointParams(*EndpointParameters)
}

func bindEndpointParams(input interface{}, options Options) *EndpointParameters {
func bindEndpointParams(input interface{}, options Options, ctx context.Context) *EndpointParameters {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be seeing the account ID binding getting generated here? Specifically somewhere from line 496 on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I regenerated the client using model without accountID builtin in my last commit. I will regenerate that using mocked model

@wty-Bryant wty-Bryant force-pushed the feat-endpoint-builtin branch from 05d0878 to 02e7fde Compare February 6, 2024 21:21
@@ -0,0 +1,12 @@
package aws

// AccountIDEndpointMode switches on/off the account ID based endpoint routing
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AccountIDEndpointMode switches on/off the account ID based endpoint routing
// AccountIDEndpointMode controls how a resolved AWS account ID is handled for endpoint routing.

// enums of valid AccountIDEndpointMode
const (
AccountIDEndpointModeUnset AccountIDEndpointMode = ""
AccountIDEndpointModePreferred AccountIDEndpointMode = "preferred"
Copy link
Contributor

Choose a reason for hiding this comment

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

[nonblocking] You can leave the type declaration off of everything but the first line, the compiler figures it out

e.g.

type Foo = string

const (
    Foo1 Foo = "1"
    Foo2     = "2" // is implicitly type Foo as is everything after it
)

aws/config.go Outdated
Comment on lines 166 to 167
// AccountIDEndpointMode indicates how aws account ID is applied in endpoint2.0 routing.
// Will be set to preferred by default. Supported modes are: Preferred, Required and Disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AccountIDEndpointMode indicates how aws account ID is applied in endpoint2.0 routing.
// Will be set to preferred by default. Supported modes are: Preferred, Required and Disabled
// Controls how a resolved AWS account ID is handled for endpoint routing.

// AccountIDEndpointMode switches on/off the account ID based endpoint routing
type AccountIDEndpointMode string

// enums of valid AccountIDEndpointMode
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than having the comment on the declaration block, give each one a comment explaining what it does.

@@ -81,6 +81,8 @@ public class AddAwsConfigFields implements GoIntegration {

private static final String REQUEST_MIN_COMPRESSION_SIZE_BYTES = "RequestMinCompressSizeBytes";

private static final String SDK_AID_ENDPOINT_MODE = "AccountIDEndpointMode";
Copy link
Contributor

Choose a reason for hiding this comment

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

[nonblocking] We'd rather see this spelled out SDK_ACCOUNTID_ENDPOINT_MODE but it's not a huge deal.


public class AccountIDEndpointRouting implements GoIntegration {
@Override
public void renderPreEndpointResolutionHook(GoSettings settings, GoWriter writer, Model model) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make sure this happens after the early return that's triggered when we detect they're using v1 endpoint resolution. You may need to fiddle with the integration order to accomplish that.

return;
}
goDelegator.useShapeWriter(settings.getService(model), goTemplate("""
func accountID(identity $auth:T, mode $accountIDEndpointMode:T) *string {
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things here

  1. the name here is too broad, this is likely to collide with random identifiers we generate in the package. I'd call it resolveAccountID, bindAccountID, etc.
  2. you're adding the builtin that calls this in a different location than where it's defined. We should move the accountID function you have here to be generated in the builtins integration instead. (checkAccountID is used here and can stay in this integration)

}
goDelegator.useShapeWriter(settings.getService(model), goTemplate("""
func accountID(identity $auth:T, mode $accountIDEndpointMode:T) *string {
if ca, ok := identity.(*$credentialsAdapter:T); ok && (mode == $aidModePreferred:T || mode == $aidModeRequired:T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking all the modes where it's on, I'd just check the one mode where it's off (disabled) and return early

Copy link
Contributor

@lucix-aws lucix-aws left a comment

Choose a reason for hiding this comment

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

fixandship!

// 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 offered
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AccountIDEndpointModePreferred indicates the AWS account ID will be used for endpoint routing if offered
// AccountIDEndpointModePreferred indicates the AWS account ID will be used for endpoint routing if present

Comment on lines 42 to 45
return $errorf:T("the accountID is configured to be required, but the " +
"identity provider could not be converted to a valid credentials adapter " +
"and provide an accountID, should switch to a valid credentials provider " +
"or change to another account id endpoint mode")
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have to specific about the type assertion failing in this path - we can just say an accountID wasn't found.

Suggested change
return $errorf:T("the accountID is configured to be required, but the " +
"identity provider could not be converted to a valid credentials adapter " +
"and provide an accountID, should switch to a valid credentials provider " +
"or change to another account id endpoint mode")
return $errorf:T("accountID is required but not set")

(use this value in the next branch as well)

}
goDelegator.useShapeWriter(settings.getService(model), goTemplate("""
func resolveAccountID(identity $auth:T, mode $accountIDEndpointMode:T) *string {
if mode == $aidModeDisabled:T || mode == $aidModeUnset:T {
Copy link
Contributor

Choose a reason for hiding this comment

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

An unset value is supposed to imply preferred, according to the spec:

preferred, or no value - Default behavior

So this should only check for disabled

@wty-Bryant wty-Bryant merged commit f40adb7 into feat-aid-endpoints Feb 12, 2024
10 checks passed
@wty-Bryant wty-Bryant deleted the feat-endpoint-builtin branch February 12, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants