diff --git a/storage/basestorage.py b/storage/basestorage.py index 332a5d2ca..da297fcf1 100644 --- a/storage/basestorage.py +++ b/storage/basestorage.py @@ -54,6 +54,10 @@ class BaseStorage(StoragePaths): # Set the IO buffer to 64kB buffer_size = 64 * 1024 + def setup(self): + """ Called to perform any storage system setup. """ + pass + def get_direct_download_url(self, path, expires_in=60, requires_cors=False): return None diff --git a/storage/cloud.py b/storage/cloud.py index 06dd8a2a9..91dadfb3e 100644 --- a/storage/cloud.py +++ b/storage/cloud.py @@ -77,6 +77,13 @@ class _CloudStorage(BaseStorage): return path[1:] return path + def get_cloud_conn(self): + self._initialize_cloud_conn() + return self._cloud_conn + + def get_cloud_bucket(self): + return self._cloud_bucket + def get_content(self, path): self._initialize_cloud_conn() path = self._init_path(path) @@ -221,6 +228,25 @@ class S3Storage(_CloudStorage): connect_kwargs, upload_params, storage_path, s3_access_key, s3_secret_key, s3_bucket) + def setup(self): + self.get_cloud_bucket().set_cors_xml(""" + + + * + GET + 3000 + Authorization + + + * + PUT + 3000 + Content-Type + x-amz-acl + origin + + """) + class GoogleCloudStorage(_CloudStorage): def __init__(self, storage_path, access_key, secret_key, bucket_name): @@ -230,6 +256,24 @@ class GoogleCloudStorage(_CloudStorage): connect_kwargs, upload_params, storage_path, access_key, secret_key, bucket_name) + def setup(self): + self.get_cloud_bucket().set_cors_xml(""" + + + + * + + + GET + PUT + + + Content-Type + + 3000 + + """) + def stream_write(self, path, fp, content_type=None, content_encoding=None): # Minimum size of upload part size on S3 is 5MB self._initialize_cloud_conn() diff --git a/util/config/validator.py b/util/config/validator.py index ec6d6f708..da533ec01 100644 --- a/util/config/validator.py +++ b/util/config/validator.py @@ -15,6 +15,13 @@ from util.oauth import GoogleOAuthConfig, GithubOAuthConfig SSL_FILENAMES = ['ssl.cert', 'ssl.key'] +def get_storage_provider(config): + parameters = config.get('DISTRIBUTED_STORAGE_CONFIG', {}).get('local', ['LocalStorage', {}]) + try: + return get_storage_driver(parameters) + except TypeError: + raise Exception('Missing required storage configuration parameter(s)') + def validate_service_for_config(service, config): """ Attempts to validate the configuration for the given service. """ if not service in _VALIDATORS: @@ -57,16 +64,18 @@ def _validate_redis(config): def _validate_registry_storage(config): """ Validates registry storage. """ - parameters = config.get('DISTRIBUTED_STORAGE_CONFIG', {}).get('local', ['LocalStorage', {}]) - try: - driver = get_storage_driver(parameters) - except TypeError: - raise Exception('Missing required storage configuration parameter(s)') + driver = get_storage_provider(config) # Put and remove a temporary file. driver.put_content('_verify', 'testing 123') driver.remove('_verify') + # Run setup on the driver if the read/write succeeded. + try: + driver.setup() + except Exception as ex: + raise Exception('Could not prepare storage: %s' % str(ex)) + def _validate_mailing(config): """ Validates sending email. """