iostreams 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/io_streams/io_streams.rb +16 -2
- data/lib/io_streams/pgp.rb +40 -1
- data/lib/io_streams/pgp/writer.rb +2 -2
- data/lib/io_streams/sftp/reader.rb +1 -1
- data/lib/io_streams/sftp/writer.rb +2 -2
- data/lib/io_streams/version.rb +1 -1
- data/test/io_streams_test.rb +57 -0
- data/test/pgp_writer_test.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b6a2e131f668f33e07b92d4bb97a502034be3e
|
4
|
+
data.tar.gz: 75d6e4b9bd1fe755f390064418872b4038e3ea81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc645f505a045422d8273b58354816676b4883953b5d1600073f8c913275eb555ed1d22c11ed74ec88014c7a74d5c0f3b9b4daef5aa243a629aa74a84601ccce
|
7
|
+
data.tar.gz: 3a7afd7654017a715ca21f56567d40e924ff4c4e45fcd7e2ed72959b488d833e9cc74f8d08ce32cd7d66565ac86b9c8395c78b28862c23ac17f421eac8d33d19
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'concurrent'
|
2
2
|
module IOStreams
|
3
3
|
# A registry to hold formats for processing files during upload or download
|
4
|
-
@@extensions = Concurrent::
|
4
|
+
@@extensions = Concurrent::Map.new
|
5
5
|
|
6
6
|
UTF8_ENCODING = Encoding.find('UTF-8').freeze
|
7
7
|
BINARY_ENCODING = Encoding.find('BINARY').freeze
|
@@ -175,7 +175,7 @@ module IOStreams
|
|
175
175
|
# IOStreams.copy(source_stream, target_stream)
|
176
176
|
# end
|
177
177
|
# end
|
178
|
-
def self.copy(source_stream, target_stream, buffer_size=65536)
|
178
|
+
def self.copy(source_stream, target_stream, buffer_size = 65536)
|
179
179
|
bytes = 0
|
180
180
|
while data = source_stream.read(buffer_size)
|
181
181
|
break if data.size == 0
|
@@ -185,6 +185,20 @@ module IOStreams
|
|
185
185
|
bytes
|
186
186
|
end
|
187
187
|
|
188
|
+
# Copies the source file name to the target file name.
|
189
|
+
#
|
190
|
+
# Returns [Integer] the number of bytes copied
|
191
|
+
#
|
192
|
+
# Example:
|
193
|
+
# IOStreams.copy_file('a.csv', 'b.csv.enc')
|
194
|
+
def self.copy_file(source_file_name, target_file_name, buffer_size = 65536)
|
195
|
+
reader(source_file_name) do |source_stream|
|
196
|
+
writer(target_file_name) do |target_stream|
|
197
|
+
copy(source_stream, target_stream, buffer_size)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
188
202
|
# Returns [true|false] whether the supplied file_name_or_io is a reader stream
|
189
203
|
def self.reader_stream?(file_name_or_io)
|
190
204
|
file_name_or_io.respond_to?(:read)
|
data/lib/io_streams/pgp.rb
CHANGED
@@ -166,7 +166,7 @@ module IOStreams
|
|
166
166
|
output = out.read.chomp
|
167
167
|
if waith_thr.value.success?
|
168
168
|
output.each_line do |line|
|
169
|
-
return true if line.
|
169
|
+
return true if line.include?(email)
|
170
170
|
end
|
171
171
|
false
|
172
172
|
else
|
@@ -176,6 +176,25 @@ module IOStreams
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
+
# Returns [String] the first fingerprint for the supplied email
|
180
|
+
# Returns nil if no fingerprint was found
|
181
|
+
def self.fingerprint(email:)
|
182
|
+
Open3.popen2e("gpg --list-keys --fingerprint --with-colons #{email}") do |stdin, out, waith_thr|
|
183
|
+
output = out.read.chomp
|
184
|
+
if waith_thr.value.success?
|
185
|
+
output.each_line do |line|
|
186
|
+
if match = line.match(/\Afpr.*::([^\:]*):\Z/)
|
187
|
+
return match[1]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
nil
|
191
|
+
else
|
192
|
+
return if output =~ /(public key not found|No public key)/i
|
193
|
+
raise(Pgp::Failure, "GPG Failed calling gpg to list keys for #{email}: #{output}")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
179
198
|
# Returns [String] the key for the supplied email address
|
180
199
|
#
|
181
200
|
# email: [String] Email address for requested key
|
@@ -209,5 +228,25 @@ module IOStreams
|
|
209
228
|
end
|
210
229
|
end
|
211
230
|
|
231
|
+
# Set the trust level for an existing key.
|
232
|
+
#
|
233
|
+
# Returns [String] output if the trust was successfully updated
|
234
|
+
# Returns nil if the email was not found
|
235
|
+
#
|
236
|
+
# After importing keys, they are not trusted and the relevant trust level must be set.
|
237
|
+
# Default: 5 : Ultimate
|
238
|
+
def self.set_trust(email:, level: 5)
|
239
|
+
fingerprint = fingerprint(email: email)
|
240
|
+
return unless fingerprint
|
241
|
+
|
242
|
+
trust = "#{fingerprint}:#{level + 1}:\n"
|
243
|
+
out, err, status = Open3.capture3('gpg --import-ownertrust', stdin_data: trust)
|
244
|
+
if status.success?
|
245
|
+
err
|
246
|
+
else
|
247
|
+
raise(Pgp::Failure, "GPG Failed trusting key: #{err} #{out}")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
212
251
|
end
|
213
252
|
end
|
@@ -39,7 +39,7 @@ module IOStreams
|
|
39
39
|
# compression: [:none|:zip|:zlib|:bzip2]
|
40
40
|
# Note: Standard PGP only supports :zip.
|
41
41
|
# :zlib is better than zip.
|
42
|
-
# :bzip2 is best, but uses a lot of memory.
|
42
|
+
# :bzip2 is best, but uses a lot of memory and is much slower.
|
43
43
|
# Default: :zip
|
44
44
|
#
|
45
45
|
# compress_level: [Integer]
|
@@ -64,7 +64,7 @@ module IOStreams
|
|
64
64
|
stdin.close
|
65
65
|
rescue Errno::EPIPE
|
66
66
|
# Ignore broken pipe because gpg terminates early due to an error
|
67
|
-
::File.delete(file_name_or_io)
|
67
|
+
::File.delete(file_name_or_io) if ::File.exist?(file_name_or_io)
|
68
68
|
raise(Pgp::Failure, "GPG Failed writing to encrypted file: #{file_name_or_io}: #{out.read.chomp}")
|
69
69
|
end
|
70
70
|
unless waith_thr.value.success?
|
@@ -58,8 +58,8 @@ module IOStreams
|
|
58
58
|
mode = binary ? 'wb' : 'w'
|
59
59
|
|
60
60
|
Net::SFTP.start(host, user, options) do |sftp|
|
61
|
-
sftp.session.exec!("mkdir -p '#{File.dirname(file_name)}'") if mkdir
|
62
|
-
sftp.file.open(file_name, mode, &
|
61
|
+
sftp.session.exec!("mkdir -p '#{::File.dirname(file_name)}'") if mkdir
|
62
|
+
sftp.file.open(file_name, mode, &block)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/lib/io_streams/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
# Unit Test for IOStreams::File
|
4
|
+
module Streams
|
5
|
+
class IOStreamsTest < Minitest::Test
|
6
|
+
describe IOStreams do
|
7
|
+
before do
|
8
|
+
@source_file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt')
|
9
|
+
@data = File.read(@source_file_name)
|
10
|
+
|
11
|
+
@temp_file = Tempfile.new('iostreams')
|
12
|
+
@target_file_name = @temp_file.to_path
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
@temp_file.delete if @temp_file
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.copy' do
|
20
|
+
it 'file' do
|
21
|
+
size = IOStreams.reader(@source_file_name) do |source_stream|
|
22
|
+
IOStreams.writer(@target_file_name) do |target_stream|
|
23
|
+
IOStreams.copy(source_stream, target_stream)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
actual = File.read(@target_file_name)
|
27
|
+
|
28
|
+
assert_equal actual, @data
|
29
|
+
assert_equal actual.size, size
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'stream' do
|
33
|
+
size = File.open(@source_file_name) do |source_stream|
|
34
|
+
IOStreams.writer(@target_file_name) do |target_stream|
|
35
|
+
IOStreams.copy(source_stream, target_stream)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
actual = File.read(@target_file_name)
|
39
|
+
|
40
|
+
assert_equal actual, @data
|
41
|
+
assert_equal actual.size, size
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.copy_file' do
|
46
|
+
it 'copies' do
|
47
|
+
size = IOStreams.copy_file(@source_file_name, @target_file_name)
|
48
|
+
actual = File.read(@target_file_name)
|
49
|
+
|
50
|
+
assert_equal actual, @data
|
51
|
+
assert_equal actual.size, size
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/test/pgp_writer_test.rb
CHANGED
@@ -76,9 +76,9 @@ module Streams
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'fails with stream output' do
|
79
|
-
|
79
|
+
string_io = StringIO.new
|
80
80
|
assert_raises NotImplementedError do
|
81
|
-
IOStreams::Pgp::Writer.open(
|
81
|
+
IOStreams::Pgp::Writer.open(string_io, recipient: 'receiver@example.org') do |io|
|
82
82
|
io.write(@data)
|
83
83
|
end
|
84
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iostreams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- test/files/text.zip
|
68
68
|
- test/gzip_reader_test.rb
|
69
69
|
- test/gzip_writer_test.rb
|
70
|
+
- test/io_streams_test.rb
|
70
71
|
- test/pgp_reader_test.rb
|
71
72
|
- test/pgp_writer_test.rb
|
72
73
|
- test/test_helper.rb
|
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.8
|
97
98
|
signing_key:
|
98
99
|
specification_version: 4
|
99
100
|
summary: Ruby file streaming. Supports Text, Zip, Gzip, Xlsx, csv, PGP / GPG and Symmetric
|
@@ -113,6 +114,7 @@ test_files:
|
|
113
114
|
- test/files/text.zip
|
114
115
|
- test/gzip_reader_test.rb
|
115
116
|
- test/gzip_writer_test.rb
|
117
|
+
- test/io_streams_test.rb
|
116
118
|
- test/pgp_reader_test.rb
|
117
119
|
- test/pgp_writer_test.rb
|
118
120
|
- test/test_helper.rb
|