puppet-lint-check_unsafe_interpolations 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e90440a4433f82202315ae44353245ca75123974ba549af84cd46d47bc9b1b3
|
4
|
+
data.tar.gz: 29e8dbe2d2e16fe3593dcc3ec4f1b7ef2d87b0d88df7b626086001e93562aeca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e01934881a975c45ca0b2e874694fe8fa7dcde5c5ef83e67bce31fba3f27b630a35a9790ab380c6915790f22ae95d313d967bc6e7efbbe17047d1b6d0fa3adc
|
7
|
+
data.tar.gz: 8acb71fac65eaa6389e70f821ef3c5eda2477c1de8265815ad9f703b7edfc506dce5ebcb5ff959e8c0494d8f3eb98d6e93c77ba1227574364ed94738fb346a38
|
@@ -1,6 +1,7 @@
|
|
1
1
|
PuppetLint.new_check(:check_unsafe_interpolations) do
|
2
2
|
COMMANDS = Array['command', 'onlyif', 'unless']
|
3
3
|
INTERPOLATED_STRINGS = Array[:DQPRE, :DQMID]
|
4
|
+
USELESS_CHARS = Array[:WHITESPACE, :COMMA]
|
4
5
|
def check
|
5
6
|
# Gather any exec commands' resources into an array
|
6
7
|
exec_resources = resource_indexes.map { |resource|
|
@@ -8,14 +9,9 @@ PuppetLint.new_check(:check_unsafe_interpolations) do
|
|
8
9
|
resource if resource[:type].value == 'exec' && !(COMMANDS & resource_parameters).empty?
|
9
10
|
}.compact
|
10
11
|
|
11
|
-
# Filter the list of titles returned by get_title_tokens for those contained in an exec
|
12
|
-
exec_title_tokens = get_title_tokens.select { |title|
|
13
|
-
title if title[:resource_type].value == 'exec'
|
14
|
-
}.compact
|
15
|
-
|
16
12
|
# Iterate over title tokens and raise a warning if any are variables
|
17
|
-
unless
|
18
|
-
|
13
|
+
unless get_exec_titles.empty?
|
14
|
+
get_exec_titles.each do |title|
|
19
15
|
check_unsafe_title(title)
|
20
16
|
end
|
21
17
|
end
|
@@ -28,7 +24,7 @@ PuppetLint.new_check(:check_unsafe_interpolations) do
|
|
28
24
|
|
29
25
|
# Iterate over the tokens in a title and raise a warning if an interpolated variable is found
|
30
26
|
def check_unsafe_title(title)
|
31
|
-
title
|
27
|
+
title.each do |token|
|
32
28
|
notify_warning(token.next_code_token) if interpolated?(token)
|
33
29
|
end
|
34
30
|
end
|
@@ -83,43 +79,36 @@ PuppetLint.new_check(:check_unsafe_interpolations) do
|
|
83
79
|
|
84
80
|
# This function is a replacement for puppet_lint's title_tokens function which assumes titles have single quotes
|
85
81
|
# This function adds a check for titles in double quotes where there could be interpolated variables
|
86
|
-
def
|
82
|
+
def get_exec_titles
|
87
83
|
result = []
|
88
84
|
tokens.each_index do |token_idx|
|
89
|
-
next unless tokens[token_idx].
|
85
|
+
next unless ['exec'].include?(tokens[token_idx].value)
|
86
|
+
# We have a resource declaration. Now find the title
|
90
87
|
tokens_array = []
|
91
88
|
# Check if title is an array
|
92
|
-
if tokens[token_idx
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
89
|
+
if tokens[token_idx].next_code_token.next_code_token.type == :LBRACK
|
90
|
+
# Get the start and end indices of the array of titles
|
91
|
+
array_start_idx = tokens.rindex { |r| r.type == :LBRACK }
|
92
|
+
array_end_idx = tokens.rindex { |r| r.type == :RBRACK }
|
93
|
+
|
94
|
+
# Grab everything within the array
|
95
|
+
title_array_tokens = tokens[(array_start_idx + 1)..(array_end_idx - 1)]
|
96
|
+
tokens_array.concat(title_array_tokens.reject do |token|
|
97
|
+
USELESS_CHARS.include?(token.type)
|
99
98
|
end)
|
100
|
-
result <<
|
101
|
-
tokens: tokens_array,
|
102
|
-
resource_type: tokens[array_start_idx].prev_code_token.prev_code_token
|
103
|
-
}
|
99
|
+
result << tokens_array
|
104
100
|
# Check if title is double quotes string
|
105
|
-
elsif tokens[token_idx
|
106
|
-
# Find
|
107
|
-
title_start_idx = tokens.rindex
|
108
|
-
|
109
|
-
|
110
|
-
result <<
|
111
|
-
# Title is tokens from :DQPRE to the index before :COLON
|
112
|
-
tokens: tokens[title_start_idx..(token_idx - 1)],
|
113
|
-
resource_type: tokens[title_start_idx].prev_code_token.prev_code_token
|
114
|
-
}
|
101
|
+
elsif tokens[token_idx].next_code_token.next_code_token.type == :DQPRE
|
102
|
+
# Find the start and end of the title
|
103
|
+
title_start_idx = tokens.rindex { |r| r.type == :DQPRE }
|
104
|
+
title_end_idx = tokens.rindex { |r| r.type == :DQPOST }
|
105
|
+
|
106
|
+
result << tokens[title_start_idx..title_end_idx]
|
115
107
|
# Title is in single quotes
|
116
108
|
else
|
117
|
-
|
118
|
-
|
119
|
-
result <<
|
120
|
-
tokens: tokens_array,
|
121
|
-
resource_type: tokens[token_idx - 1].prev_code_token.prev_code_token
|
122
|
-
}
|
109
|
+
tokens_array.concat([tokens[token_idx].next_code_token.next_code_token])
|
110
|
+
|
111
|
+
result << tokens_array
|
123
112
|
end
|
124
113
|
end
|
125
114
|
result
|
@@ -160,5 +160,27 @@ describe 'check_unsafe_interpolations' do
|
|
160
160
|
expect(problems).to have(1).problems
|
161
161
|
end
|
162
162
|
end
|
163
|
+
|
164
|
+
context 'case statement and an exec' do
|
165
|
+
let(:code) do
|
166
|
+
<<-PUPPET
|
167
|
+
class foo {
|
168
|
+
case bar {
|
169
|
+
baz : {
|
170
|
+
echo qux
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
exec { 'foo':
|
175
|
+
command => "echo bar",
|
176
|
+
}
|
177
|
+
}
|
178
|
+
PUPPET
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'detects zero problems' do
|
182
|
+
expect(problems).to have(0).problems
|
183
|
+
end
|
184
|
+
end
|
163
185
|
end
|
164
186
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-check_unsafe_interpolations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '4'
|
27
33
|
description: " A puppet-lint plugin to check for unsafe interpolations.\n"
|
28
34
|
email:
|
29
35
|
executables: []
|