-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add pro clients, allow setting of request params through a "proxy" #7923
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
Conversation
localstack/aws/connect.py
Outdated
if service_principal: | ||
params["_ServicePrincipal"] = service_principal | ||
self._params = params | ||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think it would be better to make this immutable and always return a new object
…eturn value of request_metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.