file_pool 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file_pool/version.rb +2 -1
- data/lib/file_pool.rb +35 -12
- metadata +2 -6
- data/test/test_file_pool.rb +0 -85
- data/test/test_file_pool_encryption.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc512434b751b3cb4a8654b57ad512f389b9055
|
4
|
+
data.tar.gz: 5e8b5fb1e8cb897cfa0b6b683cc40498c2033cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ca7a96294fd39d864a9b6440875246edc0369de448ff61dbf9c0e1d2615718d09c99da1cfe0a4a31ca1477a5d637538545cbd811063e0ad039b4f95ff50392a
|
7
|
+
data.tar.gz: 3e6666cabf58d6414e5b844462d7c6034b7adcb3c97942159d97fe7e0bfb329870d50a7a0317bd8c4c565cbee1071e681d238796eb00847a41c481909f82628b
|
data/lib/file_pool/version.rb
CHANGED
data/lib/file_pool.rb
CHANGED
@@ -10,8 +10,7 @@ module FilePool
|
|
10
10
|
class InvalidFileId < Exception; end
|
11
11
|
|
12
12
|
#
|
13
|
-
# Setup the root directory of the file pool
|
14
|
-
# to write log messages
|
13
|
+
# Setup the root directory of the file pool and configure encryption
|
15
14
|
#
|
16
15
|
# === Parameters:
|
17
16
|
#
|
@@ -19,9 +18,21 @@ module FilePool
|
|
19
18
|
# absolute path of the file pool's root directory under which all files will be stored.
|
20
19
|
# config_file_path (String)::
|
21
20
|
# path to the config file of the filepool.
|
21
|
+
# options (Hash)::
|
22
|
+
# * :secrets_file (String)
|
23
|
+
# path to file containing key and IV for encryption (if omitted FilePool
|
24
|
+
# does not encrypt/decrypt). If file is not present, the file is initialized with a
|
25
|
+
# new random key and IV.
|
26
|
+
# * :encryption_block_size (Integer) sets the block size for
|
27
|
+
# encryption/decryption in bytes. Larger blocks need more memory and less time (less IO).
|
28
|
+
# Defaults to 1'048'576 (1 MiB).
|
22
29
|
def self.setup root, options={}
|
30
|
+
unless(unknown = options.keys - [:encryption_block_size, :secrets_file]).empty?
|
31
|
+
puts "FilePool Warning: unknown option(s) passed to #setup: #{unknown.inspect}"
|
32
|
+
end
|
23
33
|
@@root = root
|
24
34
|
@@crypted_mode = false
|
35
|
+
@@block_size = options[:encryption_block_size] || (1024*1024)
|
25
36
|
configure options[:secrets_file]
|
26
37
|
end
|
27
38
|
|
@@ -247,10 +258,17 @@ module FilePool
|
|
247
258
|
def self.crypt path
|
248
259
|
# Crypt the file in the temp folder and copy after
|
249
260
|
cipher = create_cipher
|
250
|
-
result = Tempfile.new
|
251
|
-
|
252
|
-
|
253
|
-
|
261
|
+
result = Tempfile.new 'FilePool-encrypt'
|
262
|
+
|
263
|
+
buf = ''
|
264
|
+
|
265
|
+
File.open(path) do |inf|
|
266
|
+
while inf.read(@@block_size, buf)
|
267
|
+
result << cipher.update(buf)
|
268
|
+
end
|
269
|
+
result << cipher.final
|
270
|
+
end
|
271
|
+
|
254
272
|
result.close
|
255
273
|
result.path
|
256
274
|
end
|
@@ -271,12 +289,17 @@ module FilePool
|
|
271
289
|
def self.decrypt path
|
272
290
|
decipher = create_decipher
|
273
291
|
# Now decrypt the data:
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
292
|
+
output = Tempfile.new 'FilePool-decrypt'
|
293
|
+
|
294
|
+
buf = ''
|
295
|
+
File.open(path) do |inf|
|
296
|
+
while inf.read(@@block_size, buf)
|
297
|
+
output << decipher.update(buf)
|
298
|
+
end
|
299
|
+
output << decipher.final
|
300
|
+
end
|
301
|
+
|
302
|
+
output.open # re-open for reading, prevents early deletion of tempfile
|
280
303
|
output.path
|
281
304
|
end
|
282
305
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- robokopp (Robert Anniés)
|
@@ -38,8 +38,6 @@ files:
|
|
38
38
|
- README.md
|
39
39
|
- lib/file_pool.rb
|
40
40
|
- lib/file_pool/version.rb
|
41
|
-
- test/test_file_pool.rb
|
42
|
-
- test/test_file_pool_encryption.rb
|
43
41
|
homepage: https://github.com/robokopp/file_pool
|
44
42
|
licenses: []
|
45
43
|
metadata: {}
|
@@ -63,7 +61,5 @@ rubygems_version: 2.4.6
|
|
63
61
|
signing_key:
|
64
62
|
specification_version: 4
|
65
63
|
summary: Manage a large number files in a pool
|
66
|
-
test_files:
|
67
|
-
- test/test_file_pool.rb
|
68
|
-
- test/test_file_pool_encryption.rb
|
64
|
+
test_files: []
|
69
65
|
has_rdoc:
|
data/test/test_file_pool.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'shoulda-context'
|
6
|
-
require 'file_pool'
|
7
|
-
|
8
|
-
class FilePoolTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@test_dir = "#{File.dirname(__FILE__)}/files"
|
12
|
-
@pool_root = "#{File.dirname(__FILE__)}/fp_root"
|
13
|
-
FilePool.setup @pool_root
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
FileUtils.rm_r(Dir.glob @pool_root+"/*")
|
18
|
-
end
|
19
|
-
|
20
|
-
context "File Pool" do
|
21
|
-
should "store files" do
|
22
|
-
fid = FilePool.add(@test_dir+"/a")
|
23
|
-
|
24
|
-
assert UUIDTools::UUID.parse(fid).valid?
|
25
|
-
|
26
|
-
md5_orig = Digest::MD5.hexdigest(File.open(@test_dir+"/a").read)
|
27
|
-
md5_pooled = Digest::MD5.hexdigest(File.open(FilePool.path(fid)).read)
|
28
|
-
|
29
|
-
assert_equal md5_orig, md5_pooled
|
30
|
-
end
|
31
|
-
|
32
|
-
should "return path from stored files" do
|
33
|
-
|
34
|
-
fidb = FilePool.add(@test_dir+"/b")
|
35
|
-
fidc = FilePool.add(@test_dir+"/c")
|
36
|
-
fidd = FilePool.add!(@test_dir+"/d")
|
37
|
-
|
38
|
-
assert_equal "#{@pool_root}/#{fidb[0,1]}/#{fidb[1,1]}/#{fidb[2,1]}/#{fidb}", FilePool.path(fidb)
|
39
|
-
assert_equal "#{@pool_root}/#{fidc[0,1]}/#{fidc[1,1]}/#{fidc[2,1]}/#{fidc}", FilePool.path(fidc)
|
40
|
-
assert_equal "#{@pool_root}/#{fidd[0,1]}/#{fidd[1,1]}/#{fidd[2,1]}/#{fidd}", FilePool.path(fidd)
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
should "remove files from pool" do
|
45
|
-
|
46
|
-
fidb = FilePool.add(@test_dir+"/b")
|
47
|
-
fidc = FilePool.add!(@test_dir+"/c")
|
48
|
-
fidd = FilePool.add!(@test_dir+"/d")
|
49
|
-
|
50
|
-
path_c = FilePool.path(fidc)
|
51
|
-
FilePool.remove(fidc)
|
52
|
-
|
53
|
-
assert !File.exist?(path_c)
|
54
|
-
assert File.exist?(FilePool.path(fidb))
|
55
|
-
assert File.exist?(FilePool.path(fidd))
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
should "throw excceptions when using add! and remove! on failure" do
|
60
|
-
assert_raises(FilePool::InvalidFileId) do
|
61
|
-
FilePool.remove!("invalid-id")
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_raises(Errno::ENOENT) do
|
65
|
-
FilePool.remove!("61e9b2d1-1738-440d-9b3d-e3c64876f2b0")
|
66
|
-
end
|
67
|
-
|
68
|
-
assert_raises(Errno::ENOENT) do
|
69
|
-
FilePool.add!("/not/here/foo.png")
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
should "not throw exceptions when using add and remove on failure" do
|
75
|
-
assert !FilePool.remove("invalid-id")
|
76
|
-
assert !FilePool.remove("61e9b2d1-1738-440d-9b3d-e3c64876f2b0")
|
77
|
-
assert !FilePool.add("/not/here/foo.png")
|
78
|
-
end
|
79
|
-
|
80
|
-
should "detect whether file encrypted" do
|
81
|
-
fid = FilePool.add(@test_dir+"/a")
|
82
|
-
assert !FilePool.encrypted?(fid)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'shoulda-context'
|
6
|
-
require 'file_pool'
|
7
|
-
|
8
|
-
class FilePoolEncryptionTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@test_dir = "#{File.dirname(__FILE__)}/files"
|
12
|
-
@pool_root = "#{File.dirname(__FILE__)}/fp_root"
|
13
|
-
@file_pool_config = "#{File.dirname(__FILE__)}/file_pool_cfg.yml"
|
14
|
-
FilePool.setup @pool_root, :secrets_file => @file_pool_config
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
FileUtils.rm_r(Dir.glob @pool_root+"/*")
|
19
|
-
FileUtils.rm_r(Dir.glob "#{@pool_root}_secured/*")
|
20
|
-
FileUtils.rm_r(Dir.glob @file_pool_config)
|
21
|
-
end
|
22
|
-
|
23
|
-
context "File Pool" do
|
24
|
-
should "store encrypted files" do
|
25
|
-
fid = FilePool.add(@test_dir+"/a")
|
26
|
-
|
27
|
-
assert UUIDTools::UUID.parse(fid).valid?
|
28
|
-
|
29
|
-
md5_orig = Digest::MD5.hexdigest(File.open(@test_dir+"/a").read)
|
30
|
-
md5_pooled = Digest::MD5.hexdigest(File.open(FilePool.path(fid)).read)
|
31
|
-
|
32
|
-
assert_equal md5_orig, md5_pooled
|
33
|
-
end
|
34
|
-
|
35
|
-
should "return path from stored encrypted files is in the tmp folder" do
|
36
|
-
|
37
|
-
fida = FilePool.add(@test_dir+"/a")
|
38
|
-
assert UUIDTools::UUID.parse(fida).valid?
|
39
|
-
|
40
|
-
fidb = FilePool.add(@test_dir+"/b")
|
41
|
-
assert UUIDTools::UUID.parse(fidb).valid?
|
42
|
-
|
43
|
-
fidc = FilePool.add(@test_dir+"/c")
|
44
|
-
assert UUIDTools::UUID.parse(fidc).valid?
|
45
|
-
|
46
|
-
fidd = FilePool.add!(@test_dir+"/d")
|
47
|
-
assert UUIDTools::UUID.parse(fidd).valid?
|
48
|
-
|
49
|
-
assert_equal Digest::MD5.hexdigest(File.open(@test_dir+"/a").read),
|
50
|
-
Digest::MD5.hexdigest(File.open(FilePool.path(fida)).read)
|
51
|
-
assert_equal Digest::MD5.hexdigest(File.open(@test_dir+"/b").read),
|
52
|
-
Digest::MD5.hexdigest(File.open(FilePool.path(fidb)).read)
|
53
|
-
assert_equal Digest::MD5.hexdigest(File.open(@test_dir+"/c").read),
|
54
|
-
Digest::MD5.hexdigest(File.open(FilePool.path(fidc)).read)
|
55
|
-
assert_equal Digest::MD5.hexdigest(File.open(@test_dir+"/d").read),
|
56
|
-
Digest::MD5.hexdigest(File.open(FilePool.path(fidd)).read)
|
57
|
-
|
58
|
-
assert_equal Dir.tmpdir, File.dirname(FilePool.path(fida))
|
59
|
-
assert_equal Dir.tmpdir, File.dirname(FilePool.path(fidb))
|
60
|
-
assert_equal Dir.tmpdir, File.dirname(FilePool.path(fidc))
|
61
|
-
assert_equal Dir.tmpdir,File.dirname( FilePool.path(fidd))
|
62
|
-
end
|
63
|
-
|
64
|
-
should "remove files from encrypted pool" do
|
65
|
-
|
66
|
-
fidb = FilePool.add(@test_dir+"/b")
|
67
|
-
fidc = FilePool.add!(@test_dir+"/c")
|
68
|
-
fidd = FilePool.add!(@test_dir+"/d")
|
69
|
-
|
70
|
-
path_c = FilePool.path(fidc, :decrypt => false)
|
71
|
-
FilePool.remove(fidc)
|
72
|
-
|
73
|
-
assert !File.exist?(path_c)
|
74
|
-
assert File.exist?(FilePool.path(fidb, :decrypt => false))
|
75
|
-
assert File.exist?(FilePool.path(fidd, :decrypt => false))
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
should "throw exceptions when using add! and remove! on failure in encrypted mode" do
|
80
|
-
assert_raises(FilePool::InvalidFileId) do
|
81
|
-
FilePool.remove!("invalid-id")
|
82
|
-
end
|
83
|
-
|
84
|
-
assert_raises(Errno::ENOENT) do
|
85
|
-
FilePool.remove!("61e9b2d1-1738-440d-9b3d-e3c64876f2b0")
|
86
|
-
end
|
87
|
-
|
88
|
-
assert_raises(Errno::ENOENT) do
|
89
|
-
FilePool.add!("/not/here/foo.png")
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
should "not throw exceptions when using add and remove on failure in encrypted mode" do
|
95
|
-
assert !FilePool.remove("invalid-id")
|
96
|
-
assert !FilePool.remove("61e9b2d1-1738-440d-9b3d-e3c64876f2b0")
|
97
|
-
assert !FilePool.add("/not/here/foo.png")
|
98
|
-
end
|
99
|
-
|
100
|
-
should "detect whether file encrypted" do
|
101
|
-
fid = FilePool.add(@test_dir+"/a")
|
102
|
-
assert FilePool.encrypted?(fid)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|