recent_ruby 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +33 -6
- data/lib/recent_ruby.rb +13 -4
- data/lib/recent_ruby/version.rb +1 -1
- data/lib/recent_ruby/xml_ast.rb +55 -50
- 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: a626dae98bcb8ac0b68c2089454706ffcee4a319eee7559f19b7ec918b3c84e1
|
4
|
+
data.tar.gz: 816502e54a5bfd77e5ee6386a8c50197a5edf307949f4ca6ce421c343e904154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5a2ccb5f8315f8d7185162fb78cf58e1240a6276225319427608e4a542c382133e529bb625a4a8dbb8fb4cefcbbbb057f767879193054706843b24af6696ea
|
7
|
+
data.tar.gz: 01c25327c51eaa090c9c314a57593060f8354871b3f391133c214e1587abd5ee51f99c5f3c440bdc5b76e3737b85d58df89eee4feee9e91ae7c0696876496baf
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Recent Ruby
|
2
2
|
|
3
|
-
This script takes a Ruby version number, compares it to all available Ruby versions, and throws an error unless the supplied version number contains the latest security patches.
|
3
|
+
This script takes a Ruby version number, compares it to all available Ruby versions, and throws an error unless the supplied version number contains the latest security patches. Put it in your build pipeline and you'll never deploy an app to an unpatched Ruby again.
|
4
4
|
|
5
5
|
## Why
|
6
6
|
|
7
|
-
Heroku (and other platforms) use the Gemfile to determine which version of Ruby to use. This means, whenever a Ruby vulnerability is found, you need to
|
7
|
+
Heroku (and other platforms) use the Gemfile to determine which version of Ruby to use. This means, whenever a Ruby vulnerability is found, you need to update your Gemfile in order to be safe. More importantly it means you need to pay close attention to the Ruby security notices. On smaller teams, this is often overlooked.
|
8
8
|
|
9
|
-
For
|
9
|
+
For gems, you can use Brakeman or Hakiri or Github itself to stay up-to-date with security patches. For your Ruby version, you can now use Recent Ruby.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -24,25 +24,33 @@ gem 'recent_ruby', require: false
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
Just add Recent Ruby in your CI/CD build process, wherever you would put Rubocop or Brakeman. Recent Ruby can check either your Gemfile, or whatever is supplied as a command line argument, and checks if that version of Ruby is the most recent TEENY/PATCH release for that minor version.
|
27
|
+
Just add Recent Ruby in your CI/CD build process, wherever you would put Rubocop or Brakeman. Recent Ruby can check either your Gemfile, or whatever is supplied as a command line argument, and checks if that version of Ruby is the most recent TEENY/PATCH release for that minor version.
|
28
|
+
|
29
|
+
It also makes sure that your minor version is not End-of-Life yet. If your version of Ruby does happen to be out of date and potentially insecure, it exits with status code 1. This means you can simply drop it into your .circle.yml or your Semaphore build step, or wherever you usually put these things.
|
28
30
|
|
29
31
|
## Examples
|
30
32
|
|
31
|
-
|
33
|
+
Outdated version number supplied on command line (2.3.7 was the latest 2.3 release at the time of this writing):
|
32
34
|
|
33
35
|
```
|
34
36
|
$ recent_ruby --version-string 2.3.1
|
35
37
|
Downloading latest list of Rubies from Github...
|
36
38
|
Comparing version numbers...
|
37
39
|
Current version is 2.3.1, but the latest patch release for 2.3 is 2.3.7!
|
40
|
+
```
|
38
41
|
|
42
|
+
Latest release for 2.3:
|
43
|
+
```
|
39
44
|
$ recent_ruby --version-string 2.3.7
|
40
45
|
Downloading latest list of Rubies from Github...
|
41
46
|
Comparing version numbers...
|
42
47
|
Downloading details for 2.3.7...
|
43
48
|
Checking EOL status...
|
44
49
|
Ruby version check completed successfully.
|
50
|
+
```
|
45
51
|
|
52
|
+
Latest release for 2.0, which is End-of-Life (no longer getting security patches):
|
53
|
+
```
|
46
54
|
$ recent_ruby --version-string 2.0.0-p648
|
47
55
|
Downloading latest list of Rubies from Github...
|
48
56
|
Comparing version numbers...
|
@@ -67,6 +75,16 @@ Comparing version numbers...
|
|
67
75
|
Current version is 2.3.3, but the latest patch release for 2.3 is 2.3.7!
|
68
76
|
```
|
69
77
|
|
78
|
+
Build steps I use on in the project settings on SemaphoreCI:
|
79
|
+
|
80
|
+
```
|
81
|
+
# Setup:
|
82
|
+
gem install recent_ruby --no-rdoc --no-ri
|
83
|
+
|
84
|
+
# Build:
|
85
|
+
recent_ruby --gemfile Gemfile
|
86
|
+
```
|
87
|
+
|
70
88
|
## How
|
71
89
|
|
72
90
|
If `--gemfile` was supplied, we use the parser gem to extract the Ruby version from the Gemfile.
|
@@ -77,4 +95,13 @@ Since the ruby-build repository is well maintained and used in production by man
|
|
77
95
|
|
78
96
|
## Contributing
|
79
97
|
|
80
|
-
Feel free to create issues for any problems you may have. Patches are welcome, especially if they come with a Cucumber scenario.
|
98
|
+
Feel free to create issues for any problems you may have. Patches are welcome, especially if they come with a Cucumber scenario.
|
99
|
+
|
100
|
+
## Contributors
|
101
|
+
|
102
|
+
- Lucas Luitjes
|
103
|
+
- Cedric Hartskeerl
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
This project is MIT licensed.
|
data/lib/recent_ruby.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'recent_ruby/version'
|
2
4
|
require 'recent_ruby/xml_ast'
|
3
5
|
|
4
6
|
module RecentRuby
|
7
|
+
RUBY_NODE_XPATH = "//send[symbol-val[@value='ruby']]"
|
8
|
+
VERSION_XPATH = "#{RUBY_NODE_XPATH}/str/string-val/@value"
|
9
|
+
PATCHLEVEL_XPATH = "#{RUBY_NODE_XPATH}/hash/pair[sym[symbol-val[@value='patchlevel']]]"
|
10
|
+
PATCHLEVEL_VALUE_XPATH = "#{PATCHLEVEL_XPATH}/int/integer-val/@value"
|
11
|
+
|
5
12
|
def http_get(url)
|
6
13
|
uri = URI(url)
|
7
14
|
Net::HTTP.start(uri.host, uri.port,
|
@@ -29,19 +36,21 @@ module RecentRuby
|
|
29
36
|
def parse_gemfile(gemfile)
|
30
37
|
ast = Parser::CurrentRuby.parse(File.read(gemfile))
|
31
38
|
xml = RecentRuby::XMLAST.new(ast)
|
32
|
-
version = xml.xpath(
|
33
|
-
version = version.first ? version.first.value : nil
|
39
|
+
version = xml.xpath(VERSION_XPATH)&.first&.value
|
34
40
|
unless version
|
35
41
|
puts 'Unable to find ruby version in gemfile.'
|
36
42
|
exit(1)
|
37
43
|
end
|
44
|
+
|
45
|
+
patchlevel = xml.xpath(PATCHLEVEL_VALUE_XPATH)&.first&.value
|
46
|
+
version += "-p#{patchlevel}" if patchlevel
|
38
47
|
version
|
39
48
|
end
|
40
49
|
|
41
50
|
def validate_mri_version(version)
|
42
51
|
return if version =~ /^(\d+\.\d+\.\d+(-p\d+)?)$/
|
43
|
-
|
44
|
-
|
52
|
+
puts 'Only stable release MRI version strings are currently supported. (e.g. 2.3.1 or 2.3.1-p12)'
|
53
|
+
exit(1)
|
45
54
|
end
|
46
55
|
|
47
56
|
def get_rubies(versions_url)
|
data/lib/recent_ruby/version.rb
CHANGED
data/lib/recent_ruby/xml_ast.rb
CHANGED
@@ -1,55 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'parser/current'
|
2
4
|
require 'rexml/document'
|
3
5
|
|
4
6
|
module RecentRuby
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
7
|
+
# Class comes from: https://medium.com/rubyinside/using-xpath-to-rewrite-ruby-code-with-ease-8f635af65b5b
|
8
|
+
# TODO: turn into a separate gem
|
9
|
+
|
10
|
+
class XMLAST
|
11
|
+
include REXML
|
12
|
+
attr_reader :doc
|
13
|
+
|
14
|
+
def initialize(sexp)
|
15
|
+
@doc = Document.new '<root></root>'
|
16
|
+
@sexp = sexp
|
17
|
+
root = @doc.root
|
18
|
+
populate_tree(root, sexp)
|
19
|
+
end
|
20
|
+
|
21
|
+
def populate_tree(xml, sexp)
|
22
|
+
if sexp.is_a?(String) ||
|
23
|
+
sexp.is_a?(Symbol) ||
|
24
|
+
sexp.is_a?(Numeric) ||
|
25
|
+
sexp.is_a?(NilClass)
|
26
|
+
el = Element.new(sexp.class.to_s.downcase + '-val')
|
27
|
+
el.add_attribute 'value', sexp.to_s
|
28
|
+
xml.add_element el
|
29
|
+
else
|
30
|
+
el = Element.new(sexp.type.to_s)
|
31
|
+
el.add_attribute('id', sexp.object_id)
|
32
|
+
|
33
|
+
sexp.children.each { |n| populate_tree(el, n) }
|
34
|
+
xml.add_element el
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def treewalk(sexp = @sexp)
|
39
|
+
return sexp unless sexp&.respond_to?(:children)
|
40
|
+
[sexp, sexp.children.map { |n| treewalk(n) }].flatten
|
41
|
+
end
|
42
|
+
|
43
|
+
def xpath(path)
|
44
|
+
results = XPath.match(doc, path)
|
45
|
+
results.map do |n|
|
46
|
+
if n.respond_to?(:attributes) && n.attributes['id']
|
47
|
+
treewalk.find do |m|
|
48
|
+
m.object_id.to_s == n.attributes['id']
|
49
|
+
end
|
50
|
+
else
|
51
|
+
n
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def pp
|
57
|
+
doc.write(STDOUT, 2)
|
58
|
+
end
|
59
|
+
end
|
55
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recent_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Luitjes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,6 +131,7 @@ extensions: []
|
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
133
|
- ".gitignore"
|
134
|
+
- ".rubocop.yml"
|
134
135
|
- Gemfile
|
135
136
|
- Gemfile.lock
|
136
137
|
- LICENSE
|