3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/s3_uploader/lib/s3_bucket_manager.rb', line 3
def self.ensure_bucket(bucket_name)
prop_key = "s3_bucket_#{bucket_name}"
unless Volt.current_app.properties[prop_key]
Volt.logger.info("Creating/Setting up S3 Bucket: #{bucket_name}")
creds = Aws::Credentials.new(Volt.config.s3.key, Volt.config.s3.secret)
s3 = Aws::S3::Resource.new(region: 'us-east-1', credentials: creds)
s3.create_bucket(
{
acl: "private", bucket: bucket_name, }
)
bucket = s3.bucket(bucket_name)
bucket.cors.put(
{
bucket: bucket_name,
cors_configuration: {
cors_rules: [
{
allowed_origins: ["*"],
allowed_methods: ["GET", "POST", "PUT"], allowed_headers: ["*"]
},
],
}
}
)
Volt.current_app.properties[prop_key] = '1'
end
end
|