This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/config_app/config_endpoints/api/tar_config_loader.py
Sam Chow d6d0bb640a Modify config field to use base api endpoint
allow streaming from gzipped tarball config
2018-06-22 10:57:35 -04:00

28 lines
891 B
Python

import tarfile
from flask import request, make_response
from data.database import configure
from config_app.c_app import app, config_provider
from config_app.config_endpoints.api import resource, ApiResource, nickname
@resource('/v1/configapp/tarconfig')
class TarConfigLoader(ApiResource):
""" Resource for validating a block of configuration against an external service. """
@nickname('uploadTarballConfig')
def put(self):
""" Loads tarball config into the config provider """
input_stream = request.stream
tar_stream = tarfile.open(mode="r|gz", fileobj=input_stream)
config_provider.load_from_tar_stream(tar_stream)
# now try to connect to the db provided in their config
combined = dict(**app.config)
combined.update(config_provider.get_config())
configure(combined)
return make_response('OK')