encrypted_s3_copy 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/encrypted_s3_copy.gemspec +2 -2
- data/lib/encrypted_s3_copy/client.rb +16 -5
- data/lib/encrypted_s3_copy/version.rb +1 -1
- data/spec/encrypted_s3_copy/client_spec.rb +45 -22
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd0ff5fcab6597788f33cf6ddf805f3158189c03
|
4
|
+
data.tar.gz: 25b15f638ca1ff29652a8f71981c6cc99b763c30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea8cf92dfd4044e832d4a3e6bd008611600a96cceb483e42463bd0bd72029ec48f372649439c12a47e0654040a2d6c8440b75ff4b35dadf1dd00f1e10b767aa3
|
7
|
+
data.tar.gz: 8890b9d079aa0def0ec3907e737b3ca96c16c7238a70a6fd0af1e05f0d5dabae04d73652f001ca482011a3a4bb409f34491ce1b18e8d0be427b8113a6c904cfc
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ command options
|
|
25
25
|
|
26
26
|
For client side encryption of AWS S3, generate symmetric key and save to file.
|
27
27
|
|
28
|
-
$
|
28
|
+
$ aes_key_gen -k /path/to/symmetric_key/file
|
29
29
|
|
30
30
|
### Upload or download encrypted file from/to AWS S3
|
31
31
|
|
data/encrypted_s3_copy.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "aws-sdk", "~> 1.
|
23
|
+
spec.add_dependency "aws-sdk", "~> 1.30"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
spec.add_development_dependency "rspec", ">= 2.99"
|
28
28
|
end
|
@@ -8,11 +8,17 @@ module EncryptedS3Copy
|
|
8
8
|
class Client
|
9
9
|
# s3://(a_bucket)/(path/to/target_file)
|
10
10
|
S3_PATH = /^s3:\/\/([^\/]+)\/(.+)/
|
11
|
+
|
12
|
+
def initialize(opts={})
|
13
|
+
@source = opts[:source_path]
|
14
|
+
@dest = opts[:destination_path]
|
15
|
+
set_s3_encryption_key(opts[:key_file_path]) if opts[:key_file_path]
|
16
|
+
end
|
17
|
+
|
11
18
|
def before
|
12
19
|
opt = OptionParser.new
|
13
20
|
opt.on('-k', '--key-file=KEY_FILE_PATH') do |path|
|
14
|
-
|
15
|
-
AWS.config(s3_encryption_key: Base64.decode64(encoded_key.chomp))
|
21
|
+
set_s3_encryption_key(path)
|
16
22
|
end
|
17
23
|
opt.on('-s', '--source=SOURCE_PATH') do |path|
|
18
24
|
@source = path
|
@@ -31,8 +37,6 @@ class Client
|
|
31
37
|
handle
|
32
38
|
end
|
33
39
|
|
34
|
-
private
|
35
|
-
|
36
40
|
def handle
|
37
41
|
if !(@source =~ S3_PATH) && @dest =~ S3_PATH
|
38
42
|
if @is_recursive
|
@@ -52,12 +56,19 @@ class Client
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
private
|
60
|
+
|
61
|
+
def set_s3_encryption_key(path)
|
62
|
+
encoded_key = File.read(path)
|
63
|
+
AWS.config(s3_encryption_key: Base64.decode64(encoded_key.chomp))
|
64
|
+
end
|
65
|
+
|
55
66
|
def recursive_download(bucket_name, suffix)
|
56
67
|
suffix += '/' unless suffix =~ /\/$/
|
57
68
|
|
58
69
|
s3_objects = get_s3_objects(bucket_name)
|
59
70
|
s3_objects.with_prefix(suffix).each do |obj|
|
60
|
-
next if obj.
|
71
|
+
next if obj.key =~ /\/$/
|
61
72
|
single_download(obj)
|
62
73
|
end
|
63
74
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
# require 'simplecov'
|
2
|
-
require_relative '../../lib/encrypted_s3_copy/client'
|
3
|
+
# require_relative '../../lib/encrypted_s3_copy/client'
|
3
4
|
|
4
5
|
describe EncryptedS3Copy::Client do
|
5
6
|
let(:bucket_name) { 'test_bkt' }
|
@@ -103,7 +104,7 @@ describe EncryptedS3Copy::Client do
|
|
103
104
|
expect(subject).to receive(:single_upload).with('dest', 'dir/file02.txt')
|
104
105
|
expect(subject).to receive(:single_upload).
|
105
106
|
with('dest', 'dir/dir2/file01.txt')
|
106
|
-
subject.
|
107
|
+
subject.handle
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
@@ -130,13 +131,6 @@ describe EncryptedS3Copy::Client do
|
|
130
131
|
allow(s3_file03_double).to receive(:key).and_return('dir/test/myfile')
|
131
132
|
allow(s3_file04_double).to receive(:key).and_return('hoge.txt')
|
132
133
|
|
133
|
-
allow(s3_dir01_double).to receive(:content_length).and_return(0)
|
134
|
-
allow(s3_dir02_double).to receive(:content_length).and_return(0)
|
135
|
-
allow(s3_file01_double).to receive(:content_length).and_return(10)
|
136
|
-
allow(s3_file02_double).to receive(:content_length).and_return(10)
|
137
|
-
allow(s3_file03_double).to receive(:content_length).and_return(10)
|
138
|
-
allow(s3_file04_double).to receive(:content_length).and_return(10)
|
139
|
-
|
140
134
|
allow(subject).to receive(:get_s3_objects).with('dest').
|
141
135
|
and_return(s3_objects_double)
|
142
136
|
|
@@ -156,7 +150,7 @@ describe EncryptedS3Copy::Client do
|
|
156
150
|
|
157
151
|
expect(file_double).to receive(:write).with(chunk_double).exactly(4).times
|
158
152
|
|
159
|
-
subject.
|
153
|
+
subject.handle
|
160
154
|
end
|
161
155
|
end
|
162
156
|
end
|
@@ -173,7 +167,7 @@ describe EncryptedS3Copy::Client do
|
|
173
167
|
end
|
174
168
|
it 'should get bucket object' do
|
175
169
|
expect(subject).to receive(:get_s3_object).with(bucket_name, dest_s3_suffix)
|
176
|
-
subject.
|
170
|
+
subject.handle
|
177
171
|
end
|
178
172
|
context 'when destination path is directory path' do
|
179
173
|
let(:remote_dest_path) { "s3://#{bucket_name}/#{dest_s3_suffix}" }
|
@@ -185,20 +179,20 @@ describe EncryptedS3Copy::Client do
|
|
185
179
|
it 'should complement file name' do
|
186
180
|
expected_dest = dest_s3_suffix + 'source_file_name'
|
187
181
|
expect(subject).to receive(:get_s3_object).with(bucket_name, expected_dest)
|
188
|
-
subject.
|
182
|
+
subject.handle
|
189
183
|
end
|
190
184
|
end
|
191
185
|
it 'should open source file' do
|
192
186
|
expect(File).to receive(:open).with(local_source_path)
|
193
|
-
subject.
|
187
|
+
subject.handle
|
194
188
|
end
|
195
189
|
it 'should write file contents to s3 object' do
|
196
190
|
expect(obj_double).to receive(:write).with(file_double)
|
197
|
-
subject.
|
191
|
+
subject.handle
|
198
192
|
end
|
199
193
|
it 'should close file pointer' do
|
200
194
|
expect(file_double).to receive(:close)
|
201
|
-
subject.
|
195
|
+
subject.handle
|
202
196
|
end
|
203
197
|
end
|
204
198
|
|
@@ -211,16 +205,16 @@ describe EncryptedS3Copy::Client do
|
|
211
205
|
end
|
212
206
|
it 'should execute single_download' do
|
213
207
|
expect(subject).to receive(:single_download)
|
214
|
-
subject.
|
208
|
+
subject.handle
|
215
209
|
end
|
216
210
|
it 'should get bucket' do
|
217
211
|
expect(subject).to receive(:get_s3_object)
|
218
|
-
subject.
|
212
|
+
subject.handle
|
219
213
|
end
|
220
214
|
context 'when destination path is full path' do
|
221
215
|
it 'should open local destination file' do
|
222
216
|
expect(File).to receive(:open).with(local_dest_path, 'wb')
|
223
|
-
subject.
|
217
|
+
subject.handle
|
224
218
|
end
|
225
219
|
end
|
226
220
|
context 'when destination path is directory path' do
|
@@ -228,19 +222,19 @@ describe EncryptedS3Copy::Client do
|
|
228
222
|
it 'should complement file name' do
|
229
223
|
expected_dest = local_dest_path + 'source_file_name'
|
230
224
|
expect(File).to receive(:open).with(expected_dest, 'wb')
|
231
|
-
subject.
|
225
|
+
subject.handle
|
232
226
|
end
|
233
227
|
end
|
234
228
|
it 'should read s3 object' do
|
235
229
|
allow(File).to receive(:open).and_yield(file_double)
|
236
230
|
expect(obj_double).to receive(:read)
|
237
|
-
subject.
|
231
|
+
subject.handle
|
238
232
|
end
|
239
233
|
it 'should write contents of s3 object to local file' do
|
240
234
|
allow(File).to receive(:open).and_yield(file_double)
|
241
235
|
allow(obj_double).to receive(:read).and_yield('chunk')
|
242
236
|
expect(file_double).to receive(:write).with('chunk')
|
243
|
-
subject.
|
237
|
+
subject.handle
|
244
238
|
end
|
245
239
|
end
|
246
240
|
|
@@ -249,7 +243,7 @@ describe EncryptedS3Copy::Client do
|
|
249
243
|
subject.instance_variable_set(:@source, local_source_path)
|
250
244
|
subject.instance_variable_set(:@dest, local_dest_path)
|
251
245
|
message = 'either source path or destination path or both are wrong'
|
252
|
-
expect{ subject.
|
246
|
+
expect{ subject.handle }.to raise_error(RuntimeError, message)
|
253
247
|
end
|
254
248
|
end
|
255
249
|
end
|
@@ -285,4 +279,33 @@ describe EncryptedS3Copy::Client do
|
|
285
279
|
subject.execute
|
286
280
|
end
|
287
281
|
end
|
282
|
+
|
283
|
+
context 'use as library' do
|
284
|
+
describe ".initialize" do
|
285
|
+
let(:opts) do
|
286
|
+
{ key_file_path: '/path/to/key_file',
|
287
|
+
source_path: '/path/to/source_file',
|
288
|
+
destination_path: 's3://bucket/path/to/file' }
|
289
|
+
end
|
290
|
+
let(:client) { described_class.new(opts) }
|
291
|
+
let(:key_str) { "a_key_str\n" }
|
292
|
+
|
293
|
+
before :each do
|
294
|
+
allow(File).to receive(:read).with(opts[:key_file_path]).and_return(key_str)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'set value of s3_encryption_key' do
|
298
|
+
source_value = client.instance_variable_get(:@source)
|
299
|
+
expect(source_value).to eq(opts[:source_path])
|
300
|
+
end
|
301
|
+
it 'set value of destination_path' do
|
302
|
+
dest_value = client.instance_variable_get(:@dest)
|
303
|
+
expect(dest_value).to eq(opts[:destination_path])
|
304
|
+
end
|
305
|
+
it 'set s3_encryption_key' do
|
306
|
+
expect(AWS).to receive(:config).with(s3_encryption_key: Base64.decode64(key_str.chomp))
|
307
|
+
client
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
288
311
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypted_s3_copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nabewata07
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.30'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.30'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.0.2
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: upload and download encrypted files to/from AWS S3
|