Move tar filter to file, add tests for it
This commit is contained in:
parent
db757edcd2
commit
d7ffb54333
9 changed files with 83 additions and 32 deletions
|
@ -271,11 +271,15 @@ class SuperUserConfigValidate(ApiResource):
|
|||
# Note: This method is called to validate the database configuration before super users exists,
|
||||
# so we also allow it to be called if there is no valid registry configuration setup. Note that
|
||||
# this is also safe since this method does not access any information not given in the request.
|
||||
|
||||
# We can skip localstorage validation, since we can't guarantee that this will be the same machine
|
||||
# Q.E. will run under
|
||||
config = request.get_json()['config']
|
||||
validator_context = ValidatorContext.from_app(app, config, request.get_json().get('password', ''),
|
||||
instance_keys=instance_keys,
|
||||
ip_resolver=ip_resolver,
|
||||
config_provider=config_provider)
|
||||
config_provider=config_provider,
|
||||
skip_localstorage_validation=True)
|
||||
|
||||
return validate_service_for_config(service, validator_context)
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import tarfile
|
|||
from flask import request, make_response, send_file
|
||||
|
||||
from data.database import configure
|
||||
from util.config.validator import EXTRA_CA_DIRECTORY
|
||||
|
||||
from config_app.c_app import app, config_provider
|
||||
from config_app.config_endpoints.api import resource, ApiResource, nickname
|
||||
from config_app.config_util.tar import tarinfo_filter_partial
|
||||
|
||||
@resource('/v1/configapp/initialization')
|
||||
class ConfigInitialization(ApiResource):
|
||||
|
@ -17,7 +17,7 @@ class ConfigInitialization(ApiResource):
|
|||
"""
|
||||
|
||||
@nickname('scStartNewConfig')
|
||||
def get(self):
|
||||
def post(self):
|
||||
config_provider.new_config_dir()
|
||||
|
||||
return make_response('OK')
|
||||
|
@ -37,22 +37,12 @@ class TarConfigLoader(ApiResource):
|
|||
# remove the initial trailing / from the prefix path, and add the last dir one
|
||||
tar_dir_prefix = config_path[1:] + '/'
|
||||
|
||||
def tarinfo_filter(tarinfo):
|
||||
# remove leading directory info
|
||||
tarinfo.name = tarinfo.name.replace(tar_dir_prefix, '')
|
||||
|
||||
# ignore any directory that isn't the specified extra ca one:
|
||||
if tarinfo.isdir() and not tarinfo.name == EXTRA_CA_DIRECTORY:
|
||||
return None
|
||||
|
||||
return tarinfo
|
||||
|
||||
temp = tempfile.NamedTemporaryFile()
|
||||
|
||||
tar = tarfile.open(temp.name, mode="w|gz")
|
||||
|
||||
for name in os.listdir(config_path):
|
||||
tar.add(os.path.join(config_path, name), filter=tarinfo_filter)
|
||||
tar.add(os.path.join(config_path, name), filter=tarinfo_filter_partial(tar_dir_prefix))
|
||||
|
||||
tar.close()
|
||||
|
||||
|
|
Reference in a new issue