icat4json 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c85d6a903ebea3b9c793c9afe4896bdcefe2623d3fdb12ad38caab5d80d0911f
4
- data.tar.gz: 12e136c7720e1ba168b44cec60242aa0314abbe818e6ffa04909bfcf569aaaa8
3
+ metadata.gz: d281a60d9b2f391e08a65bed60ac3ce0342ab07c5819317831629821bb96f48c
4
+ data.tar.gz: e129d880c36496294002f27ba6bef62d28187d328685fcf0f2d3ea6044406aa3
5
5
  SHA512:
6
- metadata.gz: c2e294b7257bfaff1a98631900252be8f903148d43f8d8623a33e95ad5765126968b4bd75c04b247f92685241fe54c6356aa645472c89a9e6e6f6d8c692b9775
7
- data.tar.gz: c31a4de53e09cdb2a3e85ed1d0a7f106fde2fb85247e6ee19d94db0ca1b1723f45f4b4837c9d0489de4aaed3c19f0f31ec1702be3a23859afaa52b08606e3edf
6
+ metadata.gz: 50ee08b358a5902eecad7fb03e88d9e355547cf36319527a0f0ff6abab35ca9b9a1cf6da291b5beeefc31e13558a2b78eb5913fa3eeea0dd897539c7ee931289
7
+ data.tar.gz: 2d43be11039034792748e0377155bda36e6e3c98660527d218b89e3cc307fe77906696f02b368481b5673825fe101a53d7b2ceec467cde99b53750022caa85d3
data/README.md CHANGED
@@ -28,12 +28,27 @@ require 'icat4json'
28
28
 
29
29
  so,
30
30
 
31
- ```
31
+ ```ruby
32
32
  data = ICat4JSON.new
33
33
  puts data.json
34
34
  puts data.icat
35
35
  ```
36
36
 
37
+ ### Error Handling
38
+
39
+ ```ruby
40
+ begin
41
+ data = ICat4JSON.new
42
+ puts data.icat.docTitle
43
+ rescue ICat4JSON::ConnectionError => e
44
+ puts "Connection failed: #{e.message}"
45
+ rescue ICat4JSON::ParseError => e
46
+ puts "Failed to parse response: #{e.message}"
47
+ rescue ICat4JSON::Error => e
48
+ puts "Error: #{e.message}"
49
+ end
50
+ ```
51
+
37
52
  ## Development
38
53
 
39
54
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -42,7 +57,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
42
57
 
43
58
  ## Contributing
44
59
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/icat4json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/masoo/icat4json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
61
 
47
62
  ## License
48
63
 
data/icat4json.gemspec CHANGED
@@ -11,16 +11,17 @@ 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.files = `git ls-files -z`.split("\x0").reject do |f|
15
- f.match(%r{^(test|spec|features)/})
16
- end
14
+ spec.files = Dir.glob("{lib}/**/*").push(
15
+ "LICENSE.txt", "README.md", "icat4json.gemspec"
16
+ ).select { |f| File.file?(f) }
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
  spec.required_ruby_version = ">= 3.2.0"
21
21
 
22
- spec.add_development_dependency "bundler", "~> 2.0"
23
22
  spec.add_development_dependency "rake", "~> 13.0"
24
23
  spec.add_development_dependency "irb"
25
24
  spec.add_development_dependency "standard", "~> 1.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "webmock", "~> 3.0"
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module ICat4JSON
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/icat4json.rb CHANGED
@@ -4,43 +4,76 @@ require "uri"
4
4
  require "json"
5
5
 
6
6
  module ICat4JSON
7
+ class Error < StandardError; end
8
+ class ConnectionError < Error; end
9
+ class ParseError < Error; end
10
+
7
11
  class ICat4JSON
8
12
  attr_reader :json, :icat
9
13
 
14
+ MAX_RESPONSE_SIZE = 1_048_576
15
+
10
16
  ICATData = Struct.new(:itemdata, :docTitle, :docTitleFix, :docLink, :docDate)
11
17
  ItemData = Struct.new(:item_title, :item_link, :item_date, :item_identifier)
12
18
 
13
19
  def initialize
14
- begin
15
- uri = URI.parse(icat4json_url)
16
- http = Net::HTTP.get(uri)
17
- rescue => e
18
- raise e, "HTTP request failed: #{e.message}"
19
- end
20
+ raw = fetch_feed
21
+ @json = parse_json(raw)
22
+ @icat = build_icat_data(@json)
23
+ end
20
24
 
21
- begin
22
- @json = JSON.parse(http)
23
- rescue JSON::ParserError => e
24
- raise e, "JSON parsing failed: #{e.message}"
25
- end
25
+ private
26
26
 
27
- @icat = ICATData.new
28
- @json.each { |k, v| icat[k] = v unless k == "itemdata" }
29
- @icat[:itemdata] = []
30
- @json["itemdata"].each do |itemdata|
31
- item = ItemData.new
32
- itemdata.each do |k, v|
33
- item[k] = v
34
- end
35
- @icat[:itemdata].push item
27
+ def fetch_feed
28
+ uri = URI.parse(icat4json_url)
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+ http.use_ssl = (uri.scheme == "https")
31
+ http.open_timeout = 10
32
+ http.read_timeout = 10
33
+
34
+ response = http.request(Net::HTTP::Get.new(uri))
35
+ unless response.is_a?(Net::HTTPSuccess)
36
+ raise ConnectionError, "HTTP request failed with status #{response.code}"
36
37
  end
38
+
39
+ body = response.body
40
+ raise Error, "Response too large: #{body.bytesize} bytes" if body.bytesize > MAX_RESPONSE_SIZE
41
+ body.encode("UTF-8")
42
+ rescue SocketError, Timeout::Error => e
43
+ raise ConnectionError, "HTTP request failed: #{e.message}"
37
44
  end
38
45
 
39
- private
46
+ def parse_json(raw)
47
+ JSON.parse(raw)
48
+ rescue JSON::ParserError => e
49
+ raise ParseError, "JSON parsing failed: #{e.message}"
50
+ end
51
+
52
+ def build_icat_data(json)
53
+ ICATData.new(
54
+ itemdata: build_item_data(json["itemdata"]),
55
+ docTitle: json["docTitle"],
56
+ docTitleFix: json["docTitleFix"],
57
+ docLink: json["docLink"],
58
+ docDate: json["docDate"]
59
+ )
60
+ end
61
+
62
+ def build_item_data(items)
63
+ return [] if items.nil?
64
+ items.map do |h|
65
+ ItemData.new(
66
+ item_title: h["item_title"],
67
+ item_link: h["item_link"],
68
+ item_date: h["item_date"],
69
+ item_identifier: h["item_identifier"]
70
+ )
71
+ end
72
+ end
40
73
 
41
74
  # analize https://www.ipa.go.jp/security/announce/irss/icatw2.js
42
75
  def icat4json_url
43
- "http://isec-myjvn-feed1.ipa.go.jp/IPARssReader.php?#{Time.now.to_i}&tool=icatw"
76
+ "https://isec-myjvn-feed1.ipa.go.jp/IPARssReader.php?#{Time.now.to_i}&tool=icatw"
44
77
  end
45
78
  end
46
79
 
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUNABARA Masao
@@ -9,20 +9,6 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: bundler
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '2.0'
19
- type: :development
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '2.0'
26
12
  - !ruby/object:Gem::Dependency
27
13
  name: rake
28
14
  requirement: !ruby/object:Gem::Requirement
@@ -65,6 +51,34 @@ dependencies:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
53
  version: '1.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: minitest
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: webmock
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
68
82
  description: A Ruby gem to fetch and parse vulnerability information from IPA's icat
69
83
  for JSON feed. Provides easy access to Japanese vulnerability database.
70
84
  email:
@@ -73,16 +87,8 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - ".gitignore"
77
- - CODE_OF_CONDUCT.md
78
- - Gemfile
79
- - Gemfile.lock
80
90
  - LICENSE.txt
81
91
  - README.md
82
- - Rakefile
83
- - Taskfile.yml
84
- - bin/console
85
- - bin/setup
86
92
  - icat4json.gemspec
87
93
  - lib/icat4json.rb
88
94
  - lib/icat4json/version.rb
@@ -104,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
110
  - !ruby/object:Gem::Version
105
111
  version: '0'
106
112
  requirements: []
107
- rubygems_version: 3.6.9
113
+ rubygems_version: 4.0.3
108
114
  specification_version: 4
109
115
  summary: Ruby client for IPA's icat for JSON vulnerability feed
110
116
  test_files: []
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- .ruby-version
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at masao@masoo.jp. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in icat4json.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,87 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- icat4json (1.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.3)
10
- date (3.4.1)
11
- erb (5.0.2)
12
- io-console (0.8.1)
13
- irb (1.15.2)
14
- pp (>= 0.6.0)
15
- rdoc (>= 4.0.0)
16
- reline (>= 0.4.2)
17
- json (2.15.0)
18
- language_server-protocol (3.17.0.5)
19
- lint_roller (1.1.0)
20
- parallel (1.27.0)
21
- parser (3.3.9.0)
22
- ast (~> 2.4.1)
23
- racc
24
- pp (0.6.2)
25
- prettyprint
26
- prettyprint (0.2.0)
27
- prism (1.5.1)
28
- psych (5.2.6)
29
- date
30
- stringio
31
- racc (1.8.1)
32
- rainbow (3.1.1)
33
- rake (13.3.0)
34
- rdoc (6.14.2)
35
- erb
36
- psych (>= 4.0.0)
37
- regexp_parser (2.11.3)
38
- reline (0.6.2)
39
- io-console (~> 0.5)
40
- rubocop (1.80.2)
41
- json (~> 2.3)
42
- language_server-protocol (~> 3.17.0.2)
43
- lint_roller (~> 1.1.0)
44
- parallel (~> 1.10)
45
- parser (>= 3.3.0.2)
46
- rainbow (>= 2.2.2, < 4.0)
47
- regexp_parser (>= 2.9.3, < 3.0)
48
- rubocop-ast (>= 1.46.0, < 2.0)
49
- ruby-progressbar (~> 1.7)
50
- unicode-display_width (>= 2.4.0, < 4.0)
51
- rubocop-ast (1.47.1)
52
- parser (>= 3.3.7.2)
53
- prism (~> 1.4)
54
- rubocop-performance (1.25.0)
55
- lint_roller (~> 1.1)
56
- rubocop (>= 1.75.0, < 2.0)
57
- rubocop-ast (>= 1.38.0, < 2.0)
58
- ruby-progressbar (1.13.0)
59
- standard (1.51.1)
60
- language_server-protocol (~> 3.17.0.2)
61
- lint_roller (~> 1.0)
62
- rubocop (~> 1.80.2)
63
- standard-custom (~> 1.0.0)
64
- standard-performance (~> 1.8)
65
- standard-custom (1.0.2)
66
- lint_roller (~> 1.0)
67
- rubocop (~> 1.50)
68
- standard-performance (1.8.0)
69
- lint_roller (~> 1.1)
70
- rubocop-performance (~> 1.25.0)
71
- stringio (3.1.7)
72
- unicode-display_width (3.2.0)
73
- unicode-emoji (~> 4.1)
74
- unicode-emoji (4.1.0)
75
-
76
- PLATFORMS
77
- ruby
78
-
79
- DEPENDENCIES
80
- bundler (~> 2.0)
81
- icat4json!
82
- irb
83
- rake (~> 13.0)
84
- standard (~> 1.0)
85
-
86
- BUNDLED WITH
87
- 2.5.18
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task default: :spec
data/Taskfile.yml DELETED
@@ -1,23 +0,0 @@
1
- version: '3'
2
-
3
- tasks:
4
- default:
5
- desc: help
6
- deps:
7
- - help
8
-
9
- build:
10
- desc: Build the gem
11
- cmds:
12
- - gem build
13
-
14
- release:
15
- cmds:
16
- - rake release
17
- desc: Release a new version of the gem
18
-
19
- help:
20
- desc: list all tasks
21
- silent: true
22
- cmds:
23
- - task --list-all
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "icat4json"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here