class Crossing
Documentation incoming
Public Class Methods
new(s3_client_encrypted, s3_client_unencrypted = nil)
click to toggle source
# File lib/crossing.rb, line 16 def initialize(s3_client_encrypted, s3_client_unencrypted = nil) raise CrossingMisconfigurationException if s3_client_encrypted.nil? unless s3_client_encrypted.is_a? Aws::S3::Encryption::Client raise CrossingMisconfigurationException end @s3_client_encrypted = s3_client_encrypted setup_unencrypted_client s3_client_encrypted, s3_client_unencrypted end
Public Instance Methods
get(bucket, file)
click to toggle source
# File lib/crossing.rb, line 43 def get(bucket, file) if File.exist?(file) raise(CrossingFileExistsException, "File #{file} already exists, will not overwrite.") end content = get_content(bucket, file) File.open(file, 'wb') { |f| f.write(content) } end
get_content(bucket, file)
click to toggle source
# File lib/crossing.rb, line 62 def get_content(bucket, file) @s3_client_encrypted.get_object(bucket: bucket, key: file).body.read # If a decryption exception occurs, warn and get the object without decryption rescue Aws::S3::Encryption::Errors::DecryptionError STDERR.puts "WARNING: #{file} decryption failed. Retreiving the object without encryption." @s3_client_unencrypted.get_object(bucket: bucket, key: file).body.read end
get_multiple(bucket, filelist)
click to toggle source
# File lib/crossing.rb, line 54 def get_multiple(bucket, filelist) filelist.each { |file| get(bucket, file) } end
put(bucket, filename)
click to toggle source
# File lib/crossing.rb, line 28 def put(bucket, filename) File.open(filename, 'r') do |file| put_content(bucket, File.basename(filename), file.read) end rescue Errno::ENOENT raise CrossingFileNotFoundException, "File not found: #{filename}" end
put_content(bucket, filename, content)
click to toggle source
# File lib/crossing.rb, line 36 def put_content(bucket, filename, content) @s3_client_encrypted.put_object(bucket: bucket, key: filename, body: content, metadata: { 'x-crossing-uploaded' => 'true' }) end
put_multiple(bucket, filelist)
click to toggle source
# File lib/crossing.rb, line 58 def put_multiple(bucket, filelist) filelist.each { |file| put(bucket, file) } end
setup_unencrypted_client(s3_client_encrypted, s3_client_unencrypted)
click to toggle source
# File lib/crossing.rb, line 5 def setup_unencrypted_client(s3_client_encrypted, s3_client_unencrypted) if !s3_client_unencrypted.nil? raise CrossingMisconfigurationException unless s3_client_unencrypted.is_a? Aws::S3::Client @s3_client_unencrypted = s3_client_unencrypted else # assign regular s3 client @s3_client_unencrypted = s3_client_encrypted.client end end