diff --git a/botocore/useragent.py b/botocore/useragent.py index 8cfc731ee6..f837fc8699 100644 --- a/botocore/useragent.py +++ b/botocore/useragent.py @@ -116,6 +116,16 @@ def to_string(self): return self._value +# This is not a public interface and is subject to abrupt breaking changes. +# Any usage is not advised or supported in external code bases. +try: + from botocore.customizations.useragent import modify_components +except ImportError: + # Default implementation that returns unmodified User-Agent components. + def modify_components(components): + return components + + class UserAgentString: """ Generator for AWS SDK User-Agent header strings. @@ -271,6 +281,9 @@ def to_string(self): *self._build_app_id(), *self._build_extra(), ] + + components = modify_components(components) + return ' '.join([comp.to_string() for comp in components]) def _build_sdk_metadata(self): diff --git a/tests/unit/test_useragent.py b/tests/unit/test_useragent.py index 640a2f7469..a649dd9350 100644 --- a/tests/unit/test_useragent.py +++ b/tests/unit/test_useragent.py @@ -14,16 +14,23 @@ import pytest +import botocore.useragent from botocore import __version__ as botocore_version from botocore.config import Config from botocore.useragent import ( UserAgentString, sanitize_user_agent_string_component, ) +from tests import mock from .. import requires_crt +# Returns a list of unmodified User-Agent components. +def unmodified_components(components): + return components + + @pytest.mark.parametrize( 'raw_str, allow_hash, expected_str', [ @@ -52,6 +59,9 @@ def test_sanitize_ua_string_component(raw_str, allow_hash, expected_str): assert actual_str == expected_str +@mock.patch.object( + botocore.useragent, 'modify_components', unmodified_components +) def test_basic_user_agent_string(): ua = UserAgentString( platform_name='linux', @@ -113,6 +123,9 @@ def test_shared_test_case(): assert indices == list(sorted(indices)), 'Elements were found out of order' +@mock.patch.object( + botocore.useragent, 'modify_components', unmodified_components +) def test_user_agent_string_with_missing_information(): # Even when collecting information from the environment fails completely, # some minimal string should be generated.