Modify config field to use base api endpoint

allow streaming from gzipped tarball config
This commit is contained in:
Sam Chow 2018-06-21 15:55:17 -04:00
parent aff1a08a83
commit d6d0bb640a
7 changed files with 40 additions and 33 deletions

View file

@ -36,8 +36,8 @@ class SuperUserCustomCertificate(ApiResource):
# Validate the certificate.
try:
logger.debug('Loading custom certificate %s', certpath)
cert = config_provider.get_volume_file(cert_full_path)
load_certificate(cert)
with config_provider.get_volume_file(cert_full_path) as f:
load_certificate(f.read())
except CertInvalidException:
logger.exception('Got certificate invalid error for cert %s', certpath)
return '', 204
@ -70,13 +70,14 @@ class SuperUserCustomCertificates(ApiResource):
cert_views = []
for extra_cert_path in extra_certs_found:
try:
cert = config_provider.get_volume_file(extra_cert_path)
certificate = load_certificate(cert)
cert_views.append({
'path': extra_cert_path,
'names': list(certificate.names),
'expired': certificate.expired,
})
cert_full_path = config_provider.get_volume_path(EXTRA_CA_DIRECTORY, extra_cert_path)
with config_provider.get_volume_file(cert_full_path) as f:
certificate = load_certificate(f.read())
cert_views.append({
'path': extra_cert_path,
'names': list(certificate.names),
'expired': certificate.expired,
})
except CertInvalidException as cie:
cert_views.append({
'path': extra_cert_path,

View file

@ -1,5 +1,4 @@
import tarfile
import cStringIO
from flask import request, make_response
@ -13,16 +12,12 @@ class TarConfigLoader(ApiResource):
""" Resource for validating a block of configuration against an external service. """
@nickname('uploadTarballConfig')
def post(self):
def put(self):
""" Loads tarball config into the config provider """
input_stream = request.stream
tar_stream = tarfile.open(mode="r|gz", fileobj=input_stream)
# since we're working with a tar file, shouldn't be larger than ~20KB, so just read the whole thing into mem
buf = input_stream.read()
config = tarfile.open(mode="r:gz", fileobj=cStringIO.StringIO(buf))
# TODO(sam): refactor config provider to accept a stream write to avoid loading into memory
config_provider.load_from_tarball(config)
config_provider.load_from_tar_stream(tar_stream)
# now try to connect to the db provided in their config
combined = dict(**app.config)