Class: Bard::Backup
- Inherits:
-
Struct
- Object
- Struct
- Bard::Backup
- Defined in:
- lib/bard/backup.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#s3_path ⇒ Object
Returns the value of attribute s3_path.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key
9 10 11 |
# File 'lib/bard/backup.rb', line 9 def access_key @access_key end |
#s3_path ⇒ Object
Returns the value of attribute s3_path
9 10 11 |
# File 'lib/bard/backup.rb', line 9 def s3_path @s3_path end |
#secret_key ⇒ Object
Returns the value of attribute secret_key
9 10 11 |
# File 'lib/bard/backup.rb', line 9 def secret_key @secret_key end |
Class Method Details
.call(s3_path, access_key:, secret_key:) ⇒ Object
10 11 12 |
# File 'lib/bard/backup.rb', line 10 def self.call s3_path, access_key:, secret_key: new(s3_path, access_key, secret_key).call end |
Instance Method Details
#call ⇒ Object
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 |
# File 'lib/bard/backup.rb', line 14 def call @time = Time.now Backhoe.dump path self.full_s3_path = "/#{s3_path}/#{filename}" if s3_path.include?("/") s3_bucket = s3_path.split("/").first self.s3_path = s3_path.split("/")[1..].join("/") uri = URI("https://#{s3_bucket}.s3.amazonaws.com/#{s3_path}/#{filename}") else uri = URI("https://#{s3_path}.s3.amazonaws.com/#{filename}") end request = Net::HTTP::Put.new(uri, { "Content-Length": File.size(path).to_s, "Content-Type": content_type, "Date": date, "Authorization": "AWS #{access_key}:#{signature}", "x-amz-storage-class": "STANDARD", "x-amz-acl": "private", }) request.body_stream = File.open(path) Net::HTTP.start(uri.hostname) do |http| response = http.request(request) response.value # raises if not success end end |