Class: S3Sync::Upload
- Inherits:
-
Object
- Object
- S3Sync::Upload
- Defined in:
- lib/s3_sync/upload.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#files ⇒ Object
Returns the value of attribute files.
-
#key_id ⇒ Object
Returns the value of attribute key_id.
-
#key_secret ⇒ Object
Returns the value of attribute key_secret.
-
#region ⇒ Object
Returns the value of attribute region.
-
#secret_phrase ⇒ Object
Returns the value of attribute secret_phrase.
Instance Method Summary collapse
-
#initialize(options = S3Sync.configuration) ⇒ Upload
constructor
A new instance of Upload.
Constructor Details
#initialize(options = S3Sync.configuration) ⇒ Upload
Returns a new instance of Upload.
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 |
# File 'lib/s3_sync/upload.rb', line 5 def initialize( = S3Sync.configuration) @key_id = .key_id @key_secret = .key_secret @region = .region @bucket = .bucket @secret_phrase = .secret_phrase @files = .files raise "check your configuration" unless [@key_id, @key_secret, @region, @bucket, @secret_phrase].map{|s| s.class}.uniq == [String] && @files.is_a?(Array) creds = Aws::Credentials.new(@key_id, @key_secret) # Create bucket. resource = Aws::S3::Resource.new(:region => @region, credentials: creds) bucket_names = resource.buckets.map{|b| b.name} resource.create_bucket(:bucket => @bucket, :acl => "private") unless bucket_names.include?(@bucket) # Upload files client = Aws::S3::Client.new(:region => @region, :credentials => creds) @files.each do |file| raise "couldn't find file #{file}" unless File.exist?(file) encrypted_file_contents = Encryptor.encrypt(File.read(file), :key => @secret_phrase) s3_file = File.join(Date.today.to_s, file) client.put_object(:bucket => @bucket, :key => s3_file, :body => encrypted_file_contents) puts "uploaded encrypted contents of #{file} to #{@bucket}/#{s3_file}" end end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def bucket @bucket end |
#files ⇒ Object
Returns the value of attribute files.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def files @files end |
#key_id ⇒ Object
Returns the value of attribute key_id.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def key_id @key_id end |
#key_secret ⇒ Object
Returns the value of attribute key_secret.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def key_secret @key_secret end |
#region ⇒ Object
Returns the value of attribute region.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def region @region end |
#secret_phrase ⇒ Object
Returns the value of attribute secret_phrase.
3 4 5 |
# File 'lib/s3_sync/upload.rb', line 3 def secret_phrase @secret_phrase end |