def post(self, certpath): uploaded_file = request.files['file'] if not uploaded_file: raise InvalidRequest('Missing certificate file') # Save the certificate. certpath = pathvalidate.sanitize_filename(certpath) if not certpath.endswith('.crt'): raise InvalidRequest('Invalid certificate file: must have suffix `.crt`') logger.debug('Saving custom certificate %s', certpath) cert_full_path = config_provider.get_volume_path(EXTRA_CA_DIRECTORY, certpath) config_provider.save_volume_file(cert_full_path, uploaded_file) logger.debug('Saved custom certificate %s', certpath) # Validate the certificate. try: logger.debug('Loading custom certificate %s', certpath) 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 except IOError: logger.exception('Got IO error for cert %s', certpath) return '', 204 # Call the update script with config dir location to install the certificate immediately. if not app.config['TESTING']: cert_dir = os.path.join(config_provider.get_config_dir_path(), EXTRA_CA_DIRECTORY) if subprocess.call([os.path.join(INIT_SCRIPTS_LOCATION, 'certs_install.sh')], env={ 'CERTDIR': cert_dir }) != 0: raise Exception('Could not install certificates') return '', 204
def post(self, certpath): uploaded_file = request.files["file"] if not uploaded_file: raise InvalidRequest("Missing certificate file") # Save the certificate. certpath = pathvalidate.sanitize_filename(certpath) if not certpath.endswith(".crt"): raise InvalidRequest("Invalid certificate file: must have suffix `.crt`") logger.debug("Saving custom certificate %s", certpath) cert_full_path = config_provider.get_volume_path(EXTRA_CA_DIRECTORY, certpath) filename = config_provider.save_volume_file(cert_full_path, uploaded_file) logger.debug("Saved custom certificate %s to %s", certpath, filename) # Validate the certificate. try: logger.debug("Loading custom certificate %s", certpath) 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 except IOError: logger.exception("Got IO error for cert %s", certpath) return "", 204 # Call the update script with config dir location to install the certificate immediately. # This is needed by the configuration application to verify connections to external services # which require a self-signed or otherwise user-managed certificate. if not app.config["TESTING"]: try: cert_dir = os.path.join(config_provider.get_config_dir_path(), EXTRA_CA_DIRECTORY) script_env = {"CERTDIR": cert_dir} logger.debug("Installing certificates from the directory: %s" % cert_dir) script_filename = os.path.join(INIT_SCRIPTS_LOCATION, "certs_install.sh") logger.debug("Running script to install all certificates: %s", script_filename) process = Popen([script_filename], stderr=PIPE, stdout=PIPE, env=script_env) output, err = process.communicate() return_code = process.returncode if return_code != 0: raise Exception("Could not install certificates. Output: %s" % output) else: logger.debug("Successfully installed certificates. Output: %s", output) except Exception as e: logger.exception("Unable to install certificates. Unexpected error: %s", e) else: msg = ( "Quay is using the test configuration. Certificates will not be installed. " "This may break the configuration app's ability to verify certificates." ) logger.warning(msg) return "", 204
def post(self): try: new_secret = get_config_as_kube_secret(config_provider.get_config_dir_path()) KubernetesAccessorSingleton.get_instance().replace_qe_secret(new_secret) except K8sApiException as e: logger.exception("Failed to deploy qe config secret to kubernetes.") return make_response(e.message, 503) return make_response("Ok", 201)
def get(self): config_path = config_provider.get_config_dir_path() tar_dir_prefix = strip_absolute_path_and_add_trailing_dir(config_path) temp = tempfile.NamedTemporaryFile() with closing(tarfile.open(temp.name, mode="w|gz")) as tar: for name in os.listdir(config_path): tar.add(os.path.join(config_path, name), filter=tarinfo_filter_partial(tar_dir_prefix)) return send_file(temp.name, mimetype='application/gzip')
def put(self): """ Loads tarball config into the config provider """ # Generate a new empty dir to load the config into config_provider.new_config_dir() input_stream = request.stream with tarfile.open(mode="r|gz", fileobj=input_stream) as tar_stream: tar_stream.extractall(config_provider.get_config_dir_path()) config_provider.create_copy_of_config_dir() # now try to connect to the db provided in their config to validate it works combined = dict(**app.config) combined.update(config_provider.get_config()) configure(combined) return make_response('OK')
def post(self): # Get a clean transient directory to write the config into config_provider.new_config_dir() kube_accessor = KubernetesAccessorSingleton.get_instance() kube_accessor.save_secret_to_directory(config_provider.get_config_dir_path()) config_provider.create_copy_of_config_dir() # We update the db configuration to connect to their specified one # (Note, even if this DB isn't valid, it won't affect much in the config app, since we'll report an error, # and all of the options create a new clean dir, so we'll never pollute configs) combined = dict(**app.config) combined.update(config_provider.get_config()) configure(combined) return 200
def post(self, certpath): uploaded_file = request.files["file"] if not uploaded_file: raise InvalidRequest("Missing certificate file") # Save the certificate. certpath = pathvalidate.sanitize_filename(certpath) if not certpath.endswith(".crt"): raise InvalidRequest( "Invalid certificate file: must have suffix `.crt`") logger.debug("Saving custom certificate %s", certpath) cert_full_path = config_provider.get_volume_path( EXTRA_CA_DIRECTORY, certpath) config_provider.save_volume_file(cert_full_path, uploaded_file) logger.debug("Saved custom certificate %s", certpath) # Validate the certificate. try: logger.debug("Loading custom certificate %s", certpath) 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 except IOError: logger.exception("Got IO error for cert %s", certpath) return "", 204 # Call the update script with config dir location to install the certificate immediately. if not app.config["TESTING"]: cert_dir = os.path.join(config_provider.get_config_dir_path(), EXTRA_CA_DIRECTORY) if (subprocess.call( [os.path.join(INIT_SCRIPTS_LOCATION, "certs_install.sh")], env={"CERTDIR": cert_dir}, ) != 0): raise Exception("Could not install certificates") return "", 204