Skip to content

Commit

Permalink
move account_id_endpoint_mode validation to endpoint resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlm committed Aug 23, 2023
1 parent f0c0376 commit e73f6f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
26 changes: 0 additions & 26 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@
# Maximum allowed length of the ``user_agent_appid`` config field. Longer
# values result in a warning-level log message.
USERAGENT_APPID_MAXLEN = 50
# Allowed values for the ``account_id_endpoint_mode`` config field.
VALID_ACCOUNT_ID_ENDPOINT_MODES = [
'preferred',
'disabled',
'required',
]


class ClientArgsCreator:
Expand Down Expand Up @@ -281,7 +275,6 @@ def compute_client_args(
self._compute_connect_timeout(config_kwargs)
self._compute_user_agent_appid_config(config_kwargs)
self._compute_request_compression_config(config_kwargs)
self._compute_account_id_endpoint_mode(config_kwargs)
s3_config = self.compute_s3_config(client_config)

is_s3_service = self._is_s3_service(service_name)
Expand Down Expand Up @@ -782,22 +775,3 @@ def _compute_user_agent_appid_config(self, config_kwargs):
f'maximum length of {USERAGENT_APPID_MAXLEN} characters.'
)
config_kwargs['user_agent_appid'] = user_agent_appid

def _compute_account_id_endpoint_mode(self, config_kwargs):
act_id_ep_mode = config_kwargs.get('account_id_endpoint_mode')
if act_id_ep_mode is None:
act_id_ep_mode = self._config_store.get_config_variable(
'account_id_endpoint_mode'
)
if act_id_ep_mode is not None:
if act_id_ep_mode not in VALID_ACCOUNT_ID_ENDPOINT_MODES:
valid_modes_str = ', '.join(VALID_ACCOUNT_ID_ENDPOINT_MODES)
error_msg = (
f"Invalid value '{act_id_ep_mode}' for "
"account_id_endpoint_mode. Valid values are: "
f"{valid_modes_str}"
)
raise botocore.exceptions.InvalidConfigError(
error_msg=error_msg
)
config_kwargs['account_id_endpoint_mode'] = act_id_ep_mode
19 changes: 19 additions & 0 deletions botocore/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
AccountIDNotFound,
EndpointProviderError,
EndpointVariantError,
InvalidConfigError,
InvalidEndpointConfigurationError,
InvalidHostLabelError,
MissingDependencyException,
Expand All @@ -47,6 +48,12 @@
LOG = logging.getLogger(__name__)
DEFAULT_URI_TEMPLATE = '{service}.{region}.{dnsSuffix}' # noqa
DEFAULT_SERVICE_DATA = {'endpoints': {}}
# Allowed values for the ``account_id_endpoint_mode`` config field.
VALID_ACCOUNT_ID_ENDPOINT_MODES = [
'preferred',
'disabled',
'required',
]


class BaseEndpointResolver:
Expand Down Expand Up @@ -622,6 +629,8 @@ def _resolve_param_as_builtin(
return builtin_value

def _resolve_account_id_builtin(self, builtin, account_id_endpoint_mode):
self._validate_account_id_endpoint_mode(account_id_endpoint_mode)

if account_id_endpoint_mode == 'disabled':
return None

Expand All @@ -636,6 +645,16 @@ def _resolve_account_id_builtin(self, builtin, account_id_endpoint_mode):

return builtin_value

def _validate_account_id_endpoint_mode(account_id_endpoint_mode):
if account_id_endpoint_mode not in VALID_ACCOUNT_ID_ENDPOINT_MODES:
valid_modes_str = ', '.join(VALID_ACCOUNT_ID_ENDPOINT_MODES)
error_msg = (
f"Invalid value '{account_id_endpoint_mode}' for "
"account_id_endpoint_mode. Valid values are: "
f"{valid_modes_str}"
)
raise InvalidConfigError(error_msg=error_msg)

@instance_cache
def _get_static_context_params(self, operation_model):
"""Mapping of param names to static param value for an operation"""
Expand Down

0 comments on commit e73f6f7

Please sign in to comment.