cookstyle 6.5.3 → 6.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/config/cookstyle.yml +253 -8
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/chef/platform_helpers.rb +2 -1
- data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +77 -0
- data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb +45 -0
- data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +3 -3
- data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +8 -4
- metadata +6 -2
data/lib/cookstyle/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: Copyright 2019, Chef Software Inc.
|
2
|
+
# Copyright:: Copyright 2019-2020, Chef Software Inc.
|
3
3
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
'mswin' => 'windows',
|
33
33
|
'opensuse' => 'suse',
|
34
34
|
'opensuseleap' => 'suse',
|
35
|
+
'oracle' => 'rhel',
|
35
36
|
'redhat' => 'rhel',
|
36
37
|
'scientific' => 'rhel',
|
37
38
|
'sles' => 'suse',
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Use valid platform family values in case statements.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# case node['platform_family']
|
27
|
+
# when 'redhat'
|
28
|
+
# puts "I'm on a RHEL-like system"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class InvalidPlatformFamilyInCase < Cop
|
32
|
+
include RangeHelp
|
33
|
+
include ::RuboCop::Chef::PlatformHelpers
|
34
|
+
|
35
|
+
MSG = 'Use valid platform family values in case statements.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :node_platform_family?, <<-PATTERN
|
38
|
+
(send (send nil? :node) :[] (str "platform_family") )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_case(node)
|
42
|
+
node_platform_family?(node.condition) do
|
43
|
+
node.each_when do |when_node|
|
44
|
+
when_node.each_condition do |con|
|
45
|
+
next unless con.str_type? # if the condition isn't a string we can't check so skip
|
46
|
+
|
47
|
+
if INVALID_PLATFORM_FAMILIES[con.str_content]
|
48
|
+
add_offense(con, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
new_value = INVALID_PLATFORM_FAMILIES[node.str_content]
|
57
|
+
|
58
|
+
# some invalid platform families have no direct correction value and return nil instead
|
59
|
+
return unless new_value
|
60
|
+
|
61
|
+
# if the correct value already exists in the when statement then we just want to delete this node
|
62
|
+
if node.parent.conditions.any? { |x| x.str_content == new_value }
|
63
|
+
lambda do |corrector|
|
64
|
+
range = range_with_surrounding_comma(range_with_surrounding_space(range: node.loc.expression, side: :left), :both)
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
lambda do |corrector|
|
69
|
+
corrector.replace(node.loc.expression, "'#{new_value}'")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# Use valid platform values in case statements.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# case node['platform']
|
27
|
+
# when 'rhel'
|
28
|
+
# puts "I'm on a Red Hat system!"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
class InvalidPlatformInCase < Cop
|
32
|
+
include RangeHelp
|
33
|
+
include ::RuboCop::Chef::PlatformHelpers
|
34
|
+
|
35
|
+
MSG = 'Use valid platform values in case statements.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :node_platform?, <<-PATTERN
|
38
|
+
(send (send nil? :node) :[] (str "platform") )
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_case(node)
|
42
|
+
node_platform?(node.condition) do
|
43
|
+
node.each_when do |when_node|
|
44
|
+
when_node.each_condition do |con|
|
45
|
+
next unless con.str_type? # if the condition isn't a string we can't check so skip
|
46
|
+
|
47
|
+
if INVALID_PLATFORMS[con.str_content]
|
48
|
+
add_offense(con, location: :expression, message: MSG, severity: :refactor)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def autocorrect(node)
|
56
|
+
new_value = INVALID_PLATFORMS[node.str_content]
|
57
|
+
|
58
|
+
# some invalid platform have no direct correction value and return nil instead
|
59
|
+
return unless new_value
|
60
|
+
|
61
|
+
# if the correct value already exists in the when statement then we just want to delete this node
|
62
|
+
if node.parent.conditions.any? { |x| x.str_content == new_value }
|
63
|
+
lambda do |corrector|
|
64
|
+
range = range_with_surrounding_comma(range_with_surrounding_space(range: node.loc.expression, side: :left), :both)
|
65
|
+
corrector.remove(range)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
lambda do |corrector|
|
69
|
+
corrector.replace(node.loc.expression, "'#{new_value}'")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2020, Chef Software Inc.
|
3
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module ChefCorrectness
|
22
|
+
# When setting a node attribute as a default value for a custom resource property, make sure to wrap the node attribute in `lazy {}` so that the node attribute is available when the resource executes.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# property :Something, String, default: node['hostname']
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# property :Something, String, default: lazy { node['hostname'] }
|
31
|
+
#
|
32
|
+
class LazyEvalNodeAttributeDefaults < Cop
|
33
|
+
include RuboCop::Chef::CookbookHelpers
|
34
|
+
|
35
|
+
MSG = 'When setting a node attribute as a default value for a custom resource property, make sure to wrap the node attribute in `lazy {}` so that the node attribute is available when the resource executes.'.freeze
|
36
|
+
|
37
|
+
def_node_matcher :non_lazy_node_attribute_default?, <<-PATTERN
|
38
|
+
(send nil? :property (sym _) ... (hash <(pair (sym :default) $(send (send _ :node) :[] _) ) ...>))
|
39
|
+
PATTERN
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
non_lazy_node_attribute_default?(node) do |default|
|
43
|
+
add_offense(default, location: :expression, message: MSG, severity: :refactor)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
corrector.replace(node.loc.expression, "lazy { #{node.loc.expression.source} }")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2020, Chef Software Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
module RuboCop
|
18
|
+
module Cop
|
19
|
+
module Chef
|
20
|
+
module ChefCorrectness
|
21
|
+
# The openSSL cookbook provides a deprecated `secure_password` helper in the `Opscode::OpenSSL::Password` class, which should not longer be used. This helper would generate a random password that would be used when a data bag or attribute was no present. The practice of generating passwords to be stored on the node is bad security as it exposes the password to anyone that can view the nodes, and deleting a node deletes the password. Passwords should be retrieved from a secure source for use in cookbooks.
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# ::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
|
25
|
+
# basic_auth_password = secure_password
|
26
|
+
#
|
27
|
+
class OpenSSLPasswordHelpers < Cop
|
28
|
+
MSG = 'The `secure_password` helper from the openssl cookbooks `Opscode::OpenSSL::Password` class should not be used to generate passwords.'.freeze
|
29
|
+
|
30
|
+
def_node_matcher :openssl_helper?, <<~PATTERN
|
31
|
+
(const
|
32
|
+
(const
|
33
|
+
(const nil? :Opscode) :OpenSSL) :Password)
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_const(node)
|
37
|
+
openssl_helper?(node) do
|
38
|
+
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright:: 2019, Chef Software, Inc.
|
2
|
+
# Copyright:: 2019-2020, Chef Software, Inc.
|
3
3
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,8 +18,7 @@ module RuboCop
|
|
18
18
|
module Cop
|
19
19
|
module Chef
|
20
20
|
module ChefDeprecations
|
21
|
-
# Do not include the deprecated xml::ruby recipe to install the nokogiri gem.
|
22
|
-
# Chef Infra Client 12 and later ships with nokogiri included.
|
21
|
+
# Do not include the deprecated xml::ruby recipe to install the nokogiri gem. Chef Infra Client 12 and later ships with nokogiri included.
|
23
22
|
#
|
24
23
|
# @example
|
25
24
|
#
|
@@ -35,6 +34,7 @@ module RuboCop
|
|
35
34
|
|
36
35
|
def on_send(node)
|
37
36
|
xml_ruby_recipe?(node) do
|
37
|
+
node = node.parent if node.parent&.conditional? && node.parent&.single_line_condition? # make sure we catch any inline conditionals
|
38
38
|
add_offense(node, location: :expression, message: MSG, severity: :warning)
|
39
39
|
end
|
40
40
|
end
|
@@ -47,12 +47,14 @@ module RuboCop
|
|
47
47
|
(send
|
48
48
|
$(array ... ) :each)
|
49
49
|
(args ... )
|
50
|
-
(block
|
50
|
+
{(block
|
51
51
|
(send nil? :package
|
52
52
|
(lvar ... ))
|
53
53
|
(args)
|
54
54
|
(send nil? :action
|
55
|
-
(sym :install)))
|
55
|
+
(sym :install)))
|
56
|
+
(send nil? :package
|
57
|
+
(lvar _))}) nil?)
|
56
58
|
PATTERN
|
57
59
|
|
58
60
|
def_node_matcher :package_array_install?, <<-PATTERN
|
@@ -60,12 +62,14 @@ module RuboCop
|
|
60
62
|
(send
|
61
63
|
$(array ... ) :each)
|
62
64
|
(args ... )
|
63
|
-
(block
|
65
|
+
{(block
|
64
66
|
(send nil? :package
|
65
67
|
(lvar ... ))
|
66
68
|
(args)
|
67
69
|
(send nil? :action
|
68
|
-
(sym :install)))
|
70
|
+
(sym :install)))
|
71
|
+
(send nil? :package
|
72
|
+
(lvar _))})
|
69
73
|
PATTERN
|
70
74
|
|
71
75
|
# see if all platforms in the when condition are multipackage compliant
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookstyle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom May
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-05-
|
12
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -57,17 +57,21 @@ files:
|
|
57
57
|
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
58
58
|
- lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
|
59
59
|
- lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb
|
60
|
+
- lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb
|
60
61
|
- lib/rubocop/cop/chef/correctness/invalid_platform_helper.rb
|
61
62
|
- lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb
|
63
|
+
- lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb
|
62
64
|
- lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb
|
63
65
|
- lib/rubocop/cop/chef/correctness/invalid_value_for_platform_helper.rb
|
64
66
|
- lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb
|
67
|
+
- lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb
|
65
68
|
- lib/rubocop/cop/chef/correctness/malformed_value_for_platform.rb
|
66
69
|
- lib/rubocop/cop/chef/correctness/metadata_missing_name.rb
|
67
70
|
- lib/rubocop/cop/chef/correctness/node_normal.rb
|
68
71
|
- lib/rubocop/cop/chef/correctness/node_normal_unless.rb
|
69
72
|
- lib/rubocop/cop/chef/correctness/node_save.rb
|
70
73
|
- lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb
|
74
|
+
- lib/rubocop/cop/chef/correctness/openssl_password_helpers.rb
|
71
75
|
- lib/rubocop/cop/chef/correctness/powershell_delete_file.rb
|
72
76
|
- lib/rubocop/cop/chef/correctness/resource_sets_internal_properties.rb
|
73
77
|
- lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb
|