Skip to content

Commit

Permalink
Revert "User Agent 2.0 (#2955)"
Browse files Browse the repository at this point in the history
This reverts commit e5d52ae.
  • Loading branch information
jonemo committed Jun 27, 2023
1 parent e5d52ae commit 8bbda59
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 1,060 deletions.
5 changes: 0 additions & 5 deletions .changes/next-release/enhancement-Useragent-93485.json

This file was deleted.

46 changes: 11 additions & 35 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from botocore.regions import EndpointResolverBuiltins as EPRBuiltins
from botocore.regions import EndpointRulesetResolver
from botocore.signers import RequestSigner
from botocore.useragent import UserAgentString
from botocore.utils import ensure_boolean, is_s3_accelerate_url

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -56,9 +55,6 @@
'us-west-1',
'us-west-2',
]
# Maximum allowed length of the ``user_agent_appid`` config field. Longer
# values result in a warning-level log message.
USERAGENT_APPID_MAXLEN = 50


class ClientArgsCreator:
Expand All @@ -70,17 +66,13 @@ def __init__(
loader,
exceptions_factory,
config_store,
user_agent_creator=None,
):
self._event_emitter = event_emitter
self._user_agent = user_agent
self._response_parser_factory = response_parser_factory
self._loader = loader
self._exceptions_factory = exceptions_factory
self._config_store = config_store
if user_agent_creator is None:
self._session_ua_creator = UserAgentString.from_environment()
else:
self._session_ua_creator = user_agent_creator

def get_client_args(
self,
Expand Down Expand Up @@ -167,11 +159,6 @@ def get_client_args(
event_emitter,
)

# Copy the session's user agent factory and adds client configuration.
client_ua_creator = self._session_ua_creator.with_client_config(
new_config
)

return {
'serializer': serializer,
'endpoint': endpoint,
Expand All @@ -184,7 +171,6 @@ def get_client_args(
'partition': partition,
'exceptions_factory': self._exceptions_factory,
'endpoint_ruleset_resolver': ruleset_resolver,
'user_agent_creator': client_ua_creator,
}

def compute_client_args(
Expand All @@ -207,6 +193,14 @@ def compute_client_args(
if raw_value is not None:
parameter_validation = ensure_boolean(raw_value)

# Override the user agent if specified in the client config.
user_agent = self._user_agent
if client_config is not None:
if client_config.user_agent is not None:
user_agent = client_config.user_agent
if client_config.user_agent_extra is not None:
user_agent += ' %s' % client_config.user_agent_extra

s3_config = self.compute_s3_config(client_config)
endpoint_config = self._compute_endpoint_config(
service_name=service_name,
Expand All @@ -223,6 +217,7 @@ def compute_client_args(
config_kwargs = dict(
region_name=endpoint_config['region_name'],
signature_version=endpoint_config['signature_version'],
user_agent=user_agent,
)
if 'dualstack' in endpoint_variant_tags:
config_kwargs.update(use_dualstack_endpoint=True)
Expand All @@ -239,13 +234,9 @@ def compute_client_args(
client_cert=client_config.client_cert,
inject_host_prefix=client_config.inject_host_prefix,
tcp_keepalive=client_config.tcp_keepalive,
user_agent=client_config.user_agent,
user_agent_extra=client_config.user_agent_extra,
user_agent_appid=client_config.user_agent_appid,
)
self._compute_retry_config(config_kwargs)
self._compute_connect_timeout(config_kwargs)
self._compute_user_agent_appid_config(config_kwargs)
s3_config = self.compute_s3_config(client_config)

is_s3_service = self._is_s3_service(service_name)
Expand All @@ -258,6 +249,7 @@ def compute_client_args(
return {
'service_name': service_name,
'parameter_validation': parameter_validation,
'user_agent': user_agent,
'endpoint_config': endpoint_config,
'protocol': protocol,
'config_kwargs': config_kwargs,
Expand Down Expand Up @@ -654,19 +646,3 @@ def compute_endpoint_resolver_builtin_defaults(
),
EPRBuiltins.SDK_ENDPOINT: given_endpoint,
}

def _compute_user_agent_appid_config(self, config_kwargs):
user_agent_appid = config_kwargs.get('user_agent_appid')
if user_agent_appid is None:
user_agent_appid = self._config_store.get_config_variable(
'user_agent_appid'
)
if (
user_agent_appid is not None
and len(user_agent_appid) > USERAGENT_APPID_MAXLEN
):
logger.warning(
'The configured value for user_agent_appid exceeds the '
f'maximum length of {USERAGENT_APPID_MAXLEN} characters.'
)
config_kwargs['user_agent_appid'] = user_agent_appid
14 changes: 1 addition & 13 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from botocore.model import ServiceModel
from botocore.paginate import Paginator
from botocore.retries import adaptive, standard
from botocore.useragent import UserAgentString
from botocore.utils import (
CachedProperty,
EventbridgeSignerSetter,
Expand Down Expand Up @@ -92,7 +91,6 @@ def __init__(
response_parser_factory=None,
exceptions_factory=None,
config_store=None,
user_agent_creator=None,
):
self._loader = loader
self._endpoint_resolver = endpoint_resolver
Expand All @@ -107,7 +105,6 @@ def __init__(
# config and environment variables (and potentially more in the
# future).
self._config_store = config_store
self._user_agent_creator = user_agent_creator

def create_client(
self,
Expand Down Expand Up @@ -484,7 +481,6 @@ def _get_client_args(
self._loader,
self._exceptions_factory,
config_store=self._config_store,
user_agent_creator=self._user_agent_creator,
)
return args_creator.get_client_args(
service_model,
Expand Down Expand Up @@ -844,7 +840,6 @@ def __init__(
partition,
exceptions_factory,
endpoint_ruleset_resolver=None,
user_agent_creator=None,
):
self._serializer = serializer
self._endpoint = endpoint
Expand All @@ -864,13 +859,6 @@ def __init__(
)
self._exceptions_factory = exceptions_factory
self._exceptions = None
self._user_agent_creator = user_agent_creator
if self._user_agent_creator is None:
self._user_agent_creator = (
UserAgentString.from_environment().with_client_config(
self._client_config
)
)
self._register_handlers()

def __getattr__(self, item):
Expand Down Expand Up @@ -1008,7 +996,7 @@ def _convert_to_request_dict(
if headers is not None:
request_dict['headers'].update(headers)
if set_user_agent_header:
user_agent = self._user_agent_creator.to_string()
user_agent = self._client_config.user_agent
else:
user_agent = None
prepare_request_dict(
Expand Down
7 changes: 0 additions & 7 deletions botocore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ class Config:
:param user_agent_extra: The value to append to the current User-Agent
header value.
:type user_agent_appid: str
:param user_agent_appid: A value that gets included in the User-Agent
string in the format "app/<user_agent_appid>". Allowed characters are
ASCII alphanumerics and ``!$%&'*+-.^_`|~``. All other characters will
be replaced by a ``-``.
:type connect_timeout: float or int
:param connect_timeout: The time in seconds till a timeout exception is
thrown when attempting to make a connection. The default is 60
Expand Down Expand Up @@ -207,7 +201,6 @@ class Config:
('signature_version', None),
('user_agent', None),
('user_agent_extra', None),
('user_agent_appid', None),
('connect_timeout', DEFAULT_TIMEOUT),
('read_timeout', DEFAULT_TIMEOUT),
('parameter_validation', True),
Expand Down
1 change: 0 additions & 1 deletion botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
# We can't have a default here for v1 because we need to defer to
# whatever the defaults are in _retry.json.
'max_attempts': ('max_attempts', 'AWS_MAX_ATTEMPTS', None, int),
'user_agent_appid': ('sdk_ua_app_id', 'AWS_SDK_UA_APP_ID', None, None),
}
# A mapping for the s3 specific configuration vars. These are the configuration
# vars that typically go in the s3 section of the config file. This mapping
Expand Down
27 changes: 6 additions & 21 deletions botocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,12 @@
from botocore.model import ServiceModel
from botocore.parsers import ResponseParserFactory
from botocore.regions import EndpointResolver
from botocore.useragent import UserAgentString
from botocore.utils import (
EVENT_ALIASES,
IMDSRegionProvider,
validate_region_name,
)

from botocore.compat import HAS_CRT # noqa


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -169,7 +165,6 @@ def _register_components(self):
self._register_monitor()
self._register_default_config_resolver()
self._register_smart_defaults_factory()
self._register_user_agent_creator()

def _register_event_emitter(self):
self._components.register_component('event_emitter', self._events)
Expand Down Expand Up @@ -268,10 +263,6 @@ def _register_monitor(self):
'monitor', self._create_csm_monitor
)

def _register_user_agent_creator(self):
uas = UserAgentString.from_environment()
self._components.register_component('user_agent_creator', uas)

def _create_csm_monitor(self):
if self.get_config_variable('csm_enabled'):
client_id = self.get_config_variable('csm_client_id')
Expand All @@ -292,8 +283,12 @@ def _create_csm_monitor(self):
return None

def _get_crt_version(self):
user_agent_creator = self.get_component('user_agent_creator')
return user_agent_creator._crt_version or 'Unknown'
try:
import awscrt

return awscrt.__version__
except AttributeError:
return "Unknown"

@property
def available_profiles(self):
Expand Down Expand Up @@ -958,15 +953,6 @@ def create_client(
endpoint_resolver = self._get_internal_component('endpoint_resolver')
exceptions_factory = self._get_internal_component('exceptions_factory')
config_store = self.get_component('config_store')
user_agent_creator = self.get_component('user_agent_creator')
# Session configuration values for the user agent string are applied
# just before each client creation because they may have been modified
# at any time between session creation and client creation.
user_agent_creator.set_session_config(
session_user_agent_name=self.user_agent_name,
session_user_agent_version=self.user_agent_version,
session_user_agent_extra=self.user_agent_extra,
)
defaults_mode = self._resolve_defaults_mode(config, config_store)
if defaults_mode != 'legacy':
smart_defaults_factory = self._get_internal_component(
Expand All @@ -986,7 +972,6 @@ def create_client(
response_parser_factory,
exceptions_factory,
config_store,
user_agent_creator=user_agent_creator,
)
client = client_creator.create_client(
service_name=service_name,
Expand Down
Loading

0 comments on commit 8bbda59

Please sign in to comment.