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

account id routing and credentials interface #998

Merged
merged 7 commits into from
Nov 17, 2023
Merged

Conversation

aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Nov 15, 2023

Issue #

n/a
downstream: awslabs/aws-sdk-kotlin#1111

Description of changes

Refactors Credentials to be an interface.

Miscellaneous support for upstream account ID based routing PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aajtodd aajtodd requested a review from a team as a code owner November 15, 2023 17:24
Comment on lines 1 to 6
{
"id": "6467a679-d9c3-4741-8219-28d7d32abf5f",
"type": "misc",
"description": "refactor: make `Credentials` an interface"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Correctness: Breaking

Comment on lines 10 to 14
# SDK
sdkVersion=0.28.3-SNAPSHOT
sdkVersion=0.29.0-SNAPSHOT

# codegen
codegenVersion=0.28.2
codegenVersion=0.29.0-SNAPSHOT
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Does our tooling not handle this automatically? Or is that just for aws-sdk-kotlin?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean this should have been 0.28.2-SNAPSHOT before the change?

The tooling will automatically bump the patch version (to 0.28.3, in this case) if there's a SNAPSHOT suffix or not. But since this is a breaking change in codegen, we need to bump the minor version which can't be done automatically.

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 think he's referring to the --minor-version-bump flag to kat handling this automatically based on the changelog. I don't actually know and kind of forgot we added that. I'll be reverting the change to sdkVersion in aws-sdk-kotlin as it will cause conflicts between main and release if we don't run the merge workflow before next release.

For this one though will it auto bump both sdk and codegen version? I'm confused why these weren't in sync since I thought thats what we landed on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes the --minor-version-bump should bump both versions, since the logic for it is located in bump-version command which both sdkVersion and codegenVersion use

Copy link
Contributor

Choose a reason for hiding this comment

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

They weren't in sync because there is a second bump command which runs for sdkVersion only. Probably could use a fix

Comment on lines 65 to 68
val expiration = minOf(providerCreds.expiration, (clock.now() + expireCredentialsAfter))
val expiration = minOf(providerCreds.expiration!!, (clock.now() + expireCredentialsAfter))
ExpiringValue(providerCreds, expiration)
} else {
val expiration = clock.now() + expireCredentialsAfter
Copy link
Contributor

Choose a reason for hiding this comment

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

Style:

val expiration = listOfNotNull(providerCreds.expiration, clock.now() + expireCredentialsAfter).min()
ExpiringValue(providerCreds, expiration)

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 changed this but I'm not sure it's what we want looking closer. If provider creds aren't null we set the cache expiration to the min of the two but keep the original expiration. If they are null we set the expiration of the credentials to match when we'll expire them in the cache.

If we make this change we narrow the expiration of the credentials which seems undesirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe something like this:

            val cacheExpiration = listOfNotNull(providerCreds.expiration, clock.now() + expireCredentialsAfter).min()
            val credsExpiration = providerCreds.expiration ?: cacheExpiration
            val creds = providerCreds.copy(expiration = credsExpiration)
            ExpiringValue(creds, cacheExpiration)

Comment on lines 68 to 88
/**
* Create a new [Credentials] instance
*/
public fun Credentials(
accessKeyId: String,
secretAccessKey: String,
sessionToken: String? = null,
expiration: Instant? = null,
providerName: String? = null,
attributes: Attributes? = null,
): Credentials {
val resolvedAttributes = if (providerName != null && attributes?.getOrNull(IdentityAttributes.ProviderName) != providerName) {
val merged = attributes?.toMutableAttributes() ?: mutableAttributes()
merged.setIfValueNotNull(IdentityAttributes.ProviderName, providerName)
merged
} else {
attributes ?: emptyAttributes()
}

return CredentialsImpl(accessKeyId, secretAccessKey, sessionToken, expiration, resolvedAttributes)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Any reason not to make this an invoke function on Credentials.Companion?

Comment on lines 15 to 17
init {
require(name.isNotBlank()) { "AttributeKey name (`$name`) cannot be blank" }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: If name is blank there might not be much value in including it in the error message (e.g., "AttributeKey name (``) cannot be blank").

Comment on lines 10 to 14
# SDK
sdkVersion=0.28.3-SNAPSHOT
sdkVersion=0.29.0-SNAPSHOT

# codegen
codegenVersion=0.28.2
codegenVersion=0.29.0-SNAPSHOT
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean this should have been 0.28.2-SNAPSHOT before the change?

The tooling will automatically bump the patch version (to 0.28.3, in this case) if there's a SNAPSHOT suffix or not. But since this is a breaking change in codegen, we need to bump the minor version which can't be done automatically.

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@aajtodd aajtodd merged commit 66e30ac into main Nov 17, 2023
13 of 14 checks passed
@aajtodd aajtodd deleted the accountid-builtin branch November 17, 2023 17:43
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.

3 participants