FEATURE: Support backup uploads/downloads directly to/from S3.

This reverts commit 3c59106bac4d79f39981bda3ff9db7786c1a78a0.
This commit is contained in:
Guo Xiang Tan
2018-10-15 09:43:31 +08:00
parent 6a59187ae8
commit 84d4c81a26
52 changed files with 1079 additions and 420 deletions

View File

@ -51,7 +51,7 @@ class S3Helper
# make sure we have a cors config for assets
# otherwise we will have no fonts
def ensure_cors!
def ensure_cors!(rules = nil)
rule = nil
begin
@ -63,17 +63,17 @@ class S3Helper
end
unless rule
puts "installing CORS rule"
rules = [{
allowed_headers: ["Authorization"],
allowed_methods: ["GET", "HEAD"],
allowed_origins: ["*"],
max_age_seconds: 3000
}] if rules.nil?
s3_resource.client.put_bucket_cors(
bucket: @s3_bucket_name,
cors_configuration: {
cors_rules: [{
allowed_headers: ["Authorization"],
allowed_methods: ["GET", "HEAD"],
allowed_origins: ["*"],
max_age_seconds: 3000
}]
cors_rules: rules
}
)
end
@ -137,10 +137,7 @@ class S3Helper
end
def list(prefix = "")
if @s3_bucket_folder_path.present?
prefix = File.join(@s3_bucket_folder_path, prefix)
end
prefix = get_path_for_s3_upload(prefix)
s3_bucket.objects(prefix: prefix)
end
@ -159,6 +156,11 @@ class S3Helper
)
end
def object(path)
path = get_path_for_s3_upload(path)
s3_bucket.object(path)
end
def self.s3_options(obj)
opts = { region: obj.s3_region,
endpoint: SiteSetting.s3_endpoint,