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

feat: make region optional #970

Merged
merged 2 commits into from
Jul 17, 2023
Merged

feat: make region optional #970

merged 2 commits into from
Jul 17, 2023

Conversation

ianbotsf
Copy link
Contributor

@ianbotsf ianbotsf commented Jul 3, 2023

Issue #

Closes #969

Description of changes

Makes region an optional client config parameter to support MRAP and future multi-region use cases. Note that failing to provide a region in single-region cases will still fail but will throw an exception at operation invocation instead of during client construction.

Companion PR: smithy-kotlin#884

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

Copy link
Collaborator

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

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

It's unclear to me if making region optional in the credential providers is correct or not. At what point when invoking an operation do we consider the lack of region being set to be an error?

@@ -124,7 +124,7 @@ public class ProfileCredentialsProvider(
}
}

private suspend fun LeafProvider.toCredentialsProvider(region: LazyAsyncValue<String>): CredentialsProvider =
private suspend fun LeafProvider.toCredentialsProvider(region: LazyAsyncValue<String?>): CredentialsProvider =
Copy link
Collaborator

Choose a reason for hiding this comment

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

correctness: Should region be optional everywhere or just at the client config level? I'm not sure these credential provider components ever work correctly without region.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's now optional in the underlying service clients (i.e., the STS client) so I saw no reason to keep it required in the credentials provider. I'd assumed that STS would default to the global endpoint but I now see that's not the case.

If we leave this as optional in the profile creds provider and it attempts to make a call to STS which fails because of missing region, then the provider will throw an exception. If its used as part of a chain (e.g., the default chain), then that exception will cause the the next provider in the list to be called. I think that's correct since the next provide may not require a region.

assertFailsWith<IllegalArgumentException> {
S3Client { }
}.message.shouldContain("region is a required configuration property")
// Should _not_ throw an exception since region is optional
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: What is the behavior now if region isn't set? Should we have a test case for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The S3 client can now be instantiated just fine without a region. The first place we'd encounter an error is invoking an operation. We can expand this test to attempt an operation invocation and assert on the failure.

@ianbotsf
Copy link
Contributor Author

ianbotsf commented Jul 5, 2023

It's unclear to me if making region optional in the credential providers is correct or not. At what point when invoking an operation do we consider the lack of region being set to be an error?

As written, we will now consider it to be an error when resolving an endpoint during operation invocation. For example, the S3 client will throw an error in the endpoint provider: EndpointProviderException: A region must be set when sending requests to S3..

Copy link
Collaborator

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

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

Some CI failing but otherwise looks ok

@sonarcloud
Copy link

sonarcloud bot commented Jul 12, 2023

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

Comment on lines 79 to 80
// FIXME - we likely need a way to let customizations modify/override this
// FIXME - we also need a way to tie in config properties added via integrations that need to influence the context
Copy link
Member

Choose a reason for hiding this comment

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

Are these two FIXMEs solved with interceptors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// FIXME - we likely need a way to let customizations modify/override this

I'm unclear what "customization" means in this context. Certainly interceptors can be used to modify the execution context.

// FIXME - we also need a way to tie in config properties added via integrations that need to influence the context

I wouldn't call this fixed by interceptors. Integrations could certainly add an interceptor but it seems like a boilerplate workaround. There's no common solution for it here yet, which I think is what the FIXME is about.

@ianbotsf ianbotsf merged commit 3743d98 into main Jul 17, 2023
11 of 12 checks passed
@ianbotsf ianbotsf deleted the feat-region-optional branch July 17, 2023 18:29
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.

Make region optional
3 participants