Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Jun 13, 2023
1 parent 5a3ba2b commit 659df5e
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 208 deletions.
5 changes: 2 additions & 3 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def get_client_args(
client_cert=new_config.client_cert,
proxies_config=new_config.proxies_config,
)

serializer = botocore.serialize.create_serializer(
protocol, parameter_validation
)
Expand Down Expand Up @@ -271,9 +272,7 @@ def _compute_configured_endpoint_url(self, client_config, endpoint_url):
):
return endpoint_url

return self._config_store.get_config_variable(
'configured_endpoint_url'
)
return self._config_store.get_config_variable('endpoint_url')

def _ignore_configured_endpoint_urls(self, client_config):
if (
Expand Down
38 changes: 18 additions & 20 deletions botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,8 @@ def __init__(
for the current profile for the session.
:type client_name: str
:param client_name: client name.
:param client_name: The name used to instantiate a client using
botocore.session.Session.create_client.
:type environ: dict
:param environ: A mapping to use for environment variables. If this
Expand Down Expand Up @@ -940,26 +941,23 @@ def provide(self):
logger.debug('No configured endpoint found.')
return None

def unhyphenize_service_name(self, service_name):
return service_name.replace('-', ' ')

def _get_service_id(self, client_name):
client_name = utils.handle_service_name_alias(client_name)

client_name = (
utils._CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES.get(
client_name, client_name
)
def _get_snake_case_service_id(self, client_name):
# Use lookups to get the serice ID without loading the service data
# file. `client_name`` refers to the name used to instantiate a client
# through botocore.session.Session.create_client (parameter name there
# is `service_name`). We need to look up services that have been
# renamed (SERVICE_NAME_ALIASES) as well as services that do not use
# the service ID as their data directory name
# (CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES).
client_name = utils.SERVICE_NAME_ALIASES.get(client_name, client_name)
service_id = utils.CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES.get(
client_name, client_name
)

return self.unhyphenize_service_name(client_name)

def _snakecase_service_id(self, service_id):
return service_id.replace(' ', '_')
return service_id.replace('-', '_')

def _get_service_env_var_name(self):
transformed_service_id_env = self._snakecase_service_id(
self._get_service_id(self._client_name)
transformed_service_id_env = self._get_snake_case_service_id(
self._client_name
).upper()
return f'AWS_ENDPOINT_URL_{transformed_service_id_env}'

Expand All @@ -983,8 +981,8 @@ def _get_services_config(self):
return services_section

def _get_endpoint_url_config_service(self):
snakecase_service_id = self._snakecase_service_id(
self._get_service_id(self._client_name)
snakecase_service_id = self._get_snake_case_service_id(
self._client_name
).lower()
return (
self._get_services_config()
Expand Down
5 changes: 4 additions & 1 deletion botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
SAFE_CHARS,
ArnParser,
conditionally_calculate_md5,
handle_service_name_alias,
percent_encode,
switch_host_with_param,
)
Expand Down Expand Up @@ -102,6 +101,10 @@
VERSION_ID_SUFFIX = re.compile(r'\?versionId=[^\s]+$')


def handle_service_name_alias(service_name, **kwargs):
return SERVICE_NAME_ALIASES.get(service_name, service_name)


def add_recursion_detection_header(params, **kwargs):
has_lambda_name = 'AWS_LAMBDA_FUNCTION_NAME' in os.environ
trace_id = os.environ.get('_X_AMZN_TRACE_ID')
Expand Down
2 changes: 1 addition & 1 deletion botocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ def _add_configured_endpoint_provider(self, client_name, config_store):
client_name=client_name,
)
config_store.set_config_provider(
logical_name='configured_endpoint_url',
logical_name='endpoint_url',
provider=chain,
)

Expand Down
16 changes: 9 additions & 7 deletions botocore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3317,18 +3317,20 @@ def _serialize_if_needed(self, value, iso=False):
return value


# This parameter is not part of the public interface and is subject to abrupt
# breaking changes or removal without prior announcement.
# Mapping of services that have been renamed for backwards compatibility reasons.
# Keys are the previous name that should be allowed, values are the transformed
# service IDs (lower case and hyphenated) used as the data directory name.
SERVICE_NAME_ALIASES = {'runtime.sagemaker': 'sagemaker-runtime'}


def handle_service_name_alias(service_name, **kwargs):
return SERVICE_NAME_ALIASES.get(service_name, service_name)


# This parameter is not part of the public interface and is subject to abrupt
# breaking changes or removal without prior announcement.
# Mapping to determine the service ID for services that do not use it as the
# model data directory name. The keys are the data directory name and the
# values are the service IDs. This parameter is considered private and is
# subject to abrupt breaking changes or removal without prior announcement.
_CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES = {
# values are the transformed service IDs (lower case and hyphenated).
CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES = {
# Actual service name we use -> Allowed computed service name.
'alexaforbusiness': 'alexa-for-business',
'apigateway': 'api-gateway',
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest

from botocore.session import get_session
from botocore.utils import _CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES
from botocore.utils import CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES

ENDPOINT_PREFIX_OVERRIDE = {
# entry in endpoints.json -> actual endpoint prefix.
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_client_name_matches_hyphenized_service_id(service_name):

# Handle known exceptions where we have renamed the service directory
# for one reason or another.
actual_service_name = _CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES.get(
actual_service_name = CLIENT_NAME_TO_HYPHENIZED_SERVICE_ID_OVERRIDES.get(
service_name, service_name
)

Expand Down
1 change: 0 additions & 1 deletion tests/unit/cfg/aws_services_config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ services = my-services
[services my-services]
s3 =
endpoint_url = https://localhost:5678/
addressing_style = path
dynamodb =
endpoint_url = https://localhost:8888/
6 changes: 3 additions & 3 deletions tests/unit/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ def setup_client(self):
],
}

def load_service_mock(service_name, type_name, api_version=None):
if type_name == "endpoint-rule-set-1":
def load_service_mock(*args, **kwargs):
if args[1] == "endpoint-rule-set-1":
return myservice_endpoint_rule_set
else:
return Loader(
extra_search_paths=[self.root_dir]
).load_service_model(service_name, type_name, api_version)
).load_service_model(*args, **kwargs)

self.loader = Loader(extra_search_paths=[self.root_dir])
self.loader.load_service_model = mock.Mock()
Expand Down
Loading

0 comments on commit 659df5e

Please sign in to comment.