Allow proxy_server use for chart tarball downloads

Currently the chart `source` schema allows for a proxy server to be
specified, but it is only used for git repos. This patchset allows
the `proxy_server` to also be used for tarball url sources.

Change-Id: I6f90d056fa46f596b1fb248b6c596c58b6513d64
This commit is contained in:
Sphicas, Phil (ps3910) 2019-09-17 01:24:02 -07:00
parent fd45cff385
commit 087eef4e7e
2 changed files with 20 additions and 9 deletions

View File

@ -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)

View File

@ -113,21 +113,28 @@ 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)