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

This commit is contained in:
Gerhard Schlager
2018-09-10 16:48:34 +02:00
committed by Guo Xiang Tan
parent 5039a6c3f1
commit c29a4dddc1
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,