Revert local validation context, extract another util
This commit is contained in:
parent
d7ffb54333
commit
14fefea38f
6 changed files with 18 additions and 24 deletions
|
@ -271,15 +271,11 @@ 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,
|
||||
skip_localstorage_validation=True)
|
||||
config_provider=config_provider)
|
||||
|
||||
return validate_service_for_config(service, validator_context)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from data.database import configure
|
|||
|
||||
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
|
||||
from config_app.config_util.tar import tarinfo_filter_partial, strip_absolute_path_and_add_trailing_dir
|
||||
|
||||
@resource('/v1/configapp/initialization')
|
||||
class ConfigInitialization(ApiResource):
|
||||
|
@ -19,7 +19,6 @@ class ConfigInitialization(ApiResource):
|
|||
@nickname('scStartNewConfig')
|
||||
def post(self):
|
||||
config_provider.new_config_dir()
|
||||
|
||||
return make_response('OK')
|
||||
|
||||
|
||||
|
@ -33,19 +32,14 @@ class TarConfigLoader(ApiResource):
|
|||
@nickname('scGetConfigTarball')
|
||||
def get(self):
|
||||
config_path = config_provider.get_config_dir_path()
|
||||
|
||||
# remove the initial trailing / from the prefix path, and add the last dir one
|
||||
tar_dir_prefix = config_path[1:] + '/'
|
||||
|
||||
tar_dir_prefix = strip_absolute_path_and_add_trailing_dir(config_path)
|
||||
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_partial(tar_dir_prefix))
|
||||
|
||||
tar.close()
|
||||
|
||||
return send_file(temp.name, mimetype='application/gzip')
|
||||
|
||||
@nickname('scUploadTarballConfig')
|
||||
|
@ -53,7 +47,6 @@ class TarConfigLoader(ApiResource):
|
|||
""" 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())
|
||||
|
@ -61,7 +54,6 @@ class TarConfigLoader(ApiResource):
|
|||
# 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')
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
from util.config.validator import EXTRA_CA_DIRECTORY
|
||||
|
||||
def strip_absolute_path_and_add_trailing_dir(path):
|
||||
"""
|
||||
Removes the initial trailing / from the prefix path, and add the last dir one
|
||||
"""
|
||||
return path[1:] + '/'
|
||||
|
||||
def tarinfo_filter_partial(prefix):
|
||||
def tarinfo_filter(tarinfo):
|
||||
# remove leading directory info
|
||||
|
|
|
@ -7,6 +7,8 @@ from storage.azurestorage import AzureStorage
|
|||
from storage.downloadproxy import DownloadProxy
|
||||
from util.ipresolver import NoopIPResolver
|
||||
|
||||
TYPE_LOCAL_STORAGE = 'LocalStorage'
|
||||
|
||||
STORAGE_DRIVER_CLASSES = {
|
||||
'LocalStorage': LocalStorage,
|
||||
'S3Storage': S3Storage,
|
||||
|
|
|
@ -102,8 +102,7 @@ class ValidatorContext(object):
|
|||
def __init__(self, config, user_password=None, http_client=None, context=None,
|
||||
url_scheme_and_hostname=None, jwt_auth_max=None, registry_title=None,
|
||||
ip_resolver=None, feature_sec_scanner=False, is_testing=False,
|
||||
uri_creator=None, config_provider=None, instance_keys=None,
|
||||
skip_localstorage_validation=False):
|
||||
uri_creator=None, config_provider=None, instance_keys=None):
|
||||
self.config = config
|
||||
self.user = get_authenticated_user()
|
||||
self.user_password = user_password
|
||||
|
@ -118,11 +117,10 @@ class ValidatorContext(object):
|
|||
self.uri_creator = uri_creator
|
||||
self.config_provider = config_provider
|
||||
self.instance_keys = instance_keys
|
||||
self.skip_localstorage_validation = skip_localstorage_validation
|
||||
|
||||
@classmethod
|
||||
def from_app(cls, app, config, user_password, ip_resolver, instance_keys, client=None,
|
||||
config_provider=None, skip_localstorage_validation=False):
|
||||
config_provider=None):
|
||||
"""
|
||||
Creates a ValidatorContext from an app config, with a given config to validate
|
||||
:param app: the Flask app to pull configuration information from
|
||||
|
@ -148,5 +146,4 @@ class ValidatorContext(object):
|
|||
is_testing=app.config.get('TESTING', False),
|
||||
uri_creator=get_blob_download_uri_getter(app.test_request_context('/'), url_scheme_and_hostname),
|
||||
config_provider=config_provider,
|
||||
instance_keys=instance_keys,
|
||||
skip_localstorage_validation=skip_localstorage_validation)
|
||||
instance_keys=instance_keys)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from storage import get_storage_driver
|
||||
from storage import get_storage_driver, TYPE_LOCAL_STORAGE
|
||||
from util.config.validators import BaseValidator, ConfigValidationException
|
||||
|
||||
|
||||
|
@ -12,7 +12,6 @@ class StorageValidator(BaseValidator):
|
|||
client = validator_context.http_client
|
||||
ip_resolver = validator_context.ip_resolver
|
||||
config_provider = validator_context.config_provider
|
||||
skip_localstorage_validation = validator_context.skip_localstorage_validation
|
||||
|
||||
replication_enabled = config.get('FEATURE_STORAGE_REPLICATION', False)
|
||||
|
||||
|
@ -21,7 +20,9 @@ class StorageValidator(BaseValidator):
|
|||
raise ConfigValidationException('Storage configuration required')
|
||||
|
||||
for name, (storage_type, driver) in providers:
|
||||
if skip_localstorage_validation and storage_type == 'LocalStorage':
|
||||
# We can skip localstorage validation, since we can't guarantee that
|
||||
# this will be the same machine Q.E. will run under
|
||||
if storage_type == TYPE_LOCAL_STORAGE:
|
||||
continue
|
||||
|
||||
try:
|
||||
|
|
Reference in a new issue