Class: S3
- Inherits:
-
Sink
show all
- Includes:
- AWS::S3
- Defined in:
- lib/blanket/plugins/sinks/s3.rb
Instance Attribute Summary collapse
Attributes inherited from Sink
#backup_file
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
included, #method_missing, #noop
Constructor Details
#initialize(reader) ⇒ S3
Returns a new instance of S3.
8
9
10
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 8
def initialize(reader)
@reader = reader
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Utils
Instance Attribute Details
#reader ⇒ Object
Returns the value of attribute reader.
6
7
8
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 6
def reader
@reader
end
|
Class Method Details
.additional_requirements ⇒ Object
12
13
14
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 12
def self.additional_requirements
"'capistrano/recipes/s3'"
end
|
.attribute_symbols ⇒ Object
16
17
18
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 16
def self.attribute_symbols
[:access_key_id, :secret_access_key, :sink_type, :bucket]
end
|
.create_bucket(name) ⇒ Object
45
46
47
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 45
def self.create_bucket(name)
Bucket.create(name)
end
|
.default_access_key_id ⇒ Object
24
25
26
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 24
def self.default_access_key_id
"your-id"
end
|
.default_bucket ⇒ Object
32
33
34
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 32
def self.default_bucket
"s3-bucket"
end
|
.default_secret_access_key ⇒ Object
28
29
30
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 28
def self.default_secret_access_key
"your-secret-ket"
end
|
.default_sink_type ⇒ Object
20
21
22
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 20
def self.default_sink_type
"S3"
end
|
Instance Method Details
#drain(bucket, backup_file) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 60
def drain(bucket, backup_file)
open_connection
s3_bucket = find_bucket(bucket)
if s3_bucket[backup_file]
log("Removing existing #{backup_file}", :info)
S3Object.delete(backup_file.to_s, bucket)
end
log("Uploading #{backup_file} to S3", :info)
S3Object.store(backup_file.to_s, File.open(backup_file), bucket)
end
|
#find_bucket(bucket) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 36
def find_bucket(bucket)
begin
Bucket.find(bucket)
rescue NoSuchBucket
S3.create_bucket(bucket)
find_bucket(bucket)
end
end
|
#log(msg, lvl) ⇒ Object
56
57
58
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 56
def log(msg, lvl)
puts msg
end
|
#open_connection ⇒ Object
49
50
51
52
53
54
|
# File 'lib/blanket/plugins/sinks/s3.rb', line 49
def open_connection
AWS::S3::Base.establish_connection!(
:access_key_id => @reader.access_key_id,
:secret_access_key => @reader.secret_access_key
)
end
|