Add the ability to use env variables
Gives the user the ability to use env variables when using the client outside the shell Change-Id: I39b91f25370514cf445b76adba3b5b65256b69dd
This commit is contained in:
parent
984ccccb5a
commit
dfeecdd6f0
|
@ -19,4 +19,6 @@ from monascaclient.common import utils
|
|||
def Client(version, *args, **kwargs):
|
||||
module = utils.import_versioned_module(version, 'client')
|
||||
client_class = getattr(module, 'Client')
|
||||
if 'use_environment_variables' in kwargs and kwargs['use_environment_variables']:
|
||||
utils.set_env_variables(kwargs)
|
||||
return client_class(*args, **kwargs)
|
||||
|
|
|
@ -243,3 +243,25 @@ def format_list(in_list):
|
|||
key = k
|
||||
string_list.append(key)
|
||||
return '\n'.join(string_list)
|
||||
|
||||
|
||||
def set_env_variables(kwargs):
|
||||
environment_variables = {
|
||||
'username': 'OS_USERNAME',
|
||||
'password': 'OS_PASSWORD',
|
||||
'token': 'OS_AUTH_TOKEN',
|
||||
'auth_url': 'OS_AUTH_URL',
|
||||
'service_type': 'OS_SERVICE_TYPE',
|
||||
'endpoint_type': 'OS_ENDPOINT_TYPE',
|
||||
'os_cacert': 'OS_CACERT',
|
||||
'user_domain_id': 'OS_USER_DOMAIN_ID',
|
||||
'user_domain_name': 'OS_USER_DOMAIN_NAME',
|
||||
'project_id': 'OS_PROJECT_ID',
|
||||
'project_name': 'OS_PROJECT_NAME',
|
||||
'domain_id': 'OS_DOMAIN_ID',
|
||||
'domain_name': 'OS_DOMAIN_NAME',
|
||||
'region_name': 'OS_REGION_NAME'
|
||||
}
|
||||
for k, v in environment_variables.iteritems():
|
||||
if k not in kwargs:
|
||||
kwargs[k] = env(v)
|
||||
|
|
Loading…
Reference in New Issue