cookstyle 5.5.7 → 5.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/cookstyle.yml +85 -0
- data/lib/cookstyle/version.rb +1 -1
- data/lib/rubocop/cop/chef/deprecation/recipe_metadata.rb +47 -0
- data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +82 -0
- data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +49 -0
- data/lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb +51 -0
- data/lib/rubocop/cop/chef/modernize/execute_tzutil.rb +74 -0
- data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +56 -0
- data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +52 -0
- data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +58 -0
- data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +52 -0
- data/lib/rubocop/cop/chef/modernize/systctl_param_resource.rb +52 -0
- data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +57 -0
- data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +59 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1802f69a48b5c25b599199ac6e97ebd036bc1c92a6e33653700ddcd48565f6e
|
4
|
+
data.tar.gz: 12ce2bf3e7d4b3e2cf254bfe9fad557eb7c077ae52c2572f9262fca194048d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd1ab13eecd20c9bf2777d46da546f880a3f94cf2d0411a36ebdc7e5117974bf534489619e87cfc0eeafb26ae14d406c82f497b022054464ef440fb4068c69c3
|
7
|
+
data.tar.gz: 1cb23f278d044fc0acd6b818a94664e0c078aeeba78a639a9ade4fbadb5065addf62454fa78d31beed80209d11ecc9a54af3182223a233439b19a15210c1c63d
|
data/config/cookstyle.yml
CHANGED
@@ -63,6 +63,14 @@ ChefStyle/FileMode:
|
|
63
63
|
Exclude:
|
64
64
|
- '**/metadata.rb'
|
65
65
|
|
66
|
+
ChefStyle/UsePlatformHelpers:
|
67
|
+
Description: Use platform? and platform_family? helpers for checking node platform in resources and recipes
|
68
|
+
Enabled: true
|
69
|
+
VersionAdded: '5.6.0'
|
70
|
+
Exclude:
|
71
|
+
- '**/metadata.rb'
|
72
|
+
- '**/libraries/*'
|
73
|
+
|
66
74
|
###############################
|
67
75
|
# ChefCorrectness: Avoiding potential problems
|
68
76
|
###############################
|
@@ -274,6 +282,13 @@ ChefDeprecations/LongDescriptionMetadata:
|
|
274
282
|
Include:
|
275
283
|
- '**/metadata.rb'
|
276
284
|
|
285
|
+
ChefDeprecations/RecipeMetadata:
|
286
|
+
Description: The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented in the README.md file instead.
|
287
|
+
Enabled: true
|
288
|
+
VersionAdded: '5.6.0'
|
289
|
+
Include:
|
290
|
+
- '**/metadata.rb'
|
291
|
+
|
277
292
|
ChefDeprecations/CookbookDependsOnCompatResource:
|
278
293
|
Description: Don't depend on the deprecated compat_resource cookbook made obsolete by Chef 12.19+
|
279
294
|
Enabled: true
|
@@ -390,6 +405,13 @@ ChefDeprecations/IncludingYumDNFCompatRecipe:
|
|
390
405
|
Exclude:
|
391
406
|
- '**/metadata.rb'
|
392
407
|
|
408
|
+
ChefDeprecations/WindowsTaskChangeAction:
|
409
|
+
Description: The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+. The default action of :create should can now be used to create an update tasks.
|
410
|
+
Enabled: true
|
411
|
+
VersionAdded: '5.6.0'
|
412
|
+
Exclude:
|
413
|
+
- '**/metadata.rb'
|
414
|
+
|
393
415
|
###############################
|
394
416
|
# ChefModernize: Cleaning up legacy code and using new built-in resources
|
395
417
|
###############################
|
@@ -568,6 +590,69 @@ ChefModernize/ShellOutToChocolatey:
|
|
568
590
|
Exclude:
|
569
591
|
- '**/metadata.rb'
|
570
592
|
|
593
|
+
ChefModernize/CronManageResource:
|
594
|
+
Description: The cron_manage resource was renamed to cron_access in the 6.1 release of the cron cookbook and later shipped in Chef Infra Client 14.4. The new resource name should be used.
|
595
|
+
Enabled: true
|
596
|
+
VersionAdded: '5.6.0'
|
597
|
+
Exclude:
|
598
|
+
- '**/metadata.rb'
|
599
|
+
|
600
|
+
ChefModernize/UsesZypperRepo:
|
601
|
+
Description: The zypper_repo resource was renamed zypper_repository when it was added to Chef Infra Client 13.3.
|
602
|
+
Enabled: true
|
603
|
+
VersionAdded: '5.6.0'
|
604
|
+
Exclude:
|
605
|
+
- '**/metadata.rb'
|
606
|
+
|
607
|
+
ChefModernize/DependsOnZypperCookbook:
|
608
|
+
Description: Don't include the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3+
|
609
|
+
Enabled: true
|
610
|
+
VersionAdded: '5.6.0'
|
611
|
+
Exclude:
|
612
|
+
- '**/metadata.rb'
|
613
|
+
|
614
|
+
ChefModernize/ExecuteTzUtil:
|
615
|
+
Description: Use the timezone resource included in Chef Infra Client 14.6+ instead of shelling out to tzutil
|
616
|
+
Enabled: true
|
617
|
+
VersionAdded: '5.6.0'
|
618
|
+
Exclude:
|
619
|
+
- '**/metadata.rb'
|
620
|
+
|
621
|
+
ChefModernize/OpensslRsaKeyResource:
|
622
|
+
Description: The openssl_rsa_key resource was renamed to openssl_rsa_private_key in Chef Infra Client 14.0. The new resource name should be used.
|
623
|
+
Enabled: true
|
624
|
+
VersionAdded: '5.6.0'
|
625
|
+
Exclude:
|
626
|
+
- '**/metadata.rb'
|
627
|
+
|
628
|
+
ChefModernize/OpensslX509Resource:
|
629
|
+
Description: The openssl_x509 resource was renamed to openssl_x509_certificate. The new resource name should be used.
|
630
|
+
Enabled: true
|
631
|
+
VersionAdded: '5.6.0'
|
632
|
+
Exclude:
|
633
|
+
- '**/metadata.rb'
|
634
|
+
|
635
|
+
ChefModernize/OsxConfigProfileResource:
|
636
|
+
Description: The osx_config_profile resource was renamed to osx_profile. The new resource name should be used.
|
637
|
+
Enabled: true
|
638
|
+
VersionAdded: '5.6.0'
|
639
|
+
Exclude:
|
640
|
+
- '**/metadata.rb'
|
641
|
+
|
642
|
+
ChefModernize/SysctlParamResource:
|
643
|
+
Description: The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client 14.0. The new resource name should be used.
|
644
|
+
Enabled: true
|
645
|
+
VersionAdded: '5.6.0'
|
646
|
+
Exclude:
|
647
|
+
- '**/metadata.rb'
|
648
|
+
|
649
|
+
ChefModernize/MacOsXUserdefaults:
|
650
|
+
Description: The mac_os_x_userdefaults resource was renamed to macos_userdefaults when it was added to Chef Infra Client 14.0. The new resource name should be used.
|
651
|
+
Enabled: true
|
652
|
+
VersionAdded: '5.6.0'
|
653
|
+
Exclude:
|
654
|
+
- '**/metadata.rb'
|
655
|
+
|
571
656
|
###############################
|
572
657
|
# Migrating to new patterns
|
573
658
|
###############################
|
data/lib/cookstyle/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefDeprecations
|
22
|
+
# The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented
|
23
|
+
# in the README.md file instead.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# recipe 'openldap::default', 'Install and configure OpenLDAP'
|
29
|
+
#
|
30
|
+
#
|
31
|
+
class RecipeMetadata < Cop
|
32
|
+
MSG = 'The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented in the README.md file instead.'.freeze
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :recipe
|
36
|
+
end
|
37
|
+
|
38
|
+
def autocorrect(node)
|
39
|
+
lambda do |corrector|
|
40
|
+
corrector.remove(node.loc.expression)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefDeprecations
|
21
|
+
# The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+
|
22
|
+
# The default action of :create should can now be used to create an update tasks.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# windows_task 'chef ad-join leave start time' do
|
28
|
+
# task_name 'chef ad-join leave'
|
29
|
+
# start_day '06/09/2016'
|
30
|
+
# start_time '01:00'
|
31
|
+
# action [:change, :create]
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# windows_task 'chef ad-join leave start time' do
|
36
|
+
# task_name 'chef ad-join leave'
|
37
|
+
# start_day '06/09/2016'
|
38
|
+
# start_time '01:00'
|
39
|
+
# action :create
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class WindowsTaskChangeAction < Cop
|
43
|
+
include RuboCop::Chef::CookbookHelpers
|
44
|
+
|
45
|
+
MSG = 'The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+. The default action of :create should can now be used to create an update tasks.'.freeze
|
46
|
+
|
47
|
+
def on_block(node)
|
48
|
+
match_property_in_resource?(:windows_task, 'action', node) do |action_node|
|
49
|
+
action_values = action_node.arguments.first
|
50
|
+
|
51
|
+
if action_values.sym_type? # there's only a single action given
|
52
|
+
check_action(action_values)
|
53
|
+
else # it was an array of actions
|
54
|
+
action_values.node_parts.each { |action| check_action(action) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def autocorrect(node)
|
60
|
+
if node.parent.send_type? # :change was the only action
|
61
|
+
lambda do |corrector|
|
62
|
+
corrector.replace(node.loc.expression, ':create')
|
63
|
+
end
|
64
|
+
# chances are it's [:create, :change] since that's all that makes sense, but double check that theory
|
65
|
+
elsif node.parent.child_nodes.count == 2 &&
|
66
|
+
node.parent.child_nodes.map(&:value).sort == [:change, :create]
|
67
|
+
lambda do |corrector|
|
68
|
+
corrector.replace(node.parent.loc.expression, ':create')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def check_action(ast_obj)
|
76
|
+
add_offense(ast_obj, location: :expression, message: MSG, severity: :refactor) if ast_obj.value == :change
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The cron_manage resource was renamed to cron_access in the 6.1 release of the cron
|
22
|
+
# cookbook, and later shipped in Chef Infra Client 14.4. The new resource name should
|
23
|
+
# be used.
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# cron_manage 'mike'
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# cron_access 'mike'
|
30
|
+
#
|
31
|
+
class CronManageResource < Cop
|
32
|
+
include RuboCop::Chef::CookbookHelpers
|
33
|
+
|
34
|
+
MSG = 'The cron_manage resource was renamed to cron_access in the 6.1 release of the cron cookbook and later shipped in Chef Infra Client 14.4. The new resource name should be used.'.freeze
|
35
|
+
|
36
|
+
def on_send(node)
|
37
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :cron_manage
|
38
|
+
end
|
39
|
+
|
40
|
+
def autocorrect(node)
|
41
|
+
lambda do |corrector|
|
42
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^cron_manage/, 'cron_access'))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# Don't depend the zypper cookbook as the zypper_repository resource is built into
|
22
|
+
# Chef Infra Client 13.3
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# depends 'zypper'
|
28
|
+
#
|
29
|
+
class DependsOnZypperCookbook < Cop
|
30
|
+
MSG = "Don't include the zypper cookbook as the zypper_repository resource is built into Chef Infra Client 13.3+".freeze
|
31
|
+
|
32
|
+
def_node_matcher :zypper_depends?, <<-PATTERN
|
33
|
+
(send nil? :depends (str "zypper"))
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_send(node)
|
37
|
+
zypper_depends?(node) do
|
38
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def autocorrect(node)
|
43
|
+
lambda do |corrector|
|
44
|
+
corrector.remove(node.loc.expression)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# Instead of using the execute or powershell_script resources to to run the `tzutil` command, use
|
22
|
+
# Chef Infra Client's built-in timezone resource which is available in Chef Infra Client 14.6 and later.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# execute 'set tz' do
|
26
|
+
# command 'tzutil.exe /s UTC'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# execute 'tzutil /s UTC'
|
30
|
+
#
|
31
|
+
# powershell_script 'set windows timezone' do
|
32
|
+
# code "tzutil.exe /s UTC"
|
33
|
+
# not_if { shell_out('tzutil.exe /g').stdout.include?('UTC') }
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# timezone 'UTC'
|
38
|
+
#
|
39
|
+
class ExecuteTzUtil < Cop
|
40
|
+
include RuboCop::Chef::CookbookHelpers
|
41
|
+
|
42
|
+
MSG = 'Use the timezone resource included in Chef Infra Client 14.6+ instead of shelling out to tzutil'.freeze
|
43
|
+
|
44
|
+
def_node_matcher :execute_resource?, <<-PATTERN
|
45
|
+
(send nil? :execute $str)
|
46
|
+
PATTERN
|
47
|
+
|
48
|
+
def on_send(node)
|
49
|
+
execute_resource?(node) do
|
50
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.arguments.first.value.match?(/^tzutil/i)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_block(node)
|
55
|
+
match_property_in_resource?(:execute, 'command', node) do |code_property|
|
56
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if calls_tzutil?(code_property)
|
57
|
+
end
|
58
|
+
|
59
|
+
match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
|
60
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if calls_tzutil?(code_property)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def calls_tzutil?(ast_obj)
|
67
|
+
property_data = method_arg_ast_to_string(ast_obj)
|
68
|
+
return true if property_data && property_data.match?(/^tzutil/i)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The mac_os_x_userdefaults resource was renamed to macos_userdefaults when it was added to Chef Infra Client
|
22
|
+
# 14.0. The new resource name should be used.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# mac_os_x_userdefaults 'full keyboard access to all controls' do
|
26
|
+
# domain 'AppleKeyboardUIMode'
|
27
|
+
# global true
|
28
|
+
# value '2'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# macos_userdefaults 'full keyboard access to all controls' do
|
33
|
+
# domain 'AppleKeyboardUIMode'
|
34
|
+
# global true
|
35
|
+
# value '2'
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
class MacOsXUserdefaults < Cop
|
39
|
+
include RuboCop::Chef::CookbookHelpers
|
40
|
+
|
41
|
+
MSG = 'The mac_os_x_userdefaults resource was renamed to macos_userdefaults when it was added to Chef Infra Client 14.0. The new resource name should be used.'.freeze
|
42
|
+
|
43
|
+
def on_send(node)
|
44
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :mac_os_x_userdefaults
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^mac_os_x_userdefaults/, 'macos_userdefaults'))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The openssl_rsa_key resource was renamed to openssl_rsa_private_key in Chef
|
22
|
+
# Infra Client 14.0. The new resource name should be used.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# openssl_rsa_key '/etc/httpd/ssl/server.key' do
|
26
|
+
# key_length 2048
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# openssl_rsa_private_key '/etc/httpd/ssl/server.key' do
|
31
|
+
# key_length 2048
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
class OpensslRsaKeyResource < Cop
|
35
|
+
include RuboCop::Chef::CookbookHelpers
|
36
|
+
|
37
|
+
MSG = 'The openssl_rsa_key resource was renamed to openssl_rsa_private_key in Chef Infra Client 14.0. The new resource name should be used.'.freeze
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :openssl_rsa_key
|
41
|
+
end
|
42
|
+
|
43
|
+
def autocorrect(node)
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^openssl_rsa_key/, 'openssl_rsa_private_key'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The openssl_x509 resource was renamed to openssl_x509_certificate.
|
22
|
+
# The new resource name should be used.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# openssl_x509 '/etc/httpd/ssl/mycert.pem' do
|
26
|
+
# common_name 'www.f00bar.com'
|
27
|
+
# org 'Foo Bar'
|
28
|
+
# org_unit 'Lab'
|
29
|
+
# country 'US'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # good
|
33
|
+
# openssl_x509_certificate '/etc/httpd/ssl/mycert.pem' do
|
34
|
+
# common_name 'www.f00bar.com'
|
35
|
+
# org 'Foo Bar'
|
36
|
+
# org_unit 'Lab'
|
37
|
+
# country 'US'
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
class OpensslX509Resource < Cop
|
41
|
+
include RuboCop::Chef::CookbookHelpers
|
42
|
+
|
43
|
+
MSG = 'The openssl_x509 resource was renamed to openssl_x509_certificate. The new resource name should be used.'.freeze
|
44
|
+
|
45
|
+
def on_send(node)
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :openssl_x509
|
47
|
+
end
|
48
|
+
|
49
|
+
def autocorrect(node)
|
50
|
+
lambda do |corrector|
|
51
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^openssl_x509/, 'openssl_x509_certificate'))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The osx_config_profile resource was renamed to osx_profile.
|
22
|
+
# The new resource name should be used.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# osx_config_profile 'Install screensaver profile' do
|
26
|
+
# profile 'screensaver/com.company.screensaver.mobileconfig'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# osx_profile 'Install screensaver profile' do
|
31
|
+
# profile 'screensaver/com.company.screensaver.mobileconfig'
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
class OsxConfigProfileResource < Cop
|
35
|
+
include RuboCop::Chef::CookbookHelpers
|
36
|
+
|
37
|
+
MSG = 'The osx_config_profile resource was renamed to osx_profile. The new resource name should be used.'.freeze
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :osx_config_profile
|
41
|
+
end
|
42
|
+
|
43
|
+
def autocorrect(node)
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^osx_config_profile/, 'osx_profile'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client
|
22
|
+
# 14.0. The new resource name should be used.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# sysctl_param 'fs.aio-max-nr' do
|
26
|
+
# value '1048576'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# sysctl 'fs.aio-max-nr' do
|
31
|
+
# value '1048576'
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
class SysctlParamResource < Cop
|
35
|
+
include RuboCop::Chef::CookbookHelpers
|
36
|
+
|
37
|
+
MSG = 'The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client 14.0. The new resource name should be used.'.freeze
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :sysctl_param
|
41
|
+
end
|
42
|
+
|
43
|
+
def autocorrect(node)
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^sysctl_param/, 'sysctl'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefModernize
|
21
|
+
# The zypper_repo resource was renamed zypper_repository when it was added to Chef Infra Client 13.3.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# zypper_repo 'apache' do
|
27
|
+
# baseurl 'http://download.opensuse.org/repositories/Apache'
|
28
|
+
# path '/openSUSE_Leap_42.2'
|
29
|
+
# type 'rpm-md'
|
30
|
+
# priority '100'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# # good
|
34
|
+
# zypper_repository 'apache' do
|
35
|
+
# baseurl 'http://download.opensuse.org/repositories/Apache'
|
36
|
+
# path '/openSUSE_Leap_42.2'
|
37
|
+
# type 'rpm-md'
|
38
|
+
# priority '100'
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
class UsesZypperRepo < Cop
|
42
|
+
MSG = 'The zypper_repo resource was renamed zypper_repository when it was added to Chef Infra Client 13.3.'.freeze
|
43
|
+
|
44
|
+
def on_send(node)
|
45
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :zypper_repo
|
46
|
+
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
lambda do |corrector|
|
50
|
+
corrector.replace(node.loc.expression, node.source.gsub(/^zypper_repo/, 'zypper_repository'))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: 2019, 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 ChefStyle
|
21
|
+
# Use the platform?() and platform_family?() helpers instead of node['platform] == 'foo'
|
22
|
+
# and node['platform_family'] == 'bar'. These helpers are easier to read and can accept multiple
|
23
|
+
# platform arguments, which greatly simplifies complex platform logic.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# node['platform'] == 'ubuntu'
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# platform?('ubuntu')
|
32
|
+
#
|
33
|
+
class UsePlatformHelpers < Cop
|
34
|
+
MSG = 'Use platform? and platform_family? helpers for checking node platform'.freeze
|
35
|
+
|
36
|
+
def_node_matcher :platform_check?, <<-PATTERN
|
37
|
+
( send (send (send nil? :node) :[] $(str {"platform" "platform_family"}) ) :== $str )
|
38
|
+
PATTERN
|
39
|
+
|
40
|
+
def on_send(node)
|
41
|
+
platform_check?(node) do |type, plat|
|
42
|
+
# set these so we can use them in the auto_correct method
|
43
|
+
@type = type
|
44
|
+
@plat = plat
|
45
|
+
|
46
|
+
add_offense(node, location: :expression, message: MSG, severity: :refactor)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def autocorrect(node)
|
51
|
+
lambda do |corrector|
|
52
|
+
corrector.replace(node.loc.expression, "#{@type.value}?('#{@plat.value}')")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
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: 5.
|
4
|
+
version: 5.6.2
|
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: 2019-09-
|
12
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -113,11 +113,13 @@ files:
|
|
113
113
|
- lib/rubocop/cop/chef/deprecation/node_set.rb
|
114
114
|
- lib/rubocop/cop/chef/deprecation/node_set_unless.rb
|
115
115
|
- lib/rubocop/cop/chef/deprecation/provides_metadata.rb
|
116
|
+
- lib/rubocop/cop/chef/deprecation/recipe_metadata.rb
|
116
117
|
- lib/rubocop/cop/chef/deprecation/replaces_metadata.rb
|
117
118
|
- lib/rubocop/cop/chef/deprecation/require_recipe.rb
|
118
119
|
- lib/rubocop/cop/chef/deprecation/suggests_metadata.rb
|
119
120
|
- lib/rubocop/cop/chef/deprecation/use_inline_resources.rb
|
120
121
|
- lib/rubocop/cop/chef/deprecation/user_supports_property.rb
|
122
|
+
- lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb
|
121
123
|
- lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb
|
122
124
|
- lib/rubocop/cop/chef/deprecation/yum_dnf_compat_recipe.rb
|
123
125
|
- lib/rubocop/cop/chef/effortless/data_bags.rb
|
@@ -126,11 +128,18 @@ files:
|
|
126
128
|
- lib/rubocop/cop/chef/modernize/berksfile_source.rb
|
127
129
|
- lib/rubocop/cop/chef/modernize/build_essential.rb
|
128
130
|
- lib/rubocop/cop/chef/modernize/chef_14_resources.rb
|
131
|
+
- lib/rubocop/cop/chef/modernize/cron_manage_resource.rb
|
129
132
|
- lib/rubocop/cop/chef/modernize/defines_chefspec_matchers.rb
|
133
|
+
- lib/rubocop/cop/chef/modernize/depends_zypper_cookbook.rb
|
130
134
|
- lib/rubocop/cop/chef/modernize/execute_apt_update.rb
|
135
|
+
- lib/rubocop/cop/chef/modernize/execute_tzutil.rb
|
131
136
|
- lib/rubocop/cop/chef/modernize/includes_mixin_shellout.rb
|
132
137
|
- lib/rubocop/cop/chef/modernize/libarchive_file.rb
|
138
|
+
- lib/rubocop/cop/chef/modernize/macos_user_defaults.rb
|
133
139
|
- lib/rubocop/cop/chef/modernize/minitest_handler_usage.rb
|
140
|
+
- lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb
|
141
|
+
- lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb
|
142
|
+
- lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb
|
134
143
|
- lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb
|
135
144
|
- lib/rubocop/cop/chef/modernize/powershell_install_package.rb
|
136
145
|
- lib/rubocop/cop/chef/modernize/powershell_install_windowsfeature.rb
|
@@ -142,15 +151,18 @@ files:
|
|
142
151
|
- lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb
|
143
152
|
- lib/rubocop/cop/chef/modernize/seven_zip_archive.rb
|
144
153
|
- lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb
|
154
|
+
- lib/rubocop/cop/chef/modernize/systctl_param_resource.rb
|
145
155
|
- lib/rubocop/cop/chef/modernize/whyrun_supported_true.rb
|
146
156
|
- lib/rubocop/cop/chef/modernize/windows_default_recipe.rb
|
147
157
|
- lib/rubocop/cop/chef/modernize/windows_version_helper.rb
|
148
158
|
- lib/rubocop/cop/chef/modernize/windows_zipfile.rb
|
159
|
+
- lib/rubocop/cop/chef/modernize/zypper_repo.rb
|
149
160
|
- lib/rubocop/cop/chef/style/attribute_keys.rb
|
150
161
|
- lib/rubocop/cop/chef/style/comment_sentence_spacing.rb
|
151
162
|
- lib/rubocop/cop/chef/style/comments_copyright_format.rb
|
152
163
|
- lib/rubocop/cop/chef/style/comments_format.rb
|
153
164
|
- lib/rubocop/cop/chef/style/file_mode.rb
|
165
|
+
- lib/rubocop/cop/chef/style/use_platform_helpers.rb
|
154
166
|
homepage: https://github.com/chef/cookstyle
|
155
167
|
licenses:
|
156
168
|
- Apache-2.0
|