# Path: armada/exceptions/source_exceptions.py
# class InvalidPathException(SourceException):
#     '''
#     Exception that occurs when a nonexistant path is accessed.
# 
#     **Troubleshoot:**
#     *Coming Soon*
#     '''
# 
#     def __init__(self, path):
#         self._path = path
#         self._message = 'Unable to access path ' + self._path
# 
#         super(InvalidPathException, self).__init__(self._message)
# 
# Path: armada/utils/keystone.py
# class KeystoneUtils(object):
#     """Utility methods for using Keystone."""
# 
#     @staticmethod
#     def get_session():
#         """Get an initialized keystone session.
# 
#         Authentication is based on the keystone_authtoken
#         section of the config file primarily. If that fails
#         then attempt to create a session from environmental
#         variables. This is for cases of the CLI needing
#         a token.
#         """
#         auth_info = dict()
#         auth_fields = ['auth_url', 'username', 'password', 'project_id',
#                        'user_domain_name']
#         try:
#             for f in auth_fields:
#                 auth_info[f] = getattr(CONF.keystone_authtoken, f)
#             auth = v3.Password(**auth_info)
#             ks_session = session.Session(auth=auth)
#             # Test the session
#             ks_session.get_auth_headers()
#         except Exception:  # nosec this isn't a security issue
#             pass
#         else:
#             return ks_session
# 
#         try:
#             for f in auth_fields:
#                 auth_info[f] = os.environ.get('os_{}'.format(f).upper())
#             auth = v3.Password(**auth_info)
#             ks_session = session.Session(auth=auth)
#             # Test the session
#             ks_session.get_auth_headers()
#         except Exception:
#             raise Exception('Missing credential information for Keystone.')
# 
#         return ks_session


import urllib.parse
import re
import requests
from oslo_log import log as logging
from armada.exceptions.source_exceptions import InvalidPathException
from armada.utils.keystone import KeystoneUtils
        """Retrieve design documents from local file endpoints.

        Return a byte array of the file contents

        :param design_uri: Tuple as returned by urllib.parse for the design
                           reference
        """
        if design_uri.path != '':
            with open(design_uri.path, 'rb') as f:
                doc = f.read()
            return doc

    @classmethod
    def resolve_reference_ucp(cls, design_uri):
        """Retrieve artifacts from a UCP service endpoint.

        Return a byte array of the response content. Assumes Keystone
        authentication required.

        :param design_uri: Tuple as returned by urllib.parse for the design
                           reference
        """
        ks_sess = KeystoneUtils.get_session()
        (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme)
        url = urllib.parse.urlunparse(
            (new_scheme, design_uri.netloc, design_uri.path, design_uri.params,
             design_uri.query, design_uri.fragment))
        LOG.debug("Calling Keystone session for url %s" % str(url))
        resp = ks_sess.get(url)
        if resp.status_code >= 400:

# Path: armada/exceptions/source_exceptions.py
# class InvalidPathException(SourceException):
#     '''
#     Exception that occurs when a nonexistant path is accessed.
# 
#     **Troubleshoot:**
#     *Coming Soon*
#     '''
# 
#     def __init__(self, path):
#         self._path = path
#         self._message = 'Unable to access path ' + self._path
# 
#         super(InvalidPathException, self).__init__(self._message)
# 
# Path: armada/utils/keystone.py
# class KeystoneUtils(object):
#     """Utility methods for using Keystone."""
# 
#     @staticmethod
#     def get_session():
#         """Get an initialized keystone session.
# 
#         Authentication is based on the keystone_authtoken
#         section of the config file primarily. If that fails
#         then attempt to create a session from environmental
#         variables. This is for cases of the CLI needing
#         a token.
#         """
#         auth_info = dict()
#         auth_fields = ['auth_url', 'username', 'password', 'project_id',
#                        'user_domain_name']
#         try:
#             for f in auth_fields:
#                 auth_info[f] = getattr(CONF.keystone_authtoken, f)
#             auth = v3.Password(**auth_info)
#             ks_session = session.Session(auth=auth)
#             # Test the session
#             ks_session.get_auth_headers()
#         except Exception:  # nosec this isn't a security issue
#             pass
#         else:
#             return ks_session
# 
#         try:
#             for f in auth_fields:
#                 auth_info[f] = os.environ.get('os_{}'.format(f).upper())
#             auth = v3.Password(**auth_info)
#             ks_session = session.Session(auth=auth)
#             # Test the session
#             ks_session.get_auth_headers()
#         except Exception:
#             raise Exception('Missing credential information for Keystone.')
# 
#         return ks_session


# Path: armada/handlers/document.py
import urllib.parse
import re
import requests
from oslo_log import log as logging
from armada.exceptions.source_exceptions import InvalidPathException
from armada.utils.keystone import KeystoneUtils

        """Retrieve design documents from local file endpoints.

        Return a byte array of the file contents

        :param design_uri: Tuple as returned by urllib.parse for the design
                           reference
        """
        if design_uri.path != '':
            with open(design_uri.path, 'rb') as f:
                doc = f.read()
            return doc

    @classmethod
    def resolve_reference_ucp(cls, design_uri):
        """Retrieve artifacts from a UCP service endpoint.

        Return a byte array of the response content. Assumes Keystone
        authentication required.

        :param design_uri: Tuple as returned by urllib.parse for the design
                           reference
        """
        ks_sess = KeystoneUtils.get_session()
        (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme)
        url = urllib.parse.urlunparse(
            (new_scheme, design_uri.netloc, design_uri.path, design_uri.params,
             design_uri.query, design_uri.fragment))
        LOG.debug("Calling Keystone session for url %s" % str(url))
        resp = ks_sess.get(url)
        if resp.status_code >= 400:

            raise InvalidPathException(