crossing 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/crossing.rb +30 -9
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b632249d2ce6cb691314739f99a16f452e4170db
4
- data.tar.gz: 37a0ea305b4154ea7d3492c1a5b77157eaa7de44
3
+ metadata.gz: ea547ab9192c22203ae5940c83cc60142d219d26
4
+ data.tar.gz: 553d987c1b449c4f6bd92cf7ce6e3e616d400a9d
5
5
  SHA512:
6
- metadata.gz: 3528ede47332f67ac5a7b94136c7f9d6c11b28b9cb26f3be45f96c61fb70d7d7320235af19f7c8877ceebaafbe82d4d55387c1e59afd4238ce4767a7af0af20e
7
- data.tar.gz: 7a29c5b5e2b9438f3f04534245d80128fe9ffa83b6a8dd47046c452234526be6ae053c5472116f85b0286136072a8e8c91072d35c32b8648cf4ccbe2f215ab3f
6
+ metadata.gz: beb6f637721a02d7885209a2db1ce229412664ff3e5337f4fee12fadad8f684730726e796b4b27b5be35453e755b5b5e127eb1c0cd3d5d5efa39eee34cdcf2da
7
+ data.tar.gz: ec738d813b1cd0c45c63aa77dc88f639df2e645b0cab40a72e09f2719addd975889e345d466e87bc6ec99a572d3992d8461ca0f7f60eb035151a2ead3180878f
data/lib/crossing.rb CHANGED
@@ -2,10 +2,18 @@ require 'aws-sdk'
2
2
 
3
3
  # Documentation incoming
4
4
  class Crossing
5
- def initialize(s3_client)
6
- raise CrossingMisconfigurationException if s3_client.nil?
7
- raise CrossingMisconfigurationException unless s3_client.is_a? Aws::S3::Encryption::Client
8
- @s3_client = s3_client
5
+ def initialize(s3_client_encrypted, s3_client_unencrypted = nil)
6
+ raise CrossingMisconfigurationException if s3_client_encrypted.nil?
7
+ raise CrossingMisconfigurationException unless s3_client_encrypted.is_a? Aws::S3::Encryption::Client
8
+ @s3_client_encrypted = s3_client_encrypted
9
+
10
+ if !s3_client_unencrypted.nil?
11
+ raise CrossingMisconfigurationException unless s3_client_unencrypted.is_a? Aws::S3::Client
12
+ @s3_client_unencrypted = s3_client_unencrypted
13
+ else
14
+ # create regular s3 client
15
+ @s3_client_unencrypted = Aws::S3::Client.new
16
+ end
9
17
  end
10
18
 
11
19
  def put(bucket, filename)
@@ -17,10 +25,10 @@ class Crossing
17
25
  end
18
26
 
19
27
  def put_content(bucket, filename, content)
20
- @s3_client.put_object(bucket: bucket,
21
- key: File.basename(filename),
22
- body: content,
23
- tagging: "x-crossing-uploaded=true")
28
+ @s3_client_encrypted.put_object(bucket: bucket,
29
+ key: File.basename(filename),
30
+ body: content,
31
+ tagging: 'x-crossing-uploaded=true')
24
32
  end
25
33
 
26
34
  def get(bucket, file)
@@ -34,8 +42,21 @@ class Crossing
34
42
  File.open(file, 'wb') { |f| f.write(content) }
35
43
  end
36
44
 
45
+ def get_multiple(bucket, filelist)
46
+ filelist.each { |file| get(bucket, file) }
47
+ end
48
+
49
+ def put_multiple(bucket, filelist)
50
+ filelist.each { |file| put(bucket, file) }
51
+ end
52
+
37
53
  def get_content(bucket, file)
38
- @s3_client.get_object(bucket: bucket, key: file).body.read
54
+ @s3_client_encrypted.get_object(bucket: bucket, key: file).body.read
55
+
56
+ # If a decryption exception occurs, warn and get the object without decryption
57
+ rescue Aws::S3::Encryption::Errors::DecryptionError
58
+ STDERR.puts "WARNING: #{file} decryption failed. Retreiving the object without encryption."
59
+ @s3_client_unencrypted.get_object(bucket: bucket, key: file).body.read
39
60
  end
40
61
  end
41
62
 
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crossing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ulick
8
8
  - Jonny Sywulak
9
+ - Keith Monihen
9
10
  - Stelligent
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2017-12-13 00:00:00.000000000 Z
14
+ date: 2018-01-10 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: aws-sdk