bundler-audit-fix 0.1.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 +7 -0
- data/.editorconfig +14 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +13 -0
- data/.rspec +4 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +68 -0
- data/README.md +67 -0
- data/Rakefile +12 -0
- data/bin/bundle-audit-fix +10 -0
- data/bin/bundler-audit-fix +3 -0
- data/bin/console +12 -0
- data/bundler-audit-fix.gemspec +28 -0
- data/lib/bundler/audit/fix/cli.rb +87 -0
- data/lib/bundler/audit/fix/configuration.rb +64 -0
- data/lib/bundler/audit/fix/patcher.rb +140 -0
- data/lib/bundler/audit/fix/version.rb +26 -0
- data/lib/bundler/audit/fix.rb +24 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01d9c0fdba65b4b5e1347551f5a422354d3faca7ad7503b9660afb00f14b0974
|
4
|
+
data.tar.gz: 5e37e51063008125a94d552a733b0158c469d82513eba81a0ac6760e279e7bbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5043e0eeeba8507da23840984bf6e0c327386c14da1bdae1ee93c6e3e03b883c6125d60e9a4dd44811d01654e0fbde8ff1b54d6f49354ebff25b3cf7f2ad6ee1
|
7
|
+
data.tar.gz: 22cb90f36ea55de0c139d1f0611f865cf8b6d3eaaf7edfbd853d3a257b733564539cbeadc7c41532f764108108471a28de7461509795ec48d89df58071219594
|
data/.editorconfig
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# EditorConfig is awesome: https://EditorConfig.org
|
2
|
+
|
3
|
+
root = true
|
4
|
+
|
5
|
+
[*]
|
6
|
+
indent_style = space
|
7
|
+
indent_size = 2
|
8
|
+
end_of_line = lf
|
9
|
+
charset = utf-8
|
10
|
+
trim_trailing_whitespace = true
|
11
|
+
insert_final_newline = true
|
12
|
+
|
13
|
+
[*.md]
|
14
|
+
trim_trailing_whitespace = false
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.1
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
Exclude:
|
4
|
+
- 'spec/fixtures/database/**/*'
|
5
|
+
- 'vendor/**/*'
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: single_quotes
|
10
|
+
Style/FrozenStringLiteralComment:
|
11
|
+
Exclude:
|
12
|
+
- 'bin/*'
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 100
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Max: 50
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 100
|
26
|
+
Metrics/CyclomaticComplexity:
|
27
|
+
Max: 15
|
28
|
+
Metrics/PerceivedComplexity:
|
29
|
+
Enabled: false
|
30
|
+
Metrics/ParameterLists:
|
31
|
+
CountKeywordArgs: false
|
32
|
+
Metrics/ModuleLength:
|
33
|
+
Max: 200
|
34
|
+
Metrics/ClassLength:
|
35
|
+
Max: 200
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bundler-audit-fix (0.1.0)
|
5
|
+
bundler (>= 1.2.0, < 3)
|
6
|
+
bundler-audit (~> 0.9.0)
|
7
|
+
thor (~> 1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (2.4.2)
|
13
|
+
bundler-audit (0.9.0.1)
|
14
|
+
bundler (>= 1.2.0, < 3)
|
15
|
+
thor (~> 1.0)
|
16
|
+
coderay (1.1.3)
|
17
|
+
diff-lcs (1.4.4)
|
18
|
+
method_source (1.0.0)
|
19
|
+
parallel (1.21.0)
|
20
|
+
parser (3.0.3.2)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
pry (0.14.1)
|
23
|
+
coderay (~> 1.1)
|
24
|
+
method_source (~> 1.0)
|
25
|
+
rainbow (3.0.0)
|
26
|
+
rake (13.0.6)
|
27
|
+
regexp_parser (2.2.0)
|
28
|
+
rexml (3.2.5)
|
29
|
+
rspec (3.10.0)
|
30
|
+
rspec-core (~> 3.10.0)
|
31
|
+
rspec-expectations (~> 3.10.0)
|
32
|
+
rspec-mocks (~> 3.10.0)
|
33
|
+
rspec-core (3.10.1)
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-expectations (3.10.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-mocks (3.10.2)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-support (3.10.3)
|
42
|
+
rubocop (1.23.0)
|
43
|
+
parallel (~> 1.10)
|
44
|
+
parser (>= 3.0.0.0)
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
regexp_parser (>= 1.8, < 3.0)
|
47
|
+
rexml
|
48
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
51
|
+
rubocop-ast (1.15.0)
|
52
|
+
parser (>= 3.0.1.1)
|
53
|
+
ruby-progressbar (1.11.0)
|
54
|
+
thor (1.1.0)
|
55
|
+
unicode-display_width (2.1.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler-audit-fix!
|
62
|
+
pry (~> 0.14.1)
|
63
|
+
rake (~> 13.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
rubocop (~> 1.7)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.2.18
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Bundler::Audit::Fix
|
2
|
+
|
3
|
+
Automatically apply patched version of gems audited by [rubysec/bunder-audit](https://github.com/rubysec/bundler-audit).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bundler-audit-fix'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bundler-audit-fix
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ bundle-audit-fix update [dir]
|
25
|
+
```
|
26
|
+
|
27
|
+
### .bundler-audit.yml
|
28
|
+
|
29
|
+
In addition to the original configuration, it supports `replacement` block. If a gem that is related to a fixed version and not directly listed in the Gemfile (i.g. Rails family, etc.) needs to be updated, bundle-audit-fix will replace according to the specified like below.
|
30
|
+
|
31
|
+
```yml
|
32
|
+
replacement:
|
33
|
+
rails:
|
34
|
+
- actionpack
|
35
|
+
- actionview
|
36
|
+
- activemodel
|
37
|
+
- activerecord
|
38
|
+
- actionmailer
|
39
|
+
- activejob
|
40
|
+
- actioncable
|
41
|
+
- activestorage
|
42
|
+
- activesupport
|
43
|
+
- actionmailbox
|
44
|
+
- actiontext
|
45
|
+
- railties
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nobuyo/bundler-audit-fix.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
Copyright (c) 2021 Nobuo Takizawa
|
55
|
+
|
56
|
+
bundler-audit-fix is free software: you can redistribute it and/or modify
|
57
|
+
it under the terms of the GNU General Public License as published by
|
58
|
+
the Free Software Foundation, either version 3 of the License, or
|
59
|
+
(at your option) any later version.
|
60
|
+
|
61
|
+
bundler-audit-fix is distributed in the hope that it will be useful,
|
62
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
63
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
64
|
+
GNU General Public License for more details.
|
65
|
+
|
66
|
+
You should have received a copy of the GNU General Public License
|
67
|
+
along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bundler/audit/fix'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
require 'pry'
|
12
|
+
Pry.start
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/bundler/audit/fix/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'bundler-audit-fix'
|
7
|
+
spec.version = Bundler::Audit::Fix::VERSION
|
8
|
+
spec.authors = ['Nobuo Takizawa']
|
9
|
+
spec.email = ['longzechangsheng@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Automatic apply security update inspected by bundler-audit.'
|
12
|
+
spec.homepage = 'https://github.com/nobuyo/bundler-audit-fix'
|
13
|
+
spec.required_ruby_version = '>= 2.5.0'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = 'https://github.com/nobuyo/bundler-audit-fix'
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = spec.files.grep(%r{\Abin/bundle}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'bundler', '>= 1.2.0', '< 3'
|
26
|
+
spec.add_dependency 'bundler-audit', '~> 0.9.0'
|
27
|
+
spec.add_dependency 'thor', '~> 1.0'
|
28
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2021 Nobuo Takizawa
|
5
|
+
#
|
6
|
+
# bundler-audit-fix is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# bundler-audit-fix is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'thor'
|
21
|
+
require 'bundler/cli/update'
|
22
|
+
require 'bundler/audit/cli'
|
23
|
+
require 'bundler/audit/database'
|
24
|
+
|
25
|
+
module Bundler
|
26
|
+
module Audit
|
27
|
+
module Fix
|
28
|
+
#
|
29
|
+
# The `bundle-audit-fix` command.
|
30
|
+
#
|
31
|
+
class CLI < ::Thor
|
32
|
+
include Thor::Actions
|
33
|
+
|
34
|
+
default_task :update
|
35
|
+
map '--version' => :version
|
36
|
+
|
37
|
+
desc 'check [DIR]', 'Checks the Gemfile.lock for insecure dependencies'
|
38
|
+
method_option :ignore, type: :array, aliases: '-i'
|
39
|
+
method_option :update, type: :boolean, aliases: '-u'
|
40
|
+
method_option :database, type: :string, aliases: '-D', default: Database::USER_PATH
|
41
|
+
method_option :config, type: :string, aliases: '-c', default: '.bundler-audit.yml'
|
42
|
+
method_option :gemfile_lock, type: :string, aliases: '-G', default: 'Gemfile.lock'
|
43
|
+
|
44
|
+
def update(dir = Dir.pwd)
|
45
|
+
unless File.directory?(dir)
|
46
|
+
say_error "No such file or directory: #{dir}", :red
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
if !Database.exists?(options[:database])
|
51
|
+
Bundler::Audit::CLI.new.invoke(:download, options[:database])
|
52
|
+
elsif options[:update]
|
53
|
+
Bundler::Audit::CLI.new.invoke(:update, options[:database])
|
54
|
+
end
|
55
|
+
|
56
|
+
database = Database.new(options[:database])
|
57
|
+
begin
|
58
|
+
scanner = Scanner.new(dir, options[:gemfile_lock], database, options[:config])
|
59
|
+
scanner.scan
|
60
|
+
|
61
|
+
report = scanner.report(ignore: options.ignore)
|
62
|
+
unless report.vulnerable?
|
63
|
+
say 'Nothing to do, exiting.', :green
|
64
|
+
exit 0
|
65
|
+
end
|
66
|
+
|
67
|
+
patcher = Patcher.new(dir, report, options[:gemfile_lock], options[:config])
|
68
|
+
gems_to_update = patcher.patch
|
69
|
+
|
70
|
+
gemfile = options[:gemfile_lock].sub(/\.lock$/, '')
|
71
|
+
gemfile_path = File.join(dir, gemfile)
|
72
|
+
|
73
|
+
Bundler::CLI::Update.new({ gemfile: gemfile_path }, gems_to_update).run
|
74
|
+
rescue Bundler::GemfileNotFound, Bundler::GemfileLockNotFound => e
|
75
|
+
say e.message, :red
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'version', 'Prints the bundler-audit-fix version'
|
81
|
+
def version
|
82
|
+
puts Fix::VERSION
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2021 Nobuo Takizawa
|
5
|
+
#
|
6
|
+
# bundler-audit-fix is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# bundler-audit-fix is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'yaml'
|
21
|
+
require 'bundler/audit/configuration'
|
22
|
+
|
23
|
+
module Bundler
|
24
|
+
module Audit
|
25
|
+
module Fix
|
26
|
+
#
|
27
|
+
# Class for configurations.
|
28
|
+
#
|
29
|
+
class Configuration < Configuration
|
30
|
+
attr_accessor :replacements
|
31
|
+
|
32
|
+
def self.load(file_path)
|
33
|
+
instance = super(file_path)
|
34
|
+
|
35
|
+
doc = YAML.parse(File.new(file_path))
|
36
|
+
doc.root.children.each_slice(2) do |key, value|
|
37
|
+
case key.value
|
38
|
+
when 'replacement'
|
39
|
+
unless value.children.is_a?(Array)
|
40
|
+
raise(InvalidConfigurationError, "'replacement' key found in config file, but is not an Array")
|
41
|
+
end
|
42
|
+
|
43
|
+
instance.replacements = build_replacements(value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
instance
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.build_replacements(params)
|
51
|
+
params.children.each_slice(2).map do |key, value|
|
52
|
+
raise(InvalidConfigurationError, "'replacement.#{key.value}' in config file is empty") unless value.children
|
53
|
+
|
54
|
+
unless value.children.all? { |node| node.is_a?(YAML::Nodes::Scalar) }
|
55
|
+
raise(InvalidConfigurationError, "'replacement.#{key.value}' array in config file contains a non-String")
|
56
|
+
end
|
57
|
+
|
58
|
+
{ key.value => value.children.map(&:value) }
|
59
|
+
end.inject(&:merge)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2021 Nobuo Takizawa
|
5
|
+
#
|
6
|
+
# bundler-audit-fix is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# bundler-audit-fix is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'bundler'
|
21
|
+
require 'bundler/audit'
|
22
|
+
|
23
|
+
module Bundler
|
24
|
+
module Audit
|
25
|
+
module Fix
|
26
|
+
#
|
27
|
+
# Patcher is a class for updating gem version specifications in Gemfile.
|
28
|
+
#
|
29
|
+
class Patcher
|
30
|
+
attr_reader :config, :bundled_gems, :locked_gems, :gemfile_path, :lockfile_path, :report
|
31
|
+
|
32
|
+
# @param [String] root
|
33
|
+
# The path to the project root.
|
34
|
+
#
|
35
|
+
# @param [Hash] report
|
36
|
+
# Result of ::Bundler::Audit::Scanner#report.
|
37
|
+
#
|
38
|
+
# @param [String] gemfile_lock
|
39
|
+
# Path to Gemfile.lock.
|
40
|
+
#
|
41
|
+
# @param [String] config_file_path
|
42
|
+
# Path to bundler-audit config file.
|
43
|
+
def initialize(root, report, gemfile_lock = 'Gemfile.lock', config_file_path = '.bundler-audit.yml')
|
44
|
+
root = File.expand_path(root)
|
45
|
+
gemfile = gemfile_lock.sub(/\.lock$/, '')
|
46
|
+
@gemfile_path = File.join(root, gemfile)
|
47
|
+
@lockfile_path = File.join(root, gemfile_lock)
|
48
|
+
@report = report
|
49
|
+
|
50
|
+
unless File.file?(@gemfile_path)
|
51
|
+
raise(Bundler::GemfileNotFound, "Could not find #{gemfile.inspect} in #{root.inspect}")
|
52
|
+
end
|
53
|
+
|
54
|
+
unless File.file?(@lockfile_path)
|
55
|
+
raise(Bundler::GemfileLockNotFound, "Could not find #{gemfile_lock.inspect} in #{root.inspect}")
|
56
|
+
end
|
57
|
+
|
58
|
+
@bundled_gems = Bundler::Definition.build(@gemfile_path, nil, nil).dependencies
|
59
|
+
@locked_gems = Bundler::LockfileParser.new(Bundler.read_file(@lockfile_path)).specs
|
60
|
+
|
61
|
+
config_file_abs_path = File.absolute_path(config_file_path, root)
|
62
|
+
@config = if File.exist?(config_file_abs_path)
|
63
|
+
Configuration.load(config_file_abs_path)
|
64
|
+
else
|
65
|
+
Configuration.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Write patched versions to Gemfile and return gems list to update.
|
71
|
+
#
|
72
|
+
def patch
|
73
|
+
patterns, gems_to_update = build_patterns
|
74
|
+
gemfile = File.read(gemfile_path)
|
75
|
+
|
76
|
+
patterns.each do |pattern, replace_with|
|
77
|
+
gemfile = gemfile.gsub(pattern, replace_with)
|
78
|
+
end
|
79
|
+
|
80
|
+
File.write(gemfile_path, gemfile)
|
81
|
+
|
82
|
+
gems_to_update
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def build_patterns
|
88
|
+
gems_to_update = []
|
89
|
+
patterns = report.results.map do |r|
|
90
|
+
name = replace_name_if_defined(name: r.gem.name)
|
91
|
+
|
92
|
+
current = bundled_gems.find { |gem| gem.name == name }
|
93
|
+
locked = locked_gems.find { |gem| gem.name == name }
|
94
|
+
|
95
|
+
gems_to_update << name
|
96
|
+
|
97
|
+
# If current does not exist here, skip it because the package is an indirect dependency.
|
98
|
+
next if !current && locked
|
99
|
+
|
100
|
+
patched_versions = r.advisory.patched_versions.map do |patched_version|
|
101
|
+
Gem::Requirement.parse(patched_version.as_list[-1])[1]
|
102
|
+
end
|
103
|
+
|
104
|
+
new_requirement = patched_versions.find do |patched_version|
|
105
|
+
patched_version > locked.version
|
106
|
+
end
|
107
|
+
|
108
|
+
current_requirement = current.requirements_list.join("', '")
|
109
|
+
current_requirement_operator = Gem::Requirement.parse(current.requirements_list[0])[0]
|
110
|
+
|
111
|
+
if current_requirement_operator == '='
|
112
|
+
current_requirement = Gem::Requirement.parse(current.requirements_list[0])[1]
|
113
|
+
else
|
114
|
+
new_requirement = "#{current_requirement_operator} #{new_requirement}"
|
115
|
+
end
|
116
|
+
|
117
|
+
[
|
118
|
+
/gem '#{name}',\s*'#{current_requirement}'/,
|
119
|
+
"gem '#{name}', '#{new_requirement}'"
|
120
|
+
]
|
121
|
+
end.compact
|
122
|
+
|
123
|
+
[patterns, gems_to_update]
|
124
|
+
end
|
125
|
+
|
126
|
+
def replace_name_if_defined(name:)
|
127
|
+
return name unless config.replacements
|
128
|
+
|
129
|
+
replacement = config.replacements.find do |_with, targets|
|
130
|
+
targets.include?(name)
|
131
|
+
end
|
132
|
+
|
133
|
+
return name unless replacement
|
134
|
+
|
135
|
+
replacement[0]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2021 Nobuo Takizawa
|
5
|
+
#
|
6
|
+
# bundler-audit-fix is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# bundler-audit-fix is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Bundler
|
21
|
+
module Audit
|
22
|
+
module Fix
|
23
|
+
VERSION = '0.1.0'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2021 Nobuo Takizawa
|
5
|
+
#
|
6
|
+
# bundler-audit-fix is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# bundler-audit-fix is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with bundler-audit-fix. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require_relative 'fix/version'
|
21
|
+
|
22
|
+
require_relative 'fix/cli'
|
23
|
+
require_relative 'fix/configuration'
|
24
|
+
require_relative 'fix/patcher'
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundler-audit-fix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nobuo Takizawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler-audit
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.9.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: thor
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
61
|
+
description:
|
62
|
+
email:
|
63
|
+
- longzechangsheng@gmail.com
|
64
|
+
executables:
|
65
|
+
- bundle-audit-fix
|
66
|
+
- bundler-audit-fix
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- ".editorconfig"
|
71
|
+
- ".github/workflows/main.yml"
|
72
|
+
- ".gitignore"
|
73
|
+
- ".rspec"
|
74
|
+
- ".rubocop.yml"
|
75
|
+
- CHANGELOG.md
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- bin/bundle-audit-fix
|
81
|
+
- bin/bundler-audit-fix
|
82
|
+
- bin/console
|
83
|
+
- bundler-audit-fix.gemspec
|
84
|
+
- lib/bundler/audit/fix.rb
|
85
|
+
- lib/bundler/audit/fix/cli.rb
|
86
|
+
- lib/bundler/audit/fix/configuration.rb
|
87
|
+
- lib/bundler/audit/fix/patcher.rb
|
88
|
+
- lib/bundler/audit/fix/version.rb
|
89
|
+
homepage: https://github.com/nobuyo/bundler-audit-fix
|
90
|
+
licenses: []
|
91
|
+
metadata:
|
92
|
+
homepage_uri: https://github.com/nobuyo/bundler-audit-fix
|
93
|
+
source_code_uri: https://github.com/nobuyo/bundler-audit-fix
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.5.0
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubygems_version: 3.2.15
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Automatic apply security update inspected by bundler-audit.
|
113
|
+
test_files: []
|