Skip to content

Commit 66fa889

Browse files
author
Todd Campbell
authored
Merge pull request #78 from sensu-plugins/bonsai_updates
Update rubocop and rake, remediate rubocop
2 parents 47bf0ac + d41fa24 commit 66fa889

23 files changed

+205
-46
lines changed

.rubocop.yml

Lines changed: 124 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,146 @@
11

2-
MethodLength:
2+
Metrics/MethodLength:
33
Max: 200
44

5-
LineLength:
5+
Layout/LineLength:
66
Max: 172
77

8-
AbcSize:
8+
Metrics/AbcSize:
99
Max: 100
1010

11-
FileName:
11+
Naming/FileName:
1212
Enabled: false
1313

14-
PerceivedComplexity:
14+
Metrics/PerceivedComplexity:
1515
Enabled: false
1616

17-
CyclomaticComplexity:
17+
Metrics/CyclomaticComplexity:
1818
Enabled: false
1919

20-
ClassLength:
20+
Metrics/ClassLength:
2121
Enabled: false
2222

23-
IfUnlessModifier:
23+
Style/IfUnlessModifier:
2424
Enabled: false
2525

26-
RegexpLiteral:
26+
Style/RegexpLiteral:
2727
Enabled: false
2828

2929
Style/Documentation:
3030
Enabled: false
3131

32-
# AllCops:
33-
# TargetRubyVersion: 2.0
32+
Style/ClassVars:
33+
Enabled: false
34+
35+
Layout/EmptyLinesAroundAttributeAccessor:
36+
Enabled: false
37+
38+
Layout/SpaceAroundMethodCallOperator:
39+
Enabled: false
40+
41+
Lint/BinaryOperatorWithIdenticalOperands:
42+
Enabled: false
43+
44+
Lint/DeprecatedOpenSSLConstant:
45+
Enabled: false
46+
47+
Lint/DuplicateElsifCondition:
48+
Enabled: false
49+
50+
Lint/DuplicateRescueException:
51+
Enabled: false
52+
53+
Lint/EmptyConditionalBody:
54+
Enabled: false
55+
56+
Lint/FloatComparison:
57+
Enabled: false
58+
59+
Lint/MissingSuper:
60+
Enabled: false
61+
62+
Lint/MixedRegexpCaptureTypes:
63+
Enabled: false
64+
65+
Lint/OutOfRangeRegexpRef:
66+
Enabled: false
67+
68+
Lint/RaiseException:
69+
Enabled: false
70+
71+
Lint/SelfAssignment:
72+
Enabled: false
73+
74+
Lint/StructNewOverride:
75+
Enabled: false
76+
77+
Lint/TopLevelReturnWithArgument:
78+
Enabled: false
79+
80+
Lint/UnreachableLoop:
81+
Enabled: false
82+
83+
Style/AccessorGrouping:
84+
Enabled: false
85+
86+
Style/ArrayCoercion:
87+
Enabled: false
88+
89+
Style/BisectedAttrAccessor:
90+
Enabled: false
91+
92+
Style/CaseLikeIf:
93+
Enabled: false
94+
95+
Style/ExplicitBlockArgument:
96+
Enabled: false
97+
98+
Style/ExponentialNotation:
99+
Enabled: false
100+
101+
Style/GlobalStdStream:
102+
Enabled: false
103+
104+
Style/HashAsLastArrayItem:
105+
Enabled: false
106+
107+
Style/HashEachMethods:
108+
Enabled: false
109+
110+
Style/HashLikeCase:
111+
Enabled: false
112+
113+
Style/HashTransformKeys:
114+
Enabled: false
115+
116+
Style/HashTransformValues:
117+
Enabled: false
118+
119+
Style/OptionalBooleanParameter:
120+
Enabled: false
121+
122+
Style/RedundantAssignment:
123+
Enabled: false
124+
125+
Style/RedundantFetchBlock:
126+
Enabled: false
127+
128+
Style/RedundantFileExtensionInRequire:
129+
Enabled: false
130+
131+
Style/RedundantRegexpCharacterClass:
132+
Enabled: false
133+
134+
Style/RedundantRegexpEscape:
135+
Enabled: false
136+
137+
Style/SingleArgumentDig:
138+
Enabled: false
139+
140+
Style/SlicingWithRange:
141+
Enabled: false
142+
143+
Style/StringConcatenation:
144+
Enabled: false
145+
146+

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md).
55

66
## [Unreleased]
7-
- Remove ruby-2.3.0. Upgrade bundler. Fix failing tests (@phumpal).
87

98
### Breaking Changes
109
- Bump `sensu-plugin` dependency from `~> 1.2` to `~> 4.0` you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17), [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04), and [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29)
10+
- Remove ruby-2.3.0. Upgrade bundler. Fix failing tests (@phumpal).
1111

1212
### Added
1313
- Travis build automation to generate Sensu Asset tarballs that can be used n conjunction with Sensu provided ruby runtime assets and the Bonsai Asset Index
@@ -17,6 +17,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
1717

1818
### Changed
1919
- `check-ssl-anchor.rb` uses regexp to test for present of certificates in cert chain that works with both openssl 1.0 and 1.1 formatting
20+
- Upgrade rake and rubocop dependencies
21+
- Remediate rubocop issues
2022

2123
### Fixed
2224
- ssl-anchor test now uses regexp

Gemfile

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

35
# Specify your gem's dependencies in sensu-plugins-ssl.gemspec

Rakefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'github/markup'
35
require 'redcarpet'
@@ -8,12 +10,12 @@ require 'yard/rake/yardoc_task'
810

911
ENV['TZ'] = 'CET'
1012

11-
args = [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs]
13+
args = %i[spec make_bin_executable yard rubocop check_binstubs]
1214

1315
YARD::Rake::YardocTask.new do |t|
14-
OTHER_PATHS = %w().freeze
16+
OTHER_PATHS = %w[].freeze
1517
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS]
16-
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md)
18+
t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md]
1719
end
1820

1921
RuboCop::RakeTask.new
@@ -31,7 +33,7 @@ desc 'Test for binstubs'
3133
task :check_binstubs do
3234
bin_list = Gem::Specification.load('sensu-plugins-ssl.gemspec').executables
3335
bin_list.each do |b|
34-
`which #{ b }`
36+
`which #{b}`
3537
unless $CHILD_STATUS.success?
3638
puts "#{b} was not a binstub"
3739
exit

bin/check-java-keystore-cert.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: false
3+
24
#
35
# check-java-keystore-cert
46
#
@@ -75,7 +77,7 @@ def run
7577

7678
days_until = (certificate_expiration_date - Date.today).to_i
7779

78-
if days_until < 0
80+
if days_until < 0 # rubocop: disable Style/NumericPredicate
7981
critical "Expired #{days_until.abs} days ago"
8082
elsif days_until < config[:critical]
8183
critical "#{days_until} days left"

bin/check-ssl-anchor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#! /usr/bin/env ruby
2+
# frozen_string_literal: false
3+
24
#
35
# check-ssl-anchor
46
#

bin/check-ssl-cert.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#! /usr/bin/env ruby
2+
# frozen_string_literal: false
3+
24
#
35
# check-ssl-cert
46
#
@@ -117,7 +119,7 @@ def run
117119

118120
days_until = (Date.parse(expiry.to_s) - Date.today).to_i
119121

120-
if days_until < 0
122+
if days_until < 0 # rubocop:disable Style/NumericPredicate
121123
critical "Expired #{days_until.abs} days ago"
122124
elsif days_until < config[:critical].to_i
123125
critical "#{days_until} days left"

bin/check-ssl-crl.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#! /usr/bin/env ruby
2+
# frozen_string_literal: false
3+
24
#
35
# check-ssl-crl
46
#
@@ -65,10 +67,10 @@ def validate_opts
6567
def run
6668
validate_opts
6769

68-
next_update = OpenSSL::X509::CRL.new(open(config[:url]).read).next_update
70+
next_update = OpenSSL::X509::CRL.new(open(config[:url]).read).next_update # rubocop:disable Security/Open
6971
minutes_until = seconds_to_minutes(Time.parse(next_update.to_s) - Time.now)
7072

71-
critical "#{config[:url]} - Expired #{minutes_until.abs} minutes ago" if minutes_until < 0
73+
critical "#{config[:url]} - Expired #{minutes_until.abs} minutes ago" if minutes_until < 0 # rubocop:disable Style/NumericPredicate
7274
critical "#{config[:url]} - #{minutes_until} minutes left, next update at #{next_update}" if minutes_until < config[:critical].to_i
7375
warning "#{config[:url]} - #{minutes_until} minutes left, next update at #{next_update}" if minutes_until < config[:warning].to_i
7476
ok "#{config[:url]} - #{minutes_until} minutes left, next update at #{next_update}"

bin/check-ssl-host.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: false
3+
34
# check-ssl-host.rb
45
#
56
# DESCRIPTION:
@@ -42,7 +43,7 @@
4243
# Check SSL Host
4344
#
4445
class CheckSSLHost < Sensu::Plugin::Check::CLI
45-
STARTTLS_PROTOS = %w(smtp imap).freeze
46+
STARTTLS_PROTOS = %w[smtp imap].freeze
4647

4748
check_name 'check_ssl_host'
4849

@@ -104,7 +105,7 @@ class CheckSSLHost < Sensu::Plugin::Check::CLI
104105
long: '--starttls PROTO'
105106

106107
def get_cert_chain(host, port, address, client_cert, client_key)
107-
tcp_client = TCPSocket.new(address ? address : host, port)
108+
tcp_client = TCPSocket.new(address ? address : host, port) # rubocop:disable Style/RedundantCondition
108109
handle_starttls(config[:starttls], tcp_client) if config[:starttls]
109110
ssl_context = OpenSSL::SSL::SSLContext.new
110111
ssl_context.cert = OpenSSL::X509::Certificate.new File.read(client_cert) if client_cert
@@ -139,6 +140,7 @@ def starttls_smtp(socket)
139140

140141
status = socket.readline
141142
return if /^220 / =~ status
143+
142144
critical "#{config[:host]} - did not receive SMTP 220 in response to STARTTLS"
143145
end
144146

@@ -151,14 +153,15 @@ def starttls_imap(socket)
151153

152154
status = socket.readline
153155
return if /^a001 OK Begin TLS negotiation now/ =~ status
156+
154157
critical "#{config[:host]} - did not receive OK Begin TLS negotiation now"
155158
end
156159

157160
def verify_expiry(cert)
158161
# Expiry check
159162
days = (cert.not_after.to_date - Date.today).to_i
160163
message = "#{config[:host]} - #{days} days until expiry"
161-
critical "#{config[:host]} - Expired #{days} days ago" if days < 0
164+
critical "#{config[:host]} - Expired #{days} days ago" if days < 0 # rubocop:disable Style/NumericPredicate
162165
critical message if days < config[:critical]
163166
warning message if days < config[:warning]
164167
ok message

bin/check-ssl-hsts-preloadable.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env ruby
2-
# encoding: UTF-8
2+
# frozen_string_literal: false
3+
34
# check-ssl-hsts-preloadable.rb
45
#
56
# DESCRIPTION:
@@ -43,16 +44,16 @@ class CheckSSLHSTSPreloadable < Sensu::Plugin::Check::CLI
4344
default: 'https://hstspreload.org/api/v2/preloadable'
4445

4546
def fetch(uri, limit = 10)
46-
if limit == 0
47+
if limit == 0 # rubocop:disable Style/NumericPredicate
4748
return nil
4849
end
4950

5051
response = Net::HTTP.get_response(uri)
5152

5253
case response
53-
when Net::HTTPSuccess then
54+
when Net::HTTPSuccess
5455
response
55-
when Net::HTTPRedirection then
56+
when Net::HTTPRedirection
5657
location = URI(response['location'])
5758
fetch(location, limit - 1)
5859
end
@@ -65,6 +66,7 @@ def run
6566
if response.nil?
6667
return warning 'Bad response recieved from API'
6768
end
69+
6870
body = JSON.parse(response.body)
6971
if !body['errors'].empty?
7072
critical body['errors'].map { |u| u['summary'] }.join(', ')

0 commit comments

Comments
 (0)