-
Notifications
You must be signed in to change notification settings - Fork 24
User agent #387
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
User agent #387
Conversation
packages/smithy-aws-core/src/smithy_aws_core/interceptors/__init__.py
Outdated
Show resolved
Hide resolved
JordonPhillips
left a comment
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.
You should run pyupgrade --py312-plus on all this, it'll resolve most of the typing and syntax issues I've called out.
As far as this being in AWS, I don't agree. I think almost all of this can and should be generic. The only real exception would be the app id and execution env, but those could be appended in a separate interceptor
...ws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsUserAgentIntegration.java
Outdated
Show resolved
Hide resolved
packages/smithy-aws-core/src/smithy_aws_core/plugins/__init__.py
Outdated
Show resolved
Hide resolved
...ws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsUserAgentIntegration.java
Outdated
Show resolved
Hide resolved
packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py
Outdated
Show resolved
Hide resolved
packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py
Outdated
Show resolved
Hide resolved
...gen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java
Outdated
Show resolved
Hide resolved
| writer.write(""" | ||
| def aws_user_agent_plugin(config: $1T): | ||
| config.interceptors.append( | ||
| $2T( | ||
| ua_suffix=config.user_agent_extra, | ||
| ua_app_id=config.sdk_ua_app_id, | ||
| sdk_version=$3T, | ||
| service_id='$4L' | ||
| ) | ||
| ) | ||
| """, | ||
| CodegenUtils.getConfigSymbol(c.settings()), | ||
| userAgentInterceptor, | ||
| versionSymbol, | ||
| c.settings().service().getName() | ||
| ); |
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.
Why did you move this into Java?
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.
To get the client library version and service id - since both of those are specific to the generated client.
The alternative would be to add that information to the interceptor context (or potentially to use some python metaprogramming hacks?).
Do you have thoughts or preferences between those? (or maybe another obvious way I'm missing to get client library version and service id)
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.
Ah yeah the service id isn't available right now because we're not writing out service schemas, and thus those traits aren't present.
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.
I think even with service schemas we'd still need some way for a generic (ie, non codegen) interceptor or plugin to access it. Though there are a few ways we could do that - such as adding it to the interceptor context or the config? Theres probably other pythonic metaprogramming tricks as well (get the caller's namespace and search it?)
…n is still captured on `api` field as expected by ua/2.0
nateprewitt
left a comment
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.
I think this is probably my last round of comments, otherwise things look good!
...ws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsUserAgentIntegration.java
Show resolved
Hide resolved
packages/smithy-http/tests/unit/interceptors/test_user_agent.py
Outdated
Show resolved
Hide resolved
packages/smithy-http/src/smithy_http/interceptors/user_agent.py
Outdated
Show resolved
Hide resolved
packages/smithy-http/src/smithy_http/interceptors/user_agent.py
Outdated
Show resolved
Hide resolved
packages/smithy-http/src/smithy_http/interceptors/user_agent.py
Outdated
Show resolved
Hide resolved
|
Also looks like the test_environment tests may not have everything properly mocked: It looks like you tested arm64 locally, but GHA is running on x86_64. |
Co-authored-by: Nate Prewitt <nate.prewitt@gmail.com>
Co-authored-by: Nate Prewitt <nate.prewitt@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.
The formatter has truly failed here... oh well
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.
Yeah - I had a bit of a fight with it trying to make this a little less garbage. Made it slightly better, but still don't love it.
| writer.write(""" | ||
| @dataclass(init=False) | ||
| class $L: | ||
| class $T: |
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.
T is intended for references, not declarations. Why was this change made?
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.
Reverted to $L for the decleration - Had done it without thinking since its using the symbol as an argument.
| /** | ||
| * Creates top level __init__.py file. | ||
| */ | ||
| private void generateServiceModuleInit(CustomizeDirective<GenerationContext, PythonSettings> directive) { |
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.
This could be done directly in generateInits. I'm refactoring this in a separate PR though so it's fine to have it here for now.
20b97ed
Description of changes:
Add UserAgent header to requests in generated clients using runtime plugins with separate generic and AWS specific logic.
This change adds a generic (non-aws) plugin that adds a base UserAgent object to the interceptor context that allows other interceptors to add data to the user agent. This is required because the user agent string MUST follow a defined order so we cannot simply append values to the header. The generic interceptor also adds a
modify_before_signinterceptor which sets the user agent header from the UserAgent object on the context.The AWS specific plugin must be generated per service client to give us access to the service library's version and the service ID. The interceptor just adds data to the UserAgent context object.
The
UserAgentclass logic is largely borrowed from botocore's UserAgent.The advantages of this approach:
Cons/Issues:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.