Skip to content
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

Corrected typo without breaking backwards compatibility #3398

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions botocore/configprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"""

import copy
import inspect
import logging
import os
import re

from botocore import utils
from botocore.exceptions import InvalidConfigError
Expand Down Expand Up @@ -48,9 +50,7 @@
#: the ``env var`` is the OS environment variable (``os.environ``) to
#: use, and ``default_value`` is the value to use if no value is otherwise
#: found.
#: NOTE: Fixing the spelling of this variable would be a breaking change.
#: Please leave as is.
BOTOCORE_DEFAUT_SESSION_VARIABLES = {
BOTOCORE_DEFAULT_SESSION_VARIABLES = {
# logical: config_file, env_var, default_value, conversion_func
'profile': (None, ['AWS_DEFAULT_PROFILE', 'AWS_PROFILE'], None, None),
'region': ('region', 'AWS_DEFAULT_REGION', None, None),
Expand Down Expand Up @@ -200,8 +200,37 @@
None,
),
}
BOTOCORE_DEFAUT_SESSION_VARIABLES.update(_STS_DEFAULT_SETTINGS)
BOTOCORE_DEFAULT_SESSION_VARIABLES.update(_STS_DEFAULT_SETTINGS)

_BOTOCORE_DEFAUT_SESSION_VARIABLES_TEST_PATTERN = r'.*import.*BOTOCORE_DEFAUT_SESSION_VARIABLES.*'

def _warn_misspelling_deprecated():
"""Warns the user if importing BOTOCORE_DEFAUT_SESSION_VARIABLES in a named import. Below is a summary:

Will warn on:

- Named imports: from botocore.configprovider import BOTOCORE_DEFAUT_SESSION_VARIABLES

Will not warn on:

- Module imports: import botocore.configprovider

Use of BOTOCORE_DEFAUT_SESSION_VARIABLES remains functional due to pass by reference nature of dictionaries.
"""
# Grab the stack and go through frames in reverse order (imports are likely low on the stack)
for frame in inspect.stack()[::-1]:
if frame.code_context:
# Do a basic regex match on each line
for line in frame.code_context:
# If a named import is being used, warn the user of deprecation
if re.match(_BOTOCORE_DEFAUT_SESSION_VARIABLES_TEST_PATTERN, line):
logging.warning("BOTOCORE_DEFAUT_SESSION_VARIABLES as a named import is deprecated and will be removed in a future release. Use BOTOCORE_DEFAULT_SESSION_VARIABLES instead.")
# Don't inspect rest of stack and return
return BOTOCORE_DEFAULT_SESSION_VARIABLES
# Return the value with the correct name; remains mutable via pass by reference
return BOTOCORE_DEFAULT_SESSION_VARIABLES

BOTOCORE_DEFAUT_SESSION_VARIABLES=_warn_misspelling_deprecated()

# 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 Expand Up @@ -266,7 +295,7 @@
def create_botocore_default_config_mapping(session):
chain_builder = ConfigChainFactory(session=session)
config_mapping = _create_config_chain_mapping(
chain_builder, BOTOCORE_DEFAUT_SESSION_VARIABLES
chain_builder, BOTOCORE_DEFAULT_SESSION_VARIABLES
)
config_mapping['s3'] = SectionConfigProvider(
's3',
Expand Down
4 changes: 2 additions & 2 deletions botocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from botocore.compat import HAS_CRT, MutableMapping
from botocore.configprovider import (
BOTOCORE_DEFAUT_SESSION_VARIABLES,
BOTOCORE_DEFAULT_SESSION_VARIABLES,
ConfigChainFactory,
ConfiguredEndpointProvider,
ConfigValueStore,
Expand Down Expand Up @@ -89,7 +89,7 @@ class Session:
:ivar profile: The current profile.
"""

SESSION_VARIABLES = copy.copy(BOTOCORE_DEFAUT_SESSION_VARIABLES)
SESSION_VARIABLES = copy.copy(BOTOCORE_DEFAULT_SESSION_VARIABLES)

#: The default format string to use when configuring the botocore logger.
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
Expand Down