Skip to content

Commit 19dbc2c

Browse files
alexpopchris-rock
authored andcommitted
Rubocop styles update and lint fixes (#23)
Signed-off-by: Alex Pop <alexpop@users.noreply.github.com>
1 parent 54f6acf commit 19dbc2c

7 files changed

Lines changed: 67 additions & 32 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Gemfile.lock
2+
inspec.lock

.rubocop.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Style/PercentLiteralDelimiters:
4444
'%w': '{}'
4545
'%W': ()
4646
'%x': ()
47-
Style/AlignHash:
47+
Layout/AlignHash:
4848
Enabled: false
49-
Style/PredicateName:
49+
Naming/PredicateName:
5050
Enabled: false
5151
Style/ZeroLengthPredicate:
5252
Enabled: false
@@ -62,7 +62,7 @@ Style/AndOr:
6262
Enabled: false
6363
Style/Not:
6464
Enabled: false
65-
Style/FileName:
65+
Naming/FileName:
6666
Enabled: false
6767
Style/TrailingCommaInHashLiteral:
6868
EnforcedStyleForMultiline: comma
@@ -76,7 +76,9 @@ Style/UnlessElse:
7676
Enabled: false
7777
BlockDelimiters:
7878
Enabled: false
79-
Style/SpaceAroundOperators:
79+
Layout/SpaceAroundOperators:
8080
Enabled: false
8181
Style/IfUnlessModifier:
8282
Enabled: false
83+
Style/StderrPuts:
84+
Enabled: false

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Change Log
22

3+
## [0.5.0](https://github.com/dev-sec/linux-patch-baseline/tree/0.5.0) (2019-05-14)
4+
[Full Changelog](https://github.com/dev-sec/linux-patch-baseline/compare/0.4.0...0.5.0)
5+
6+
**Closed issues:**
7+
8+
- Redhat update check only works if user has root access. [\#19](https://github.com/dev-sec/linux-patch-baseline/issues/19)
9+
10+
**Merged pull requests:**
11+
12+
- Update issue templates [\#21](https://github.com/dev-sec/linux-patch-baseline/pull/21) ([rndmh3ro](https://github.com/rndmh3ro))
13+
- allow yum to run as non-root user. [\#20](https://github.com/dev-sec/linux-patch-baseline/pull/20) ([iveskins](https://github.com/iveskins))
14+
- small typo in the packages method [\#18](https://github.com/dev-sec/linux-patch-baseline/pull/18) ([aaronlippold](https://github.com/aaronlippold))
15+
- fix \#3 [\#4](https://github.com/dev-sec/linux-patch-baseline/pull/4) ([chris-rock](https://github.com/chris-rock))
16+
317
## [0.4.0](https://github.com/dev-sec/linux-patch-baseline/tree/0.4.0) (2018-04-12)
418
[Full Changelog](https://github.com/dev-sec/linux-patch-baseline/compare/0.3.0...0.4.0)
519

@@ -36,7 +50,6 @@
3650

3751
**Merged pull requests:**
3852

39-
- fix \#3 [\#4](https://github.com/dev-sec/linux-patch-baseline/pull/4) ([chris-rock](https://github.com/chris-rock))
4053
- add basic test-kitchen config [\#1](https://github.com/dev-sec/linux-patch-baseline/pull/1) ([chris-rock](https://github.com/chris-rock))
4154

4255
## [0.1.0](https://github.com/dev-sec/linux-patch-baseline/tree/0.1.0) (2016-09-27)

Gemfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

3-
gem 'rake'
4-
gem 'rack', '1.6.4'
5-
gem 'inspec', '~> 1'
6-
gem 'highline', '~> 1.6.0'
7-
gem 'rubocop', '~>0.54.0'
5+
gem 'rake', '~> 12.3.2'
6+
gem 'rack', '~> 2.0.7'
7+
gem 'inspec', '~> 3'
8+
gem 'highline', '~> 2.0.2'
9+
gem 'rubocop', '~> 0.68.1'
810

911
group :integration do
1012
gem 'berkshelf'
@@ -14,5 +16,6 @@ group :integration do
1416
end
1517

1618
group :tools do
17-
gem 'github_changelog_generator', '~> 1.12.0'
19+
gem 'github_changelog_generator', '~> 1.14.3'
20+
gem 'pry-coolline', '~> 0.2.5'
1821
end

Rakefile

100644100755
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,30 @@ task default: [:lint, 'test:check']
2020
namespace :test do
2121
# run inspec check to verify that the profile is properly configured
2222
task :check do
23-
dir = File.join(File.dirname(__FILE__))
24-
sh("bundle exec inspec check #{dir}")
23+
require 'inspec'
24+
puts "Checking profile with InSpec Version: #{Inspec::VERSION}"
25+
profile = Inspec::Profile.for_target('.', backend: Inspec::Backend.create(Inspec::Config.mock))
26+
pp profile.check
2527
end
2628
end
2729

28-
# Automatically generate a changelog for this project. Only loaded if
29-
# the necessary gem is installed. By default its picking up the version from
30-
# inspec.yml. You can override that behavior with `rake changelog to=1.2.0`
31-
begin
32-
require 'yaml'
33-
metadata = YAML.load_file('inspec.yml')
34-
v = ENV['to'] || metadata['version']
35-
puts "Generate changelog for version #{v}"
36-
require 'github_changelog_generator/task'
37-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
38-
config.future_release = v
30+
task :changelog do
31+
# Automatically generate a changelog for this project. Only loaded if
32+
# the necessary gem is installed. By default its picking up the version from
33+
# inspec.yml. You can override that behavior with `rake changelog to=1.2.0`
34+
begin
35+
require 'yaml'
36+
metadata = YAML.load_file('inspec.yml')
37+
v = ENV['to'] || metadata['version']
38+
puts " * Generating changelog for version #{v}"
39+
require 'github_changelog_generator/task'
40+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
41+
config.future_release = v
42+
config.user = 'dev-sec'
43+
config.project = 'linux-patch-baseline'
44+
end
45+
Rake::Task[:changelog].execute
46+
rescue LoadError
47+
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
3948
end
40-
rescue LoadError
41-
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
4249
end

inspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: linux-patch-baseline
22
title: DevSec Linux Patch Benchmark
33
summary: Verifies that all patches have been applied
4-
version: 0.4.0
4+
version: 0.5.0
55

66
maintainer: Christoph Hartmann
77
copyright: Christoph Hartmann

libraries/linux_updates.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,37 @@ def initialize
3838

3939
def updates
4040
return [] if @update_mgmt.nil?
41+
4142
u = @update_mgmt.updates
4243
return [] if u.nil? || u.empty?
44+
4345
u['available']
4446
end
4547

4648
def uptodate?
4749
return nil if @update_mgmt.nil?
50+
4851
u = @update_mgmt.updates
4952
return false if u.nil? || !u['available'].empty?
53+
5054
l = @update_mgmt.patches
5155
return false if l.nil? || !l.empty?
56+
5257
true
5358
end
5459

5560
def packages
5661
return [] if @update_mgmt.nil?
62+
5763
p = @update_mgmt.packages
5864
return [] if p.nil? || p.empty?
65+
5966
p['installed']
6067
end
6168

6269
def patches
6370
return [] if @update_mgmt.nil?
71+
6472
@update_mgmt.patches || []
6573
end
6674

@@ -156,7 +164,7 @@ def packages
156164
grep '^install ok installed\\s' |\\
157165
awk '{ printf "{\\"name\\":\\""$4"\\",\\"version\\":\\""$5"\\",\\"arch\\":\\""$6"\\"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
158166
echo -n ']}'
159-
PRINT_JSON
167+
PRINT_JSON
160168
parse_json(ubuntu_packages)
161169
end
162170

@@ -166,7 +174,7 @@ def updates
166174
DEBIAN_FRONTEND=noninteractive apt-get upgrade --dry-run | grep Inst | tr -d '[]()' |\\
167175
awk '{ printf "{\\"name\\":\\""$2"\\",\\"version\\":\\""$4"\\",\\"repo\\":\\""$5"\\",\\"arch\\":\\""$6"\\"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
168176
echo -n ']}'
169-
PRINT_JSON
177+
PRINT_JSON
170178
parse_json(ubuntu_updates)
171179
end
172180

@@ -179,7 +187,7 @@ def ubuntu_base
179187
readlock() { cat /proc/locks | awk '{print $5}' | grep -v ^0 | xargs -I {1} find /proc/{1}/fd -maxdepth 1 -exec readlink {} \\; | grep '^/var/lib/dpkg/lock$'; }
180188
while test -n "$(readlock)"; do sleep 1; done
181189
echo " "
182-
PRINT_JSON
190+
PRINT_JSON
183191
base
184192
end
185193
end
@@ -192,15 +200,15 @@ def packages
192200
rpm -qa --queryformat '"name":"%{NAME}","version":"%{VERSION}-%{RELEASE}","arch":"%{ARCH}"\\n' |\\
193201
awk '{ printf "{"$1"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
194202
echo -n ']}'
195-
PRINT_JSON
203+
PRINT_JSON
196204
parse_json(rhel_packages)
197205
end
198206

199207
def updates
200208
rhel_updates = <<-PRINT_JSON
201209
#!/bin/sh
202210
python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; ybc = cli.YumBaseCli(); ybc.setCacheDir("/tmp"); list = ybc.returnPkgLists(["updates"]);res = ["{\\"name\\":\\""+x.name+"\\", \\"version\\":\\""+x.version+"-"+x.release+"\\",\\"arch\\":\\""+x.arch+"\\",\\"repository\\":\\""+x.repo.id+"\\"}" for x in list.updates]; print "{\\"available\\":["+",".join(res)+"]}"'
203-
PRINT_JSON
211+
PRINT_JSON
204212
cmd = @inspec.bash(rhel_updates)
205213
unless cmd.exit_status == 0
206214
# essentially we want https://github.com/chef/inspec/issues/1205

0 commit comments

Comments
 (0)