Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 4.0
bundler-cache: true
- name: Setup rubocop
run: |
bundle install --with=rubocop
bundle config set with rubocop
bundle install
- name: Execute rubocop
run: |
bundle exec rubocop
5 changes: 3 additions & 2 deletions .github/workflows/spec_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 4.0
bundler-cache: true
- name: Setup bundle
run: |
bundle install --with=test
bundle config set with test
bundle install
- name: Run rspec
run: |
bundle exec rspec
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
ruby-version: 4.0
bundler-cache: true
- name: Setup rubocop
run: |
bundle install --with=rubocop
bundle config set with rubocop
bundle install
- name: Run tests
run: |
bundle exec ruby test/all.rb
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stages:
- test

variables:
RUBY_VERSION: "3.3"
RUBY_VERSION: "4.0"
RUBY_IMAGE: "ruby:${RUBY_VERSION}-bookworm"

.common:
Expand Down
11 changes: 9 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AllCops:
TargetRubyVersion: 3.3
TargetRubyVersion: 4.0
NewCops: enable

require:
plugins:
- rubocop-rspec

Layout/LineLength:
Expand All @@ -17,6 +17,13 @@ Layout/SpaceInsideBlockBraces:
Exclude:
- 'Gemfile'

Style/OneClassPerFile:
Exclude:
- parse_dsalist.rb
- lib/deb_erratum_rss.rb
- gen_errata.rb
- debRelease.rb


Metrics/AbcSize:
Max: 73
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:3.3-bookworm
FROM ruby:4.0-trixie

LABEL maintainer="Markus Bucher <bucher@atix.de>" \
description="This container provides an errata-parser for Debian and Ubuntu" \
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem 'parallel', '~> 1.20', '< 1.21', group: %i[build test]

# Added at 2018-12-05 19:28:10 +0100 by markus:
group :rubocop, optional: true do
gem "rubocop", "~> 1.51.0"
gem "rubocop", "~> 1.88.0"
gem "rubocop-rspec", "~> 3.0"
end

Expand All @@ -45,3 +45,5 @@ end
gem "feedjira", "~> 3.2", group: :monitor

gem "faraday", "~> 2.14", group: :monitor

gem "fiddle", "~> 1.1", group: %i[build test]
34 changes: 21 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ GEM
loofah (>= 2.3.1, < 3)
sax-machine (>= 1.0, < 2)
ffi (1.17.4-x86_64-linux-gnu)
fiddle (1.1.8)
json (2.21.1)
json-stream (1.0.0)
json-streamer (2.1.0)
json-stream
language_server-protocol (3.17.0.6)
lint_roller (1.1.0)
logger (1.7.0)
loofah (2.25.2)
crass (~> 1.0.2)
Expand All @@ -45,7 +48,6 @@ GEM
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.12.0)
rexml (3.4.4)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -61,21 +63,24 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
rubocop (1.51.0)
rubocop (1.88.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (>= 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.50.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-rspec (3.0.0)
rubocop (~> 1.40)
rubocop-rspec (3.10.2)
lint_roller (~> 1.1)
regexp_parser (>= 2.0)
rubocop (~> 1.86, >= 1.86.2)
ruby-debian (0.3.8)
ruby-progressbar (1.13.0)
ruby-xz (1.0.3)
Expand All @@ -89,7 +94,9 @@ GEM
simplecov_json_formatter (0.1.4)
test-unit (3.7.8)
power_assert
unicode-display_width (2.6.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
uri (1.1.1)

PLATFORMS
Expand All @@ -100,12 +107,13 @@ DEPENDENCIES
bzip2-ffi (~> 1.0)
faraday (~> 2.14)
feedjira (~> 3.2)
fiddle (~> 1.1)
json-streamer (~> 2.1)
parallel (~> 1.20, < 1.21)
pry (~> 0.14.2)
rspec (~> 3.13)
rspec-collection_matchers (~> 1.2)
rubocop (~> 1.51.0)
rubocop (~> 1.88.0)
rubocop-rspec (~> 3.0)
ruby-debian (~> 0.3.8)
ruby-xz (~> 1.0)
Expand All @@ -114,4 +122,4 @@ DEPENDENCIES
test-unit (~> 3.5)

BUNDLED WITH
2.5.9
4.0.16
7 changes: 3 additions & 4 deletions debRelease.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'debian'
require 'fileutils'
require 'time'
require 'pathname'
require 'xz'
require 'zlib'

Expand All @@ -13,6 +12,7 @@
# Debian / Ubuntu release file download / parsing
class DebRelease
include Downloader

@@tempdir = '/tmp/errata_parser_cache/debian'

attr_reader :data, :files
Expand Down Expand Up @@ -233,8 +233,7 @@ def self.assemble_ubuntu_packages(target, source)
end

threads = []
pckgs = []
suites.each do |s|
pckgs = suites.map do |s|
threads << Thread.new do
warn "Loading Release for #{s.inspect}"
debrel = DebRelease.new(repository_url, s)
Expand All @@ -245,7 +244,7 @@ def self.assemble_ubuntu_packages(target, source)

warn "From #{s.inspect} get archs:#{debrel.architectures.inspect} and comps: #{debrel.components.inspect}"

pckgs << debrel.all_packages
debrel.all_packages
end
end

Expand Down
2 changes: 2 additions & 0 deletions errata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ def load_config(filename)

repository = cfg['repository']

# rubocop:disable Style/MapIntoArray
repository['releases'].each do |s|
# rubocop:enable Style/MapIntoArray
threads << Thread.new do
Thread.current[:repo_url] = repository['repo_url']
if repository.key?('credentials')
Expand Down
21 changes: 9 additions & 12 deletions gen_errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'yaml'
require 'time'
require 'debian'
require 'pathname'

require_relative 'parse_dsalist'
require_relative 'downloader'
Expand Down Expand Up @@ -379,7 +378,7 @@ def gen_ubuntu_errata(usn_db, packages, packages_by_name, release_whitelist=nil,

package = {}
pkg.each do |k, v|
package[k.to_sym || key] = v
package[k.to_sym] = v
end
package[:release] = rel

Expand Down Expand Up @@ -596,21 +595,19 @@ def get_binary_packages_for_erratum_package(source_pkg, pkg, packages, architect
require 'bzip2/ffi'
require 'stringio'

usn_db_f = File.open('test/data/database.json.bz2', 'rb')

packages = JSON.parse(File.read('test/data/packages_everything_ubuntu.json'))
errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), packages, {}, ['bionic'], ['amd64'])
usn_db_f.close
File.open('test/data/database.json.bz2', 'rb') do |usn_db_f|
packages = JSON.parse(File.read('test/data/packages_everything_ubuntu.json'))
errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), packages, {}, ['bionic'], ['amd64'])
end

when 'ubuntu-esm_test_record'
require 'bzip2/ffi'
require 'stringio'

usn_db_f = File.open('test/data/database.json.bz2', 'rb')

packages_by_name = JSON.parse(File.read('test/data/packages_everything_ubuntu_debstyle.json'))
errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), {}, packages_by_name, ['xenial'], ['amd64'])
usn_db_f.close
File.open('test/data/database.json.bz2', 'rb') do |usn_db_f|
packages_by_name = JSON.parse(File.read('test/data/packages_everything_ubuntu_debstyle.json'))
errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), {}, packages_by_name, ['xenial'], ['amd64'])
end

else
warn "Unsupported option #{type}"
Expand Down
5 changes: 3 additions & 2 deletions parse_dsalist.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

require 'json'
require 'stringio'

REGEX_1ST_LINE = /^\[(?<date>[^\]]+)\]\s*(?<ident>[A-z0-9-]+)\s*(?<package>\S+)\s*-*\s*(?<typ>.*)$/
REGEX_1ST_LINE = /^\[(?<date>[^\]]+)\]\s*(?<ident>[A-Za-z0-9-]+)\s*(?<package>\S+)\s*-*\s*(?<typ>.*)$/
REGEX_CVE_LINE = /\s+{(?<cves>[^}]*)}/
REGEX_REL_LINE = /\s+\[(?<release>[^\]]*)\]\s*-\s*(?<package>\S+)\s*(?<version>\S*)/
REGEX_NOT_LINE = /\s+NOTE:/
Expand Down Expand Up @@ -82,7 +83,7 @@ def add_cve(cve_numbers)
end

def cve_empty?
(@cve.nil? || @cve.empty?)
@cve.nil? || @cve.empty?
end

def add_release(release:, package:, version:)
Expand Down
9 changes: 4 additions & 5 deletions test/gen_test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Download
cve_list.each do |package, cves|
cves_filtered = {}
cves.each do |cve_id, cve|
releases = cve['releases'].select { |release, _pkgs| releases.include? release }
releases = cve['releases'].slice(*releases)
if cve_ids.include?(cve_id) || !releases.empty?
cves_filtered[cve_id] = cve.clone
cves_filtered[cve_id]['releases'] = releases
Expand All @@ -71,7 +71,7 @@ class Download
usn_db = Download.new.download_file_cached(config_ubuntu['usn_list_url'])
usn_db_filtered = {}
JSON.parse(Bzip2::FFI::Reader.read(StringIO.new(usn_db))).each do |usn_id, usn_data|
releases_data = usn_data['releases'].select { |r, _dat| rel_whitelist.include? r }
releases_data = usn_data['releases'].slice(*rel_whitelist)
next if releases_data.empty?

usn_db_filtered[usn_id] = usn_data.clone.merge('releases' => releases_data)
Expand Down Expand Up @@ -121,8 +121,7 @@ class Download
end

threads = []
pckgs = []
suites.each do |s|
pckgs = suites.map do |s|
threads << Thread.new do
warn "Loading Release for #{s.inspect}"
debrel = DebRelease.new(repository_url, s)
Expand All @@ -133,7 +132,7 @@ class Download

warn "From #{s.inspect} get archs:#{debrel.architectures.inspect} and comps: #{debrel.components.inspect}"

pckgs << debrel.all_packages
debrel.all_packages
end
end

Expand Down
46 changes: 24 additions & 22 deletions test/test_gen_errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ def test_gen_ubuntu_errata
packages = JSON.parse(File.read(pkg_json_path))
packages_by_name = JSON.parse(File.read(pkg_deb_json_path))

f = File.open usn_list_path, 'rb'
errata = parser.gen_ubuntu_errata(
JSON.parse(
Bzip2::FFI::Reader.read(f)
),
packages,
packages_by_name,
['bionic'],
['amd64']
)
f.close
errata = nil
File.open usn_list_path, 'rb' do |f|
errata = parser.gen_ubuntu_errata(
JSON.parse(
Bzip2::FFI::Reader.read(f)
),
packages,
packages_by_name,
['bionic'],
['amd64']
)
end
assert_instance_of(Array, errata)

hsh = {}
Expand Down Expand Up @@ -107,17 +108,18 @@ def test_gen_ubuntu_esm_errata

packages_by_name = JSON.parse(File.read(pkg_json_path))

f = File.open usn_list_path, 'rb'
errata = parser.gen_ubuntu_errata(
JSON.parse(
Bzip2::FFI::Reader.read(f)
),
{},
packages_by_name,
['xenial'],
['amd64']
)
f.close
errata = nil
File.open usn_list_path, 'rb' do |f|
errata = parser.gen_ubuntu_errata(
JSON.parse(
Bzip2::FFI::Reader.read(f)
),
{},
packages_by_name,
['xenial'],
['amd64']
)
end
assert_instance_of(Array, errata)

hsh = {}
Expand Down
Loading