-def source_credentials(rc_file):
- with open(rc_file, "r") as f:
- for line in f:
- var = line.rstrip('"\n').replace('export ', '').split("=")
- # The two next lines should be modified as soon as rc_file
- # conforms with common rules. Be aware that it could induce
- # issues if value starts with '
- key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
- value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
- os.environ[key] = value
-
-
-def get_credentials_for_rally():
- creds = get_credentials()
- env_cred_dict = get_env_cred_dict()
- rally_conf = {"type": "ExistingCloud", "admin": {}}
- for key in creds:
- if key == 'auth_url':
- rally_conf[key] = creds[key]
- else:
- rally_conf['admin'][key] = creds[key]
-
- endpoint_types = [('internalURL', 'internal'),
- ('publicURL', 'public'), ('adminURL', 'admin')]
-
- endpoint_type = get_endpoint_type_from_env()
- if endpoint_type is not None:
- cred_key = env_cred_dict.get('OS_ENDPOINT_TYPE')
- for k, v in endpoint_types:
- if endpoint_type == v:
- rally_conf[cred_key] = v
-
- region_name = os.getenv('OS_REGION_NAME')
- if region_name is not None:
- cred_key = env_cred_dict.get('OS_REGION_NAME')
- rally_conf[cred_key] = region_name
-
- cacert = os.getenv('OS_CACERT')
- if cacert is not None:
- cred_key = env_cred_dict.get('OS_CACERT')
- rally_conf[cred_key] = cacert
- return rally_conf
-
-
-def get_endpoint_type_from_env():
- endpoint_type = os.environ.get("OS_ENDPOINT_TYPE",
- os.environ.get("OS_INTERFACE"))
- if endpoint_type and "URL" in endpoint_type:
- endpoint_type = endpoint_type.replace("URL", "")
- return endpoint_type
-
-