Have the config setup tool automatically prepare the S3 or GCS storage with CORS config
This commit is contained in:
parent
3a3945779d
commit
53e5fc6265
3 changed files with 62 additions and 5 deletions
|
@ -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("""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<CORSRule>
|
||||
<AllowedOrigin>*</AllowedOrigin>
|
||||
<AllowedMethod>GET</AllowedMethod>
|
||||
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
||||
<AllowedHeader>Authorization</AllowedHeader>
|
||||
</CORSRule>
|
||||
<CORSRule>
|
||||
<AllowedOrigin>*</AllowedOrigin>
|
||||
<AllowedMethod>PUT</AllowedMethod>
|
||||
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
||||
<AllowedHeader>Content-Type</AllowedHeader>
|
||||
<AllowedHeader>x-amz-acl</AllowedHeader>
|
||||
<AllowedHeader>origin</AllowedHeader>
|
||||
</CORSRule>
|
||||
</CORSConfiguration>""")
|
||||
|
||||
|
||||
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("""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CorsConfig>
|
||||
<Cors>
|
||||
<Origins>
|
||||
<Origin>*</Origin>
|
||||
</Origins>
|
||||
<Methods>
|
||||
<Method>GET</Method>
|
||||
<Method>PUT</Method>
|
||||
</Methods>
|
||||
<ResponseHeaders>
|
||||
<ResponseHeader>Content-Type</ResponseHeader>
|
||||
</ResponseHeaders>
|
||||
<MaxAgeSec>3000</MaxAgeSec>
|
||||
</Cors>
|
||||
</CorsConfig>""")
|
||||
|
||||
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()
|
||||
|
|
Reference in a new issue