data_collector 0.29.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data_collector.gemspec +4 -4
- data/lib/data_collector/input.rb +52 -29
- data/lib/data_collector/output.rb +2 -0
- data/lib/data_collector/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec0485c6ec0c9c429f8dcef45b7357874f3f6de8449902f54f38a1fb36e2548a
|
4
|
+
data.tar.gz: 57820299fe1718fa07e561dc933c14d04aa2fbfe5ad264dfafa2db861c162aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aea723ca8aee53554b06259ad463b7bc460b0363bfce702dd3d7292519c185660fd86270a3d9b6c84db49133ed74d57eebcf27fcf974184465506967b96de56b
|
7
|
+
data.tar.gz: ffc8d3e780aab83742fc8fefdabf3f10fbdcbed5fdcddce1a69c81754e84f951e7b7ccd896037f91f82f7da23d8fd650c67d6982281ab80f23e5bb54ec0c9537
|
data/data_collector.gemspec
CHANGED
@@ -36,18 +36,18 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
37
|
spec.require_paths = ['lib']
|
38
38
|
|
39
|
-
spec.add_runtime_dependency 'activesupport', '~>
|
39
|
+
spec.add_runtime_dependency 'activesupport', '~> 7.0'
|
40
40
|
spec.add_runtime_dependency 'http', '~> 5.1'
|
41
41
|
spec.add_runtime_dependency 'json', '~> 2.6'
|
42
|
-
spec.add_runtime_dependency 'json-ld', '~> 3.
|
42
|
+
spec.add_runtime_dependency 'json-ld', '~> 3.3'
|
43
43
|
spec.add_runtime_dependency 'jsonpath', '~> 1.1'
|
44
|
-
spec.add_runtime_dependency 'mime-types', '~> 3.
|
44
|
+
spec.add_runtime_dependency 'mime-types', '~> 3.5'
|
45
45
|
spec.add_runtime_dependency 'minitar', '= 0.9'
|
46
46
|
spec.add_runtime_dependency 'nokogiri', '~> 1.15'
|
47
47
|
spec.add_runtime_dependency 'nori', '~> 2.6'
|
48
48
|
spec.add_runtime_dependency 'iso8601', '~> 0.13'
|
49
49
|
spec.add_runtime_dependency 'listen', '~> 3.8'
|
50
|
-
spec.add_runtime_dependency 'bunny', '~> 2.
|
50
|
+
spec.add_runtime_dependency 'bunny', '~> 2.22'
|
51
51
|
spec.add_runtime_dependency 'bunny_burrow', '~> 1.5'
|
52
52
|
spec.add_runtime_dependency 'builder', '~> 3.2'
|
53
53
|
spec.add_runtime_dependency 'parse-cron', '~> 0.1'
|
data/lib/data_collector/input.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#encoding: UTF-8
|
1
|
+
# encoding: UTF-8
|
2
2
|
require 'http'
|
3
3
|
require 'open-uri'
|
4
4
|
require 'nokogiri'
|
@@ -16,7 +16,7 @@ require_relative 'input/dir'
|
|
16
16
|
require_relative 'input/queue'
|
17
17
|
require_relative 'input/rpc'
|
18
18
|
|
19
|
-
#require_relative 'ext/xml_utility_node'
|
19
|
+
# require_relative 'ext/xml_utility_node'
|
20
20
|
module DataCollector
|
21
21
|
class Input
|
22
22
|
attr_reader :raw
|
@@ -25,13 +25,14 @@ module DataCollector
|
|
25
25
|
@logger = Logger.new(STDOUT)
|
26
26
|
end
|
27
27
|
|
28
|
-
def from_uri(source, options = {})
|
28
|
+
def from_uri(source, options = {}, &block)
|
29
|
+
block_consumed = false
|
29
30
|
source = CGI.unescapeHTML(source)
|
30
31
|
@logger.info("Reading #{source}")
|
31
32
|
raise DataCollector::Error, 'from_uri expects a scheme like file:// of https://' unless source =~ /:\/\//
|
32
33
|
|
33
34
|
scheme, path = source.split('://')
|
34
|
-
source="#{scheme}://#{URI.encode_www_form_component(path)}"
|
35
|
+
source = "#{scheme}://#{URI.encode_www_form_component(path)}"
|
35
36
|
uri = URI(source)
|
36
37
|
begin
|
37
38
|
data = nil
|
@@ -43,11 +44,14 @@ module DataCollector
|
|
43
44
|
when 'file'
|
44
45
|
absolute_path = File.absolute_path("#{URI.decode_www_form_component("#{uri.host}#{uri.path}")}")
|
45
46
|
if File.directory?(absolute_path)
|
46
|
-
#raise DataCollector::Error, "#{uri.host}/#{uri.path} not found" unless File.exist?("#{uri.host}/#{uri.path}")
|
47
47
|
return from_dir(uri, options)
|
48
48
|
else
|
49
|
-
|
50
|
-
|
49
|
+
if block_given?
|
50
|
+
data = from_file(uri, options, &block)
|
51
|
+
block_consumed = true if data.is_a?(TrueClass)
|
52
|
+
else
|
53
|
+
data = from_file(uri, options)
|
54
|
+
end
|
51
55
|
end
|
52
56
|
when /amqp/
|
53
57
|
if uri.scheme =~ /^rpc/
|
@@ -61,7 +65,7 @@ module DataCollector
|
|
61
65
|
|
62
66
|
data = data.nil? ? 'no data found' : data
|
63
67
|
|
64
|
-
if block_given?
|
68
|
+
if block_given? && !block_consumed
|
65
69
|
yield data
|
66
70
|
else
|
67
71
|
data
|
@@ -94,7 +98,7 @@ module DataCollector
|
|
94
98
|
|
95
99
|
http = HTTP
|
96
100
|
|
97
|
-
#http.use(logging: {logger: @logger})
|
101
|
+
# http.use(logging: {logger: @logger})
|
98
102
|
|
99
103
|
if options.key?(:user) && options.key?(:password)
|
100
104
|
@logger.debug "Set Basic_auth"
|
@@ -102,34 +106,33 @@ module DataCollector
|
|
102
106
|
password = options[:password]
|
103
107
|
http = HTTP.basic_auth(user: user, pass: password)
|
104
108
|
elsif options.key?(:bearer_token)
|
105
|
-
@logger.debug
|
109
|
+
@logger.debug "Set authorization bearer token"
|
106
110
|
bearer = options[:bearer_token]
|
107
111
|
bearer = "Bearer #{bearer}" unless bearer =~ /^Bearer /i
|
108
112
|
http = HTTP.auth(bearer)
|
109
113
|
end
|
110
114
|
|
111
|
-
if options.key?(:cookies)
|
112
|
-
@logger.debug
|
113
|
-
http = http.cookies(
|
115
|
+
if options.key?(:cookies)
|
116
|
+
@logger.debug "Set cookies"
|
117
|
+
http = http.cookies(options[:cookies])
|
114
118
|
end
|
115
119
|
|
116
|
-
if options.key?(:headers)
|
117
|
-
@logger.debug
|
118
|
-
http = http.headers(
|
120
|
+
if options.key?(:headers)
|
121
|
+
@logger.debug "Set http headers"
|
122
|
+
http = http.headers(options[:headers])
|
119
123
|
end
|
120
|
-
|
124
|
+
|
121
125
|
if options.key?(:verify_ssl) && uri.scheme.eql?('https')
|
122
126
|
@logger.warn "Disabling SSL verification. "
|
123
|
-
#shouldn't use this but we all do ...
|
127
|
+
# shouldn't use this but we all do ...
|
124
128
|
ctx = OpenSSL::SSL::SSLContext.new
|
125
129
|
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
126
130
|
|
127
131
|
http_response = http.follow.get(escape_uri(uri), ssl_context: ctx)
|
128
|
-
|
129
132
|
else
|
130
133
|
http_response = http.follow.get(escape_uri(uri))
|
131
134
|
end
|
132
|
-
|
135
|
+
|
133
136
|
case http_response.code
|
134
137
|
when 200..299
|
135
138
|
@raw = data = http_response.body.to_s
|
@@ -159,7 +162,7 @@ module DataCollector
|
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
162
|
-
raise '206 Partial Content' if http_response.code ==206
|
165
|
+
raise '206 Partial Content' if http_response.code == 206
|
163
166
|
|
164
167
|
when 401
|
165
168
|
raise DataCollector::InputError, 'Unauthorized'
|
@@ -175,7 +178,7 @@ module DataCollector
|
|
175
178
|
data
|
176
179
|
end
|
177
180
|
|
178
|
-
def from_file(uri, options = {})
|
181
|
+
def from_file(uri, options = {}, &block)
|
179
182
|
data = nil
|
180
183
|
uri = normalize_uri(uri)
|
181
184
|
absolute_path = File.absolute_path(uri)
|
@@ -190,12 +193,29 @@ module DataCollector
|
|
190
193
|
when '.xml'
|
191
194
|
data = xml_to_hash(data, options)
|
192
195
|
when '.gz'
|
196
|
+
tar_data = []
|
193
197
|
Minitar.open(Zlib::GzipReader.new(File.open("#{absolute_path}", 'rb'))) do |i|
|
194
198
|
i.each do |entry|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
+
next unless entry.typeflag.eql?('0')
|
200
|
+
if block_given?
|
201
|
+
data = xml_to_hash(entry.read, options)
|
202
|
+
yield data
|
203
|
+
|
204
|
+
data = true
|
205
|
+
else
|
206
|
+
tar_data << entry.read
|
207
|
+
|
208
|
+
if tar_data.length == 1
|
209
|
+
data = xml_to_hash(tar_data.first, options)
|
210
|
+
else
|
211
|
+
data = []
|
212
|
+
tar_data.each do |d|
|
213
|
+
data << xml_to_hash(d, options)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end #block
|
217
|
+
end #entry
|
218
|
+
end #tar
|
199
219
|
when '.csv'
|
200
220
|
data = csv_to_hash(data)
|
201
221
|
else
|
@@ -219,9 +239,12 @@ module DataCollector
|
|
219
239
|
end
|
220
240
|
|
221
241
|
def xml_to_hash(data, options = {})
|
222
|
-
#gsub('<\/', '< /') outherwise wrong XML-parsing (see records lirias1729192 )
|
223
|
-
data.
|
242
|
+
# gsub('<\/', '< /') outherwise wrong XML-parsing (see records lirias1729192 )
|
243
|
+
return unless data.is_a?(String)
|
244
|
+
data.force_encoding('UTF-8')
|
245
|
+
data = data.encode("UTF-8", invalid: :replace, replace: "")
|
224
246
|
data = data.gsub /</, '< /'
|
247
|
+
|
225
248
|
xml_typecast = options.with_indifferent_access.key?('xml_typecast') ? options.with_indifferent_access['xml_typecast'] : true
|
226
249
|
nori = Nori.new(parser: :nokogiri, advanced_typecasting: xml_typecast, strip_namespaces: true, convert_tags_to: lambda { |tag| tag.gsub(/^@/, '_') })
|
227
250
|
nori.parse(data)
|
@@ -245,7 +268,7 @@ module DataCollector
|
|
245
268
|
file_type = if headers.include?('Content-Type')
|
246
269
|
headers['Content-Type'].split(';').first
|
247
270
|
else
|
248
|
-
@logger.debug
|
271
|
+
@logger.debug "No Header content-type available"
|
249
272
|
MIME::Types.of(filename_from(headers)).first.content_type
|
250
273
|
end
|
251
274
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.0'
|
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: '
|
26
|
+
version: '7.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: http
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.3'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jsonpath
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.5'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.5'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: minitar
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '2.
|
173
|
+
version: '2.22'
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '2.
|
180
|
+
version: '2.22'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: bunny_burrow
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -333,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
333
|
- !ruby/object:Gem::Version
|
334
334
|
version: '0'
|
335
335
|
requirements: []
|
336
|
-
rubygems_version: 3.4.
|
336
|
+
rubygems_version: 3.4.19
|
337
337
|
signing_key:
|
338
338
|
specification_version: 4
|
339
339
|
summary: ETL helper library
|