# Path: armada/exceptions/source_exceptions.py
# class SourceException(base_exception.ArmadaBaseException):
# class GitException(SourceException):
# class GitAuthException(SourceException):
# class GitProxyException(SourceException):
# class GitSSHException(SourceException):
# class SourceCleanupException(SourceException):
# class TarballDownloadException(SourceException):
# class TarballExtractException(SourceException):
# class InvalidPathException(SourceException):
# class ChartSourceException(SourceException):
#     def __init__(self, location):
#     def __init__(self, repo_url, ssh_key_path):
#     def __init__(self, location):
#     def __init__(self, ssh_key_path):
#     def __init__(self, target_dir):
#     def __init__(self, tarball_url):
#     def __init__(self, tarball_dir):
#     def __init__(self, path):
#     def __init__(self, chart_name, source_type):


import os
import shutil
import tarfile
import tempfile
import requests
from git import exc as git_exc
from git import Git
from git import Repo
from oslo_config import cfg
from oslo_log import log as logging
from requests.packages import urllib3
from armada.exceptions import source_exceptions
                      'the SSH key under CONF.ssh_key_path was not found.')
            raise source_exceptions.GitSSHException(CONF.ssh_key_path)

        ssh_cmd = (
            'ssh -i {} -o ConnectionAttempts=20 -o ConnectTimeout=10'
            .format(os.path.expanduser(CONF.ssh_key_path))
        )
        env_vars.update({'GIT_SSH_COMMAND': ssh_cmd})
    else:
        LOG.debug('Attempting to clone the repo at %s using reference %s '
                  'with no authentication.', repo_url, ref)

    try:
        if proxy_server:
            LOG.debug('Cloning [%s] with proxy [%s]', repo_url, proxy_server)
            repo = Repo.clone_from(repo_url, temp_dir, env=env_vars,
                                   config='http.proxy=%s' % proxy_server)
        else:
            LOG.debug('Cloning [%s]', repo_url)
            repo = Repo.clone_from(repo_url, temp_dir, env=env_vars)

        repo.remotes.origin.fetch(ref)
        g = Git(repo.working_dir)
        g.checkout('FETCH_HEAD')
    except git_exc.GitCommandError as e:
        LOG.exception('Encountered GitCommandError during clone.')
        if ssh_cmd and ssh_cmd in e.stderr:
            raise source_exceptions.GitAuthException(repo_url,
                                                     CONF.ssh_key_path)
        elif 'Could not resolve proxy' in e.stderr:

# Path: armada/exceptions/source_exceptions.py
# class SourceException(base_exception.ArmadaBaseException):
# class GitException(SourceException):
# class GitAuthException(SourceException):
# class GitProxyException(SourceException):
# class GitSSHException(SourceException):
# class SourceCleanupException(SourceException):
# class TarballDownloadException(SourceException):
# class TarballExtractException(SourceException):
# class InvalidPathException(SourceException):
# class ChartSourceException(SourceException):
#     def __init__(self, location):
#     def __init__(self, repo_url, ssh_key_path):
#     def __init__(self, location):
#     def __init__(self, ssh_key_path):
#     def __init__(self, target_dir):
#     def __init__(self, tarball_url):
#     def __init__(self, tarball_dir):
#     def __init__(self, path):
#     def __init__(self, chart_name, source_type):


# Path: armada/utils/source.py
import os
import shutil
import tarfile
import tempfile
import requests
from git import exc as git_exc
from git import Git
from git import Repo
from oslo_config import cfg
from oslo_log import log as logging
from requests.packages import urllib3
from armada.exceptions import source_exceptions

                      'the SSH key under CONF.ssh_key_path was not found.')
            raise source_exceptions.GitSSHException(CONF.ssh_key_path)

        ssh_cmd = (
            'ssh -i {} -o ConnectionAttempts=20 -o ConnectTimeout=10'
            .format(os.path.expanduser(CONF.ssh_key_path))
        )
        env_vars.update({'GIT_SSH_COMMAND': ssh_cmd})
    else:
        LOG.debug('Attempting to clone the repo at %s using reference %s '
                  'with no authentication.', repo_url, ref)

    try:
        if proxy_server:
            LOG.debug('Cloning [%s] with proxy [%s]', repo_url, proxy_server)
            repo = Repo.clone_from(repo_url, temp_dir, env=env_vars,
                                   config='http.proxy=%s' % proxy_server)
        else:
            LOG.debug('Cloning [%s]', repo_url)
            repo = Repo.clone_from(repo_url, temp_dir, env=env_vars)

        repo.remotes.origin.fetch(ref)
        g = Git(repo.working_dir)
        g.checkout('FETCH_HEAD')
    except git_exc.GitCommandError as e:
        LOG.exception('Encountered GitCommandError during clone.')
        if ssh_cmd and ssh_cmd in e.stderr:
            raise source_exceptions.GitAuthException(repo_url,
                                                     CONF.ssh_key_path)
        elif 'Could not resolve proxy' in e.stderr:

            raise source_exceptions.GitProxyException(proxy_server)