Add pro clients, allow setting of request params through a "proxy"#7923
Merged
Add pro clients, allow setting of request params through a "proxy"#7923
Conversation
dfangl
commented
Mar 21, 2023
localstack/aws/connect.py
Outdated
| if service_principal: | ||
| params["_ServicePrincipal"] = service_principal | ||
| self._params = params | ||
| return self |
Member
Author
There was a problem hiding this comment.
On second thought, I think it would be better to make this immutable and always return a new object
…eturn value of request_metadata
dominikschubert
approved these changes
Mar 21, 2023
Member
dominikschubert
left a comment
There was a problem hiding this comment.
LGTM! 🚀
Added a minor doc suggestion.
Really itching to rewrite some things with the new client now!
| from typing import TYPE_CHECKING, Union | ||
|
|
||
| if TYPE_CHECKING: | ||
| from mypy_boto3_acm import ACMClient |
Member
There was a problem hiding this comment.
Love that these are now separated into their own file. Will keep the churn here much better isolated 👍
Co-authored-by: Dominik Schubert <dominik.schubert91@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, the new AWS provider allows us to set internal request parameters with an underscore in front of the parameter name in Pascal Case, like this:
Due to the typed nature of the new clients, this will lead to a typing error, as these parameters are not known by the boto stubs.
Changes
Introduces another method to all returned clients, named
request_metadata. You can use this method to get a "version" of your client where these parameters are automatically set on all service calls.Example:
This will be typed correctly, which removes all the yellow warnings of your IDE.
Drawback
The main drawback is the highly weird way this is done in. It introduces a new "proxy" object, which will be typed as the boto3 client. On any get attribute operation for a callable (like a client.function), it will return a partial function with the above mentioned parameters pre-filled, so you do not have to provide them.
This is quite unorthodox, but works fine without too much of a performance penalty.