Skip to content

Commit

Permalink
Don't pop from os.environ
Browse files Browse the repository at this point in the history
It's rude to other users and subsequent callers.

Change-Id: I7789f381c99311bfd1c1e0a9869cbacbc96b17d6
  • Loading branch information
mdbooth authored and emonty committed May 25, 2017
1 parent 4493871 commit 990cfa3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions os_client_config/config.py
Expand Up @@ -106,9 +106,12 @@ def _get_os_environ(envvar_prefix=None):
for k in environkeys:
newkey = k.split('_', 1)[-1].lower()
ret[newkey] = os.environ[k]
# If the only environ keys are cloud and region_name, don't return anything
# because they are cloud selectors
if set(environkeys) - set(['OS_CLOUD', 'OS_REGION_NAME']):
# If the only environ keys are selectors or behavior modification, don't
# return anything
selectors = set([
'OS_CLOUD', 'OS_REGION_NAME',
'OS_CLIENT_CONFIG_FILE', 'OS_CLIENT_SECURE_FILE', 'OS_CLOUD_NAME'])
if set(environkeys) - selectors:
return ret
return None

Expand Down Expand Up @@ -193,11 +196,11 @@ def __init__(self, config_files=None, vendor_files=None,
self._secure_files = []
self._vendor_files = []

config_file_override = os.environ.pop('OS_CLIENT_CONFIG_FILE', None)
config_file_override = os.environ.get('OS_CLIENT_CONFIG_FILE')
if config_file_override:
self._config_files.insert(0, config_file_override)

secure_file_override = os.environ.pop('OS_CLIENT_SECURE_FILE', None)
secure_file_override = os.environ.get('OS_CLIENT_SECURE_FILE')
if secure_file_override:
self._secure_files.insert(0, secure_file_override)

Expand Down Expand Up @@ -226,12 +229,12 @@ def __init__(self, config_files=None, vendor_files=None,
else:
# Get the backwards compat value
prefer_ipv6 = get_boolean(
os.environ.pop(
os.environ.get(
'OS_PREFER_IPV6', client_config.get(
'prefer_ipv6', client_config.get(
'prefer-ipv6', True))))
force_ipv4 = get_boolean(
os.environ.pop(
os.environ.get(
'OS_FORCE_IPV4', client_config.get(
'force_ipv4', client_config.get(
'broken-ipv6', False))))
Expand All @@ -243,17 +246,16 @@ def __init__(self, config_files=None, vendor_files=None,
self.force_ipv4 = True

# Next, process environment variables and add them to the mix
self.envvar_key = os.environ.pop('OS_CLOUD_NAME', 'envvars')
self.envvar_key = os.environ.get('OS_CLOUD_NAME', 'envvars')
if self.envvar_key in self.cloud_config['clouds']:
raise exceptions.OpenStackConfigException(
'"{0}" defines a cloud named "{1}", but'
' OS_CLOUD_NAME is also set to "{1}". Please rename'
' either your environment based cloud, or one of your'
' file-based clouds.'.format(self.config_filename,
self.envvar_key))
# Pull out OS_CLOUD so that if it's the only thing set, do not
# make an envvars cloud
self.default_cloud = os.environ.pop('OS_CLOUD', None)

self.default_cloud = os.environ.get('OS_CLOUD')

envvars = _get_os_environ(envvar_prefix=envvar_prefix)
if envvars:
Expand Down

0 comments on commit 990cfa3

Please sign in to comment.