summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-01-20 18:04:21 -0800
committerMonty Taylor <mordred@inaugust.com>2015-01-21 07:52:43 -0800
commit621a8636f505dd5c091a7fa8155ea79dc36b1b41 (patch)
tree71c0c752ee2dbc9137e2ace8c00eeef4f90d7c82
parent0c2662bd068b1da0cc60e4b3b2808c8cbf5322ca (diff)
downloados-client-config-621a8636f505dd5c091a7fa8155ea79dc36b1b41.tar.gz
Replace defaults_dict with scanning env vars
All of the OS_ env vars start with OS_. Also, because of keystoneclient auth plugins, we have no idea which ones we need. Instead of positively identifying them - just grab them all - since they're all base layer and can be overridden by everything else anyway. Change-Id: I633f5e7d27c0a6a5c9b25f53cb99fe05b63c78ae
-rw-r--r--os_client_config/config.py30
-rw-r--r--os_client_config/defaults_dict.py27
2 files changed, 10 insertions, 47 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 9656f6c..9c3ca87 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -18,7 +18,6 @@ import os
import yaml
from os_client_config import cloud_config
-from os_client_config import defaults_dict
from os_client_config import exceptions
from os_client_config import vendors
@@ -44,31 +43,22 @@ def get_boolean(value):
return False
+def _get_os_environ():
+ ret = dict()
+ for (k, v) in os.environ.items():
+ if k.startswith('OS_'):
+ newkey = k[3:].lower()
+ ret[newkey] = v
+ return ret
+
+
class OpenStackConfig(object):
def __init__(self, config_files=None, vendor_files=None):
self._config_files = config_files or CONFIG_FILES
self._vendor_files = vendor_files or VENDOR_FILES
- defaults = defaults_dict.DefaultsDict()
- defaults.add('username')
- defaults.add('user_domain_name')
- defaults.add('password')
- defaults.add(
- 'project_name', defaults.get('username', None),
- also='tenant_name')
- defaults.add('project_id', also='tenant_id')
- defaults.add('project_domain_name')
- defaults.add('auth_url')
- defaults.add('region_name')
- defaults.add('cache')
- defaults.add('auth_token')
- defaults.add('insecure')
- defaults.add('endpoint_type')
- defaults.add('cacert')
- defaults.add('auth_type')
-
- self.defaults = defaults
+ self.defaults = _get_os_environ()
# use a config file if it exists where expected
self.cloud_config = self._load_config_file()
diff --git a/os_client_config/defaults_dict.py b/os_client_config/defaults_dict.py
deleted file mode 100644
index 43de77b..0000000
--- a/os_client_config/defaults_dict.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import os
-
-
-class DefaultsDict(dict):
-
- def add(self, key, default_value=None, also=None, prefix=None):
- if prefix:
- key = '%s_%s' % (prefix.replace('-', '_'), key)
- if also:
- value = os.environ.get(also, default_value)
- value = os.environ.get('OS_%s' % key.upper(), default_value)
- if value is not None:
- self.__setitem__(key, value)