Skip to content

Commit

Permalink
Use s3 gem which allows the usage of EEUU and European buckets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesc Esplugas authored and Michael van Rooijen committed Jul 11, 2010
1 parent e280f66 commit a63a85d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion backup.gemspec
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |gem|

##
# Dependencies
gem.add_dependency('aws-s3', [">= 0.6.2"])
gem.add_dependency('s3', [">= 0.3.0"])
gem.add_dependency('net-ssh', [">= 2.0.15"])
gem.add_dependency('net-scp', [">= 1.0.2"])
gem.add_dependency('net-sftp', [">= 2.0.4"])
Expand Down
46 changes: 18 additions & 28 deletions lib/backup/connection/s3.rb
@@ -1,4 +1,4 @@
require 'aws/s3'
require 's3'

module Backup
module Connection
Expand All @@ -25,47 +25,37 @@ def static_initialize(procedure)

# Establishes a connection with Amazon S3 using the credentials provided by the user
def connect
AWS::S3::Base.establish_connection!(
:access_key_id => access_key_id,
:secret_access_key => secret_access_key,
:use_ssl => use_ssl
)
service
end

# Wrapper for the Service object
def service
AWS::S3::Service
::S3::Service.new(:access_key_id => access_key_id,
:secret_access_key => secret_access_key,
:use_ssl => use_ssl)
end

# Wrapper for the Bucket object
def bucket
AWS::S3::Bucket
service.buckets.find(s3_bucket)
end

# Wrapper for the Object object
def object
AWS::S3::S3Object
end


# Initializes the file transfer to Amazon S3
# This can only run after a connection has been made using the #connect method
def store
puts "Storing \"#{final_file}\" to bucket \"#{s3_bucket}\" on Amazon S3."
object.store(
final_file,
open(File.join(tmp_path, final_file)),
s3_bucket )
object = bucket.objects.build(final_file)
object.content = open(File.join(tmp_path, final_file))
object.save
end

# Destroys file from a bucket on Amazon S3
def destroy(file, bucket)
object.delete(
file,
bucket )
def destroy(file, bucket_as_string)
object = bucket.objects.find(file)
object.destroy
end

private

def load_storage_configuration_attributes(static = false)
%w(access_key_id secret_access_key use_ssl).each do |attribute|
if static
Expand Down

0 comments on commit a63a85d

Please sign in to comment.