cookstyle 7.25.10 → 7.30.1
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 +44 -0
- data/config/disable_all.yml +8 -0
- data/config/upstream.yml +46 -1
- data/lib/cookstyle/version.rb +2 -2
- data/lib/rubocop/chef/cookbook_helpers.rb +2 -0
- data/lib/rubocop/cop/chef/correctness/invalid_cookbook_name.rb +47 -0
- data/lib/rubocop/cop/chef/correctness/invalid_notification_resource.rb +59 -0
- data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +3 -2
- data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +54 -14
- data/lib/rubocop/cop/chef/security/ssh_private_key.rb +49 -0
- data/lib/rubocop/monkey_patches/directive_comment.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af05586e951fed9a9a11777583d2f8b0ec7634cca38b3b5b9641e2afb11be50b
|
4
|
+
data.tar.gz: 8d727e0f4898bf20149fa74ee6d15782840577c98eeb9fe25048ae71ab13c4b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd9a0129be207bd120c0ba860260726c4547b8e0356eda5c221b70d29aaf9ec92fdce5af7450b919f8a74774b79820c128220749e883c226de4c82f45c21915
|
7
|
+
data.tar.gz: 74e57634c9aef93e952858a542cac3966c849fa3e1deb2dd5b0ef4b7cd9f8167eba767e55635b72c2cbc7f3d08228a3fed26ed4f2e072e4eb6d8c78a09c3b151
|
data/config/cookstyle.yml
CHANGED
@@ -506,6 +506,24 @@ Chef/Correctness/MetadataMissingVersion:
|
|
506
506
|
Include:
|
507
507
|
- '**/metadata.rb'
|
508
508
|
|
509
|
+
Chef/Correctness/InvalidCookbookName:
|
510
|
+
Description: Cookbook names should not contain invalid characters such as periods.
|
511
|
+
StyleGuide: 'chef_correctness_invalidcookbookname'
|
512
|
+
Enabled: true
|
513
|
+
VersionAdded: '7.27'
|
514
|
+
Include:
|
515
|
+
- '**/metadata.rb'
|
516
|
+
|
517
|
+
Chef/Correctness/InvalidNotificationResource:
|
518
|
+
Description: The resource to notify when calling `notifies` or `subscribes` must be a string.
|
519
|
+
StyleGuide: 'chef_correctness_invalidnotificationresource'
|
520
|
+
Enabled: true
|
521
|
+
VersionAdded: '7.28'
|
522
|
+
Exclude:
|
523
|
+
- '**/attributes/*.rb'
|
524
|
+
- '**/metadata.rb'
|
525
|
+
- '**/Berksfile'
|
526
|
+
|
509
527
|
###############################
|
510
528
|
# Chef/Sharing: Issues that prevent sharing code with other teams or with the Chef community in general
|
511
529
|
###############################
|
@@ -2281,6 +2299,24 @@ InSpec/Deprecations/AttributeDefault:
|
|
2281
2299
|
Include:
|
2282
2300
|
- '**/controls/*.rb'
|
2283
2301
|
|
2302
|
+
#### Security Cops
|
2303
|
+
|
2304
|
+
Chef/Security:
|
2305
|
+
StyleGuideBaseURL: https://docs.chef.io/workstation/cookstyle/
|
2306
|
+
|
2307
|
+
Chef/Security/ :
|
2308
|
+
Description: Do not include plain text SSH private keys in your cookbook code. This sensitive data should be fetched from secrets management systems so that secrets are not uploaded in plain text to the Chef Infra Server or committed to source control systems.
|
2309
|
+
StyleGuide: 'chef_security_sshprivatekey'
|
2310
|
+
Enabled: true
|
2311
|
+
VersionAdded: '7.28'
|
2312
|
+
Include:
|
2313
|
+
- '**/libraries/*.rb'
|
2314
|
+
- '**/resources/*.rb'
|
2315
|
+
- '**/providers/*.rb'
|
2316
|
+
- '**/recipes/*.rb'
|
2317
|
+
- '**/attributes/*.rb'
|
2318
|
+
- '**/definitions/*.rb'
|
2319
|
+
|
2284
2320
|
#### The base rubocop 0.37 enabled.yml file we started with ####
|
2285
2321
|
|
2286
2322
|
Layout/AccessModifierIndentation:
|
@@ -3035,3 +3071,11 @@ Lint/DeprecatedConstants:
|
|
3035
3071
|
# always turn on deprecation cops from rubocop
|
3036
3072
|
Lint/ErbNewArguments:
|
3037
3073
|
Enabled: true
|
3074
|
+
|
3075
|
+
# reduce file read complexity
|
3076
|
+
Style/FileRead:
|
3077
|
+
Enabled: true
|
3078
|
+
|
3079
|
+
# reduce file write complexity
|
3080
|
+
Style/FileWrite:
|
3081
|
+
Enabled: true
|
data/config/disable_all.yml
CHANGED
@@ -491,6 +491,8 @@ Naming/AccessorMethodName:
|
|
491
491
|
Enabled: false
|
492
492
|
Naming/AsciiIdentifiers:
|
493
493
|
Enabled: false
|
494
|
+
Naming/BlockForwarding:
|
495
|
+
Enabled: false
|
494
496
|
Naming/BlockParameterName:
|
495
497
|
Enabled: false
|
496
498
|
Naming/ClassAndModuleCamelCase:
|
@@ -641,6 +643,10 @@ Style/ExplicitBlockArgument:
|
|
641
643
|
Enabled: false
|
642
644
|
Style/ExponentialNotation:
|
643
645
|
Enabled: false
|
646
|
+
Style/FileRead:
|
647
|
+
Enabled: false
|
648
|
+
Style/FileWrite:
|
649
|
+
Enabled: false
|
644
650
|
Style/FloatDivision:
|
645
651
|
Enabled: false
|
646
652
|
Style/For:
|
@@ -705,6 +711,8 @@ Style/LambdaCall:
|
|
705
711
|
Enabled: false
|
706
712
|
Style/LineEndConcatenation:
|
707
713
|
Enabled: false
|
714
|
+
Style/MapToHash:
|
715
|
+
Enabled: false
|
708
716
|
Style/MethodCallWithoutArgsParentheses:
|
709
717
|
Enabled: false
|
710
718
|
Style/MethodCallWithArgsParentheses:
|
data/config/upstream.yml
CHANGED
@@ -78,6 +78,8 @@ AllCops:
|
|
78
78
|
# When specifying style guide URLs, any paths and/or fragments will be
|
79
79
|
# evaluated relative to the base URL.
|
80
80
|
StyleGuideBaseURL: https://rubystyle.guide
|
81
|
+
# Documentation URLs will be constructed using the base URL.
|
82
|
+
DocumentationBaseURL: https://docs.rubocop.org/rubocop
|
81
83
|
# Extra details are not displayed in offense messages by default. Change
|
82
84
|
# behavior by overriding ExtraDetails, or by giving the
|
83
85
|
# `-E/--extra-details` option.
|
@@ -449,7 +451,11 @@ Layout/ClosingParenthesisIndentation:
|
|
449
451
|
Layout/CommentIndentation:
|
450
452
|
Description: 'Indentation of comments.'
|
451
453
|
Enabled: true
|
454
|
+
# When true, allows comments to have extra indentation if that aligns them
|
455
|
+
# with a comment on the preceding line.
|
456
|
+
AllowForAlignment: false
|
452
457
|
VersionAdded: '0.49'
|
458
|
+
VersionChanged: '1.24'
|
453
459
|
|
454
460
|
Layout/ConditionPosition:
|
455
461
|
Description: >-
|
@@ -1796,7 +1802,9 @@ Lint/ImplicitStringConcatenation:
|
|
1796
1802
|
Lint/IncompatibleIoSelectWithFiberScheduler:
|
1797
1803
|
Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
|
1798
1804
|
Enabled: pending
|
1805
|
+
SafeAutoCorrect: false
|
1799
1806
|
VersionAdded: '1.21'
|
1807
|
+
VersionChanged: '1.24'
|
1800
1808
|
|
1801
1809
|
Lint/IneffectiveAccessModifier:
|
1802
1810
|
Description: >-
|
@@ -2479,6 +2487,16 @@ Naming/BinaryOperatorParameterName:
|
|
2479
2487
|
VersionAdded: '0.50'
|
2480
2488
|
VersionChanged: '1.2'
|
2481
2489
|
|
2490
|
+
Naming/BlockForwarding:
|
2491
|
+
Description: 'Use anonymous block forwarding.'
|
2492
|
+
StyleGuide: '#block-forwarding'
|
2493
|
+
Enabled: pending
|
2494
|
+
VersionAdded: '1.24'
|
2495
|
+
EnforcedStyle: anonymous
|
2496
|
+
SupportedStyles:
|
2497
|
+
- anonymous
|
2498
|
+
- explicit
|
2499
|
+
|
2482
2500
|
Naming/BlockParameterName:
|
2483
2501
|
Description: >-
|
2484
2502
|
Checks for block parameter names that contain capital letters,
|
@@ -3492,6 +3510,18 @@ Style/ExponentialNotation:
|
|
3492
3510
|
- engineering
|
3493
3511
|
- integral
|
3494
3512
|
|
3513
|
+
Style/FileRead:
|
3514
|
+
Description: 'Favor `File.(bin)read` convenience methods.'
|
3515
|
+
StyleGuide: '#file-read'
|
3516
|
+
Enabled: pending
|
3517
|
+
VersionAdded: '1.24'
|
3518
|
+
|
3519
|
+
Style/FileWrite:
|
3520
|
+
Description: 'Favor `File.(bin)write` convenience methods.'
|
3521
|
+
StyleGuide: '#file-write'
|
3522
|
+
Enabled: pending
|
3523
|
+
VersionAdded: '1.24'
|
3524
|
+
|
3495
3525
|
Style/FloatDivision:
|
3496
3526
|
Description: 'For performing float division, coerce one side only.'
|
3497
3527
|
StyleGuide: '#float-division'
|
@@ -3650,7 +3680,7 @@ Style/HashSyntax:
|
|
3650
3680
|
StyleGuide: '#hash-literals'
|
3651
3681
|
Enabled: true
|
3652
3682
|
VersionAdded: '0.9'
|
3653
|
-
VersionChanged: '
|
3683
|
+
VersionChanged: '1.24'
|
3654
3684
|
EnforcedStyle: ruby19
|
3655
3685
|
SupportedStyles:
|
3656
3686
|
# checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
|
@@ -3661,6 +3691,13 @@ Style/HashSyntax:
|
|
3661
3691
|
- no_mixed_keys
|
3662
3692
|
# enforces both ruby19 and no_mixed_keys styles
|
3663
3693
|
- ruby19_no_mixed_keys
|
3694
|
+
# Force hashes that have a hash value omission
|
3695
|
+
EnforcedShorthandSyntax: always
|
3696
|
+
SupportedShorthandSyntax:
|
3697
|
+
# forces use of the 3.1 syntax (e.g. {foo:}) when the hash key and value are the same.
|
3698
|
+
- always
|
3699
|
+
# forces use of explicit hash literal value.
|
3700
|
+
- never
|
3664
3701
|
# Force hashes that have a symbol value to use hash rockets
|
3665
3702
|
UseHashRocketsWithSymbolValues: false
|
3666
3703
|
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
|
@@ -3837,6 +3874,12 @@ Style/LineEndConcatenation:
|
|
3837
3874
|
VersionAdded: '0.18'
|
3838
3875
|
VersionChanged: '0.64'
|
3839
3876
|
|
3877
|
+
Style/MapToHash:
|
3878
|
+
Description: 'Prefer `to_h` with a block over `map.to_h`.'
|
3879
|
+
Enabled: pending
|
3880
|
+
VersionAdded: '1.24'
|
3881
|
+
Safe: false
|
3882
|
+
|
3840
3883
|
Style/MethodCallWithArgsParentheses:
|
3841
3884
|
Description: 'Use parentheses for method calls with arguments.'
|
3842
3885
|
StyleGuide: '#method-invocation-parens'
|
@@ -4205,6 +4248,8 @@ Style/NumericLiterals:
|
|
4205
4248
|
VersionChanged: '0.48'
|
4206
4249
|
MinDigits: 5
|
4207
4250
|
Strict: false
|
4251
|
+
# You can specify allowed numbers. (e.g. port number 3000, 8080, and etc)
|
4252
|
+
AllowedNumbers: []
|
4208
4253
|
|
4209
4254
|
Style/NumericPredicate:
|
4210
4255
|
Description: >-
|
data/lib/cookstyle/version.rb
CHANGED
@@ -111,6 +111,8 @@ module RuboCop
|
|
111
111
|
case node.type
|
112
112
|
when :send
|
113
113
|
yield(node) if node.receiver.nil? # if it's not nil then we're not in a property foo we're in bar.foo
|
114
|
+
when :block # ie: not_if { ruby_foo }
|
115
|
+
yield(node)
|
114
116
|
when :while
|
115
117
|
extract_send_types(node.body) { |t| yield(t) }
|
116
118
|
when :if
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2022, Chef Software Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module Correctness
|
22
|
+
# Cookbook names should not contain invalid characters such as periods.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# #### incorrect
|
27
|
+
# name 'foo.bar'
|
28
|
+
#
|
29
|
+
# #### correct
|
30
|
+
# name 'foo_bar'
|
31
|
+
#
|
32
|
+
class InvalidCookbookName < Base
|
33
|
+
RESTRICT_ON_SEND = [:name].freeze
|
34
|
+
MSG = 'Cookbook names should not contain invalid characters such as periods.'
|
35
|
+
|
36
|
+
def_node_matcher :has_name?, '(send nil? :name $str)'
|
37
|
+
|
38
|
+
def on_send(node)
|
39
|
+
has_name?(node) do |val|
|
40
|
+
add_offense(node, message: MSG, severity: :refactor) if val.value.include?('.')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2022, Chef Software, Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module Correctness
|
22
|
+
# The resource to notify when calling `notifies` or `subscribes` must be a string.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# #### incorrect
|
27
|
+
#
|
28
|
+
# template '/etc/www/configures-apache.conf' do
|
29
|
+
# notifies :restart, service['apache'], :immediately
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# template '/etc/www/configures-apache.conf' do
|
33
|
+
# notifies :restart, service[apache], :immediately
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# #### correct
|
37
|
+
#
|
38
|
+
# template '/etc/www/configures-apache.conf' do
|
39
|
+
# notifies :restart, 'service[apache]', :immediately
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class InvalidNotificationResource < Base
|
43
|
+
MSG = 'The resource to notify when calling `notifies` or `subscribes` must be a string.'
|
44
|
+
RESTRICT_ON_SEND = [:notifies, :subscribes].freeze
|
45
|
+
|
46
|
+
def_node_matcher :invalid_notification?, <<-PATTERN
|
47
|
+
(send nil? {:notifies :subscribes} (sym _) $(send (send nil? _) :[] ...) ...)
|
48
|
+
PATTERN
|
49
|
+
|
50
|
+
def on_send(node)
|
51
|
+
invalid_notification?(node) do |resource|
|
52
|
+
add_offense(resource, message: MSG, severity: :refactor)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright:: 2019, Chef Software, Inc.
|
3
|
+
# Copyright:: 2019-2022, Chef Software, Inc.
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -26,6 +26,7 @@ module RuboCop
|
|
26
26
|
# #### incorrect
|
27
27
|
# depends 'poise'
|
28
28
|
# depends 'poise-service'
|
29
|
+
# depends 'poise-hoist'
|
29
30
|
#
|
30
31
|
class CookbookDependsOnPoise < Base
|
31
32
|
MSG = 'Cookbooks should not depend on the deprecated Poise framework'
|
@@ -37,7 +38,7 @@ module RuboCop
|
|
37
38
|
|
38
39
|
def on_send(node)
|
39
40
|
depends_method?(node) do |arg|
|
40
|
-
add_offense(node, message: MSG, severity: :warning) if %w(poise poise-service).include?(arg.value)
|
41
|
+
add_offense(node, message: MSG, severity: :warning) if %w(poise poise-service poise-hoist).include?(arg.value)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright:: 2020, Chef Software, Inc.
|
3
|
+
# Copyright:: 2020-2022, Chef Software, Inc.
|
4
4
|
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
module Cop
|
20
20
|
module Chef
|
21
21
|
module RedundantCode
|
22
|
-
# Use the
|
22
|
+
# Use the `:create_if_missing` action instead of `not_if` with a `::File.exist(FOO)` check.
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
#
|
@@ -32,6 +32,15 @@ module RuboCop
|
|
32
32
|
# not_if { ::File.exists?('/logs/foo/error.log') }
|
33
33
|
# end
|
34
34
|
#
|
35
|
+
# remote_file 'Download file' do
|
36
|
+
# path '/foo/bar'
|
37
|
+
# source 'https://foo.com/bar'
|
38
|
+
# owner 'root'
|
39
|
+
# group 'root'
|
40
|
+
# mode '0644'
|
41
|
+
# not_if { ::File.exist?('/foo/bar') }
|
42
|
+
# end
|
43
|
+
#
|
35
44
|
# #### correct
|
36
45
|
# cookbook_file '/logs/foo/error.log' do
|
37
46
|
# source 'error.log'
|
@@ -41,30 +50,61 @@ module RuboCop
|
|
41
50
|
# action :create_if_missing
|
42
51
|
# end
|
43
52
|
#
|
53
|
+
# remote_file 'Download file' do
|
54
|
+
# path '/foo/bar'
|
55
|
+
# source 'https://foo.com/bar'
|
56
|
+
# owner 'root'
|
57
|
+
# group 'root'
|
58
|
+
# mode '0644'
|
59
|
+
# action :create_if_missing
|
60
|
+
# end
|
61
|
+
#
|
44
62
|
class UseCreateIfMissing < Base
|
45
63
|
include RuboCop::Chef::CookbookHelpers
|
46
64
|
extend AutoCorrector
|
65
|
+
include RangeHelp
|
47
66
|
|
48
67
|
MSG = 'Use the :create_if_missing action instead of not_if with a ::File.exist(FOO) check.'
|
68
|
+
RESOURCES = %i(cookbook_file file remote_directory cron_d remote_file template).freeze
|
49
69
|
|
50
|
-
def_node_matcher :
|
51
|
-
(
|
70
|
+
def_node_matcher :file_exist_value, <<-PATTERN
|
71
|
+
(send (const {nil? (cbase)} :File) {:exist? :exists?} $(...))
|
52
72
|
PATTERN
|
53
73
|
|
54
|
-
|
55
|
-
(block (send nil? {:cookbook_file :file :remote_directory :cron_d :remote_file :template} $str) ... )
|
56
|
-
PATTERN
|
74
|
+
def_node_search :has_action?, '(send nil? :action ...)'
|
57
75
|
|
58
|
-
def_node_search :create_action
|
76
|
+
def_node_search :create_action, '(send nil? :action $sym)'
|
77
|
+
|
78
|
+
def_node_search :path_property_node, '(send nil? :path $...)'
|
59
79
|
|
60
80
|
def on_block(node)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
81
|
+
match_property_in_resource?(RESOURCES, :not_if, node) do |prop|
|
82
|
+
# if it's not a block type then it's not a ruby block with a file.exist
|
83
|
+
return unless prop.block_type?
|
84
|
+
|
85
|
+
file_exist_value(prop.body) do |exists_content| # check the contents of the ruby block that's passed
|
86
|
+
# not an offense if:
|
87
|
+
# - The resource block name (the last arg of the send) doesn't match the exists check content
|
88
|
+
# - If a path property is used it doesn't match the exists check content
|
89
|
+
return unless exists_content == node.send_node.last_argument ||
|
90
|
+
exists_content == path_property_node(node)&.first&.first
|
91
|
+
|
92
|
+
# we have an action so check if it is :create. If that's the case we can replace that value
|
93
|
+
# and delete the not_if line. Otherwise it's an action like :remove and while the whole resource
|
94
|
+
# no longer makes sense that's not our problem here.
|
95
|
+
create_action(node) do |create_action|
|
96
|
+
return unless create_action == s(:sym, :create)
|
97
|
+
add_offense(prop, message: MSG, severity: :refactor) do |corrector|
|
98
|
+
corrector.replace(create_action, ':create_if_missing')
|
99
|
+
corrector.remove(range_by_whole_lines(prop.source_range, include_final_newline: true))
|
100
|
+
end
|
101
|
+
return
|
102
|
+
end
|
65
103
|
|
66
|
-
|
67
|
-
|
104
|
+
# if we got this far we didn't return above when we had an action
|
105
|
+
# so we can just replace the not_if line with a new :create_if_missing action
|
106
|
+
add_offense(prop, message: MSG, severity: :refactor) do |corrector|
|
107
|
+
corrector.replace(prop, 'action :create_if_missing')
|
68
108
|
end
|
69
109
|
end
|
70
110
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: 2021-2022, Chef Software, Inc.
|
4
|
+
# Author:: Tim Smith (<tsmith@chef.io>)
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module RuboCop
|
19
|
+
module Cop
|
20
|
+
module Chef
|
21
|
+
module Security
|
22
|
+
# Do not include plain text SSH private keys in your cookbook code. This sensitive data should be fetched from secrets management systems so that secrets are not uploaded in plain text to the Chef Infra Server or committed to source control systems.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
#
|
26
|
+
# #### incorrect
|
27
|
+
# file '/Users/bob_bobberson/.ssh/id_rsa' do
|
28
|
+
# content '-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----'
|
29
|
+
# mode '600'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
class SshPrivateKey < Base
|
33
|
+
MSG = 'Do not include plain text SSH private keys in your cookbook code. This sensitive data should be fetched from secrets management systems so that secrets are not uploaded in plain text to the Chef Infra Server or committed to source control systems.'
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
return unless node.arguments?
|
37
|
+
node.arguments.each do |arg|
|
38
|
+
next unless arg.str_type? || arg.dstr_type?
|
39
|
+
|
40
|
+
if arg.value.start_with?('-----BEGIN RSA PRIVATE', '-----BEGIN EC PRIVATE') # cookstyle: disable Chef/Security/SshPrivateKey
|
41
|
+
add_offense(node, message: MSG, severity: :warning)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -3,7 +3,7 @@ module RuboCop
|
|
3
3
|
# we're monkey patching the config regex to allow for # cookstyle: disable whatever
|
4
4
|
# in addition to the # rubocop: disable whatever that comes with RuboCop
|
5
5
|
class DirectiveComment
|
6
|
-
remove_const(
|
6
|
+
remove_const(:DIRECTIVE_COMMENT_REGEXP)
|
7
7
|
DIRECTIVE_COMMENT_REGEXP = Regexp.new(
|
8
8
|
"# (?:rubocop|cookstyle) : ((?:disable|enable|todo))\\b #{COPS_PATTERN}"
|
9
9
|
.gsub(' ', '\s*')
|
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: 7.
|
4
|
+
version: 7.30.1
|
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:
|
12
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.24.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.
|
27
|
+
version: 1.24.1
|
28
28
|
description:
|
29
29
|
email:
|
30
30
|
- thom@chef.io
|
@@ -55,7 +55,9 @@ files:
|
|
55
55
|
- lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb
|
56
56
|
- lib/rubocop/cop/chef/correctness/dnf_package_allow_downgrades.rb
|
57
57
|
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
|
58
|
+
- lib/rubocop/cop/chef/correctness/invalid_cookbook_name.rb
|
58
59
|
- lib/rubocop/cop/chef/correctness/invalid_default_action.rb
|
60
|
+
- lib/rubocop/cop/chef/correctness/invalid_notification_resource.rb
|
59
61
|
- lib/rubocop/cop/chef/correctness/invalid_notification_timing.rb
|
60
62
|
- lib/rubocop/cop/chef/correctness/invalid_platform_family_helper.rb
|
61
63
|
- lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb
|
@@ -273,6 +275,7 @@ files:
|
|
273
275
|
- lib/rubocop/cop/chef/redundant/unnecessary_desired_state.rb
|
274
276
|
- lib/rubocop/cop/chef/redundant/unnecessary_name_property.rb
|
275
277
|
- lib/rubocop/cop/chef/redundant/use_create_if_missing.rb
|
278
|
+
- lib/rubocop/cop/chef/security/ssh_private_key.rb
|
276
279
|
- lib/rubocop/cop/chef/sharing/default_maintainer_metadata.rb
|
277
280
|
- lib/rubocop/cop/chef/sharing/empty_metadata_field.rb
|
278
281
|
- lib/rubocop/cop/chef/sharing/include_property_descriptions.rb
|