generated from amazon-archives/__template_Apache-2.0
-
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
Merged
Merged
User agent #387
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cb47f65
WIP - add user agent interceptor/plugin
alextwoods 91e8208
Working implementation with basic user agent
alextwoods d3b1d15
Fix pyright errors
alextwoods 2031933
Use short form license
alextwoods d5473b5
Run pyupgrade
alextwoods 83a0a8f
Cleanups from PR (still todo: seperate into generic user agent and aw…
alextwoods b7e15d1
Add Config/HttpConfig Protocols + generate __version__
alextwoods 8afb134
Add __version__ to smithy and aws core
alextwoods a7475d7
WIP - generic useragent refactoring.
alextwoods 296811b
Remove explicit Config protocol
alextwoods f449114
Major refactor - generic and aws specific user agent. Codegen userage…
alextwoods 7b7573d
Merge branch 'develop' into user_agent
alextwoods 6a49728
Use aws-sdk-python as sdk name + correctly use sdkId for serviceId
alextwoods b727753
Merge branch 'develop' into user_agent
alextwoods b88dfc2
Use aws core version as the "main" sdk version. client library versio…
alextwoods 6c6458b
User agent tests
alextwoods 7aac81c
Add user_agent interceptor test
alextwoods 86e461c
Update packages/smithy-http/src/smithy_http/interceptors/user_agent.py
alextwoods 0013139
Update packages/smithy-http/tests/unit/interceptors/test_user_agent.py
alextwoods 00ce11f
PR cleanups
alextwoods 8ea3bf2
PR updates
alextwoods a35f607
Merge branch 'develop' into user_agent
alextwoods 5f128d4
Merge branch 'smithy-lang:develop' into user_agent
alextwoods 20b97ed
PR Cleanups
alextwoods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsPythonDependency.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import software.amazon.smithy.python.codegen.PythonDependency; | ||
| import software.amazon.smithy.utils.SmithyUnstableApi; | ||
|
|
||
| /** | ||
| * AWS Dependencies used in the smithy python generator. | ||
| */ | ||
| @SmithyUnstableApi | ||
| public class AwsPythonDependency { | ||
| /** | ||
| * The core aws smithy runtime python package. | ||
| * | ||
| * <p>While in development this will use the develop branch. | ||
| */ | ||
| public static final PythonDependency SMITHY_AWS_CORE = new PythonDependency( | ||
| "smithy_aws_core", | ||
| // You'll need to locally install this before we publish | ||
| "==0.0.1", | ||
| PythonDependency.Type.DEPENDENCY, | ||
| false); | ||
| } |
54 changes: 54 additions & 0 deletions
54
...core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsUserAgentIntegration.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import software.amazon.smithy.codegen.core.Symbol; | ||
| import software.amazon.smithy.codegen.core.SymbolReference; | ||
| import software.amazon.smithy.python.codegen.ConfigProperty; | ||
| import software.amazon.smithy.python.codegen.integrations.PythonIntegration; | ||
| import software.amazon.smithy.python.codegen.integrations.RuntimeClientPlugin; | ||
| import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
|
||
| /** | ||
| * Adds a runtime plugin to set user agent. | ||
| */ | ||
| @SmithyInternalApi | ||
| public class AwsUserAgentIntegration implements PythonIntegration { | ||
| @Override | ||
| public List<RuntimeClientPlugin> getClientPlugins() { | ||
| return List.of( | ||
| RuntimeClientPlugin.builder() | ||
| .addConfigProperty( | ||
| ConfigProperty.builder() | ||
| // TODO: This is the name used in boto, but potentially could be user_agent_prefix. Depends on backwards compat strategy. | ||
| .name("user_agent_extra") | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .documentation("Additional suffix to be added to the User-Agent header.") | ||
| .type(Symbol.builder().name("str").build()) // TODO: Should common types like this be defined as constants somewhere? | ||
| .nullable(true) | ||
| .build()) | ||
| .addConfigProperty( | ||
| ConfigProperty.builder() | ||
| .name("sdk_ua_app_id") | ||
| .documentation("A unique and opaque application ID that is appended to the User-Agent header.") | ||
| .type(Symbol.builder().name("str").build()) | ||
| .nullable(true) | ||
| .build() | ||
| ) | ||
| .pythonPlugin( | ||
| SymbolReference.builder() | ||
| .symbol(Symbol.builder() | ||
| .namespace(AwsPythonDependency.SMITHY_AWS_CORE.packageName() + ".plugins", ".") | ||
| .name("user_agent_plugin") | ||
| .addDependency(AwsPythonDependency.SMITHY_AWS_CORE) | ||
| .build()) | ||
| .build() | ||
| ) | ||
| .build() | ||
| ); | ||
| } | ||
|
|
||
| } | ||
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
12 changes: 12 additions & 0 deletions
12
packages/smithy-aws-core/src/smithy_aws_core/interceptors/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
51 changes: 51 additions & 0 deletions
51
packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
|
|
||
| from smithy_aws_core.user_agent import UserAgent | ||
| from smithy_core.interceptors import Interceptor, InterceptorContext, Request | ||
| from smithy_http import Field | ||
| from smithy_http.aio import HTTPRequest | ||
|
|
||
|
|
||
| class UserAgentInterceptor(Interceptor): | ||
| """Adds UserAgent header to the Request before signing.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| ua_suffix: str | None = None, | ||
| ua_app_id: str | None = None, | ||
| sdk_version: str | None = "0.0.1", | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> None: | ||
| """Initialize the UserAgentInterceptor. | ||
|
|
||
| :ua_suffix: Additional suffix to be added to the UserAgent header. :ua_app_id: | ||
| User defined and opaque application ID to be added to the UserAgent header. | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| super().__init__() | ||
| self._ua_suffix = ua_suffix | ||
| self._ua_app_id = ua_app_id | ||
| self._sdk_version = sdk_version | ||
|
|
||
| def modify_before_signing( | ||
| self, context: InterceptorContext[Request, None, HTTPRequest, None] | ||
| ) -> HTTPRequest: | ||
| user_agent = UserAgent.from_environment().with_config( | ||
| ua_suffix=self._ua_suffix, | ||
| ua_app_id=self._ua_app_id, | ||
| sdk_version=self._sdk_version, | ||
| ) | ||
| request = context.transport_request | ||
| request.fields.set_field( | ||
| Field(name="User-Agent", values=[user_agent.to_string()]) | ||
| ) | ||
| return context.transport_request | ||
25 changes: 25 additions & 0 deletions
25
packages/smithy-aws-core/src/smithy_aws_core/plugins/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You | ||
| # may not use this file except in compliance with the License. A copy of | ||
| # the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0/ | ||
| # | ||
| # or in the "license" file accompanying this file. This file is | ||
| # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific | ||
| # language governing permissions and limitations under the License. | ||
| from typing import Any | ||
|
|
||
| from smithy_aws_core.interceptors.user_agent import UserAgentInterceptor | ||
|
|
||
|
|
||
| # TODO: Define a Protocol for Config w/ interceptor method? | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def user_agent_plugin(config: Any) -> None: | ||
| config.interceptors.append( | ||
| UserAgentInterceptor( | ||
| ua_suffix=config.user_agent_extra, | ||
| ua_app_id=config.sdk_ua_app_id, | ||
| ) | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.