From 42656bbc176a8de38fb29c6e3fe5f5fd525b1190 Mon Sep 17 00:00:00 2001 From: "Sphicas, Phil (ps3910)" Date: Tue, 17 Sep 2019 01:24:02 -0700 Subject: [PATCH] TEST - Use proxy for tar chart sources Change-Id: I6f90d056fa46f596b1fb248b6c596c58b6513d64 --- armada/handlers/armada.py | 12 ++++++++---- armada/utils/source.py | 14 +++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/armada/handlers/armada.py b/armada/handlers/armada.py index 471b839f..d1bb8604 100644 --- a/armada/handlers/armada.py +++ b/armada/handlers/armada.py @@ -122,6 +122,7 @@ class Armada(object): location = chart_source.get('location') ct_type = chart_source.get('type') subpath = chart_source.get('subpath', '.') + proxy_server = chart_source.get('proxy_server') if ct_type == 'local': chart['source_dir'] = (location, subpath) @@ -129,15 +130,19 @@ class Armada(object): source_key = (ct_type, location) if source_key not in self.chart_cache: - LOG.info('Downloading tarball from: %s', location) + logstr = 'Downloading tarball from: {}'.format(location) + if proxy_server: + logstr += ' proxy: {}'.format(proxy_server) + LOG.info(logstr) if not CONF.certs: LOG.warn( 'Disabling server validation certs to extract charts') - tarball_dir = source.get_tarball(location, verify=False) + tarball_dir = source.get_tarball(location, verify=False, + proxy_server=proxy_server) else: tarball_dir = source.get_tarball( - location, verify=CONF.certs) + location, verify=CONF.certs, proxy_server=proxy_server) self.chart_cache[source_key] = tarball_dir chart['source_dir'] = (self.chart_cache.get(source_key), subpath) elif ct_type == 'git': @@ -146,7 +151,6 @@ class Armada(object): if source_key not in self.chart_cache: auth_method = chart_source.get('auth_method') - proxy_server = chart_source.get('proxy_server') logstr = 'Cloning repo: {} from branch: {}'.format( location, reference) diff --git a/armada/utils/source.py b/armada/utils/source.py index 31120fe3..4da649bb 100644 --- a/armada/utils/source.py +++ b/armada/utils/source.py @@ -113,21 +113,25 @@ def git_clone(repo_url, ref='master', proxy_server=None, auth_method=None): return temp_dir -def get_tarball(tarball_url, verify=False): - tarball_path = download_tarball(tarball_url, verify=verify) +def get_tarball(tarball_url, verify=False, proxy_server=None): + tarball_path = download_tarball(tarball_url, verify=verify, + proxy_server=proxy_server) return extract_tarball(tarball_path) -def download_tarball(tarball_url, verify=False): +def download_tarball(tarball_url, verify=False, proxy_server=None): ''' Downloads a tarball to /tmp and returns the path ''' try: if not verify: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - + kwargs = {} + if proxy_server: + kwargs['proxies'] = { 'http': proxy_server, 'https': proxy_server, + 'ftp': proxy_server } tarball_filename = tempfile.mkstemp(prefix='armada')[1] - response = requests.get(tarball_url, verify=verify) + response = requests.get(tarball_url, verify=verify, **kwargs) with open(tarball_filename, 'wb') as f: f.write(response.content)