icat4json 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/icat4json.gemspec +1 -0
- data/lib/icat4json/version.rb +1 -1
- data/lib/icat4json.rb +30 -8
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3727e373ff93beff148bf4f2706160925524744a37942a00c9583b79c6467197
|
|
4
|
+
data.tar.gz: 990b772c6e358431e5ad314d36d2fdb40e8ae933b78d3378462975a40d7444d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38b40e3e9c40f853c1781d9db001ff801b64b325f8d2e01606ecc5cf07964d36f79cd838308f178b4bd11eb8067f7ed61ffcb14158947c5b862b11a176ce2a6f
|
|
7
|
+
data.tar.gz: 6e23c34687d8f1602a8bd78c8fe84464168c8b9a568bae236414ec1a42382911e1fa94acf1f8607ccd5aa6cd54b8a6923ce3edc25e5fb3b210988c5373fd22b2
|
data/icat4json.gemspec
CHANGED
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.description = "A Ruby gem to fetch and parse vulnerability information from IPA's icat for JSON feed. Provides easy access to Japanese vulnerability database."
|
|
12
12
|
spec.homepage = "https://github.com/masoo/icat4json"
|
|
13
13
|
spec.license = "MIT"
|
|
14
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
14
15
|
spec.files = Dir.glob("{lib}/**/*").push(
|
|
15
16
|
"LICENSE.txt", "README.md", "icat4json.gemspec"
|
|
16
17
|
).select { |f| File.file?(f) }
|
data/lib/icat4json/version.rb
CHANGED
data/lib/icat4json.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "icat4json/version"
|
|
2
2
|
require "net/http"
|
|
3
|
+
require "openssl"
|
|
3
4
|
require "uri"
|
|
4
5
|
require "json"
|
|
5
6
|
|
|
@@ -31,16 +32,31 @@ module ICat4JSON
|
|
|
31
32
|
http.open_timeout = 10
|
|
32
33
|
http.read_timeout = 10
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
body = +""
|
|
36
|
+
# 全体を読み込んでから比較すると(gzip 展開後の)巨大な応答がメモリに載るため、
|
|
37
|
+
# 受信しながらサイズを確認して上限超過の時点で打ち切る
|
|
38
|
+
http.request(Net::HTTP::Get.new(uri)) do |response|
|
|
39
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
40
|
+
raise ConnectionError, "HTTP request failed with status #{response.code}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
response.read_body do |chunk|
|
|
44
|
+
body << chunk
|
|
45
|
+
if body.bytesize > MAX_RESPONSE_SIZE
|
|
46
|
+
raise Error, "Response too large: exceeds #{MAX_RESPONSE_SIZE} bytes"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
37
49
|
end
|
|
50
|
+
to_utf8(body)
|
|
51
|
+
rescue SocketError, SystemCallError, IOError, OpenSSL::SSL::SSLError,
|
|
52
|
+
Timeout::Error, Net::ProtocolError, Net::HTTPBadResponse => e
|
|
53
|
+
raise ConnectionError, "HTTP request failed: #{e.class}: #{e.message}"
|
|
54
|
+
end
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
raise ConnectionError, "HTTP request failed: #{e.message}"
|
|
56
|
+
def to_utf8(body)
|
|
57
|
+
body.force_encoding(Encoding::UTF_8)
|
|
58
|
+
raise ParseError, "Response is not valid UTF-8" unless body.valid_encoding?
|
|
59
|
+
body
|
|
44
60
|
end
|
|
45
61
|
|
|
46
62
|
def parse_json(raw)
|
|
@@ -50,6 +66,8 @@ module ICat4JSON
|
|
|
50
66
|
end
|
|
51
67
|
|
|
52
68
|
def build_icat_data(json)
|
|
69
|
+
raise ParseError, "Unexpected JSON structure: top level must be an object" unless json.is_a?(Hash)
|
|
70
|
+
|
|
53
71
|
ICATData.new(
|
|
54
72
|
itemdata: build_item_data(json["itemdata"]),
|
|
55
73
|
docTitle: json["docTitle"],
|
|
@@ -61,7 +79,11 @@ module ICat4JSON
|
|
|
61
79
|
|
|
62
80
|
def build_item_data(items)
|
|
63
81
|
return [] if items.nil?
|
|
82
|
+
raise ParseError, "Unexpected JSON structure: itemdata must be an array" unless items.is_a?(Array)
|
|
83
|
+
|
|
64
84
|
items.map do |h|
|
|
85
|
+
raise ParseError, "Unexpected JSON structure: itemdata elements must be objects" unless h.is_a?(Hash)
|
|
86
|
+
|
|
65
87
|
ItemData.new(
|
|
66
88
|
item_title: h["item_title"],
|
|
67
89
|
item_link: h["item_link"],
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: icat4json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- FUNABARA Masao
|
|
@@ -95,7 +95,8 @@ files:
|
|
|
95
95
|
homepage: https://github.com/masoo/icat4json
|
|
96
96
|
licenses:
|
|
97
97
|
- MIT
|
|
98
|
-
metadata:
|
|
98
|
+
metadata:
|
|
99
|
+
rubygems_mfa_required: 'true'
|
|
99
100
|
rdoc_options: []
|
|
100
101
|
require_paths:
|
|
101
102
|
- lib
|