puppet-lint-nine-check 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc35597d6a8c91070d3f0f897ad882a3e0d7f5baa26136c96f3c32de2447487
|
4
|
+
data.tar.gz: d3e419564fb15a1728a7885ea243cd61b03ced9676c49d79f9b59f6216352abb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adb7afff9bca164ff1a683528169113bd8066a4ab9b4b8272ea88a71f6ae6b13205ec653484ebb721fbc6af68932a7ae7f1129dee5e6281b6bafcecb0380bd1e
|
7
|
+
data.tar.gz: 1ce9cf998c731e36e11ed2a1c322905151df43c4a99aef80749c8617f29a3f4813486d432aab22d148da12cae5cfa1a4d0d13a28c3fdd3be990483712103bb33
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# https://github.com/deanwilson/puppet-lint-no_symbolic_file_modes-check/blob/bf06d542b222ba4748ec935346a95b628a527f00/lib/puppet-lint/plugins/no_symbolic_file_modes.rb
|
2
|
+
#
|
3
|
+
# The MIT License (MIT)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2016 Dean Wilson
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
PuppetLint.new_check(:no_symbolic_file_modes) do
|
26
|
+
def ignore_type?(type)
|
27
|
+
Set[:VARIABLE, :UNDEF].include?(type)
|
28
|
+
end
|
29
|
+
|
30
|
+
def check
|
31
|
+
resource_indexes.each do |resource|
|
32
|
+
next unless resource[:type].value == "file"
|
33
|
+
|
34
|
+
param_tokens = resource[:param_tokens].select { |pt| pt.value == "mode" }
|
35
|
+
|
36
|
+
param_tokens.each do |param_token|
|
37
|
+
value_token = param_token.next_code_token.next_code_token
|
38
|
+
|
39
|
+
break if ignore_type?(value_token.type)
|
40
|
+
break if /^[0-7]{4}$/.match?(value_token.value)
|
41
|
+
|
42
|
+
notify :warning, {
|
43
|
+
message: "mode should be a 4 digit octal value, not a symbolic mode",
|
44
|
+
line: value_token.line,
|
45
|
+
column: value_token.column,
|
46
|
+
token: value_token
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# https://github.com/deanwilson/puppet-lint-template_file_extension-check/blob/ae9f1e850293e0c204f1abd876df4be4d560cf81/lib/puppet-lint/plugins/template_file_extension.rb
|
2
|
+
#
|
3
|
+
# The MIT License (MIT)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2017 Dean Wilson
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
PuppetLint.new_check(:template_file_extension) do
|
26
|
+
def check
|
27
|
+
template_extensions = {
|
28
|
+
epp: ".epp",
|
29
|
+
template: ".erb"
|
30
|
+
}
|
31
|
+
|
32
|
+
# the types a filename may be in a `template()` call
|
33
|
+
name_types = %i[DQPOST SSTRING]
|
34
|
+
|
35
|
+
resource_indexes.each do |resource|
|
36
|
+
next unless resource[:type].value == "file"
|
37
|
+
|
38
|
+
param_tokens = resource[:param_tokens].select { |pt| pt.value == "content" }
|
39
|
+
|
40
|
+
param_tokens.each do |content_token|
|
41
|
+
value_token = content_token.next_code_token.next_code_token
|
42
|
+
|
43
|
+
if (matched = value_token.value.match(/^(template|epp)$/))
|
44
|
+
template_function = matched[1]
|
45
|
+
extension = template_extensions[template_function.to_sym]
|
46
|
+
|
47
|
+
current_token = value_token.next_token
|
48
|
+
current_token = current_token.next_token while current_token.type == :WHITESPACE
|
49
|
+
|
50
|
+
# iterate over all the code tokens until we hit the closing ')'
|
51
|
+
until current_token.type == :RPAREN || current_token.type == :LBRACE
|
52
|
+
current_token = current_token.next_code_token
|
53
|
+
|
54
|
+
if (name_types.include? current_token.type) && !current_token.value.end_with?(extension)
|
55
|
+
warning = "all #{template_function} file names should end with #{extension}"
|
56
|
+
|
57
|
+
notify :warning, {
|
58
|
+
message: warning,
|
59
|
+
line: value_token.line,
|
60
|
+
column: value_token.column,
|
61
|
+
param_token: content_token,
|
62
|
+
value_token: value_token
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "no_symbolic_file_modes" do
|
4
|
+
let(:msg) { "mode should be a 4 digit octal value, not a symbolic mode" }
|
5
|
+
|
6
|
+
context "when the manifest has no file resources" do
|
7
|
+
let(:code) do
|
8
|
+
<<-TEST_CLASS
|
9
|
+
class no_file_resource {
|
10
|
+
host { 'syslog':
|
11
|
+
ip => '10.10.10.10',
|
12
|
+
}
|
13
|
+
}
|
14
|
+
TEST_CLASS
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not detect any problems" do
|
18
|
+
expect(problems.size).to eq(0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when file has an all octal mode" do
|
23
|
+
let(:code) do
|
24
|
+
<<-TEST_CLASS
|
25
|
+
class octal_file_mode {
|
26
|
+
file { '/tmp/octal-mode':
|
27
|
+
mode => '0600',
|
28
|
+
}
|
29
|
+
}
|
30
|
+
TEST_CLASS
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not detect any problems" do
|
34
|
+
expect(problems.size).to eq(0)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when file mode is specified in a variable" do
|
39
|
+
let(:code) do
|
40
|
+
<<-TEST_CLASS
|
41
|
+
class octal_file_mode {
|
42
|
+
$mode = 'ug=rw,o=rx'
|
43
|
+
|
44
|
+
file { '/tmp/octal-mode':
|
45
|
+
mode => $mode,
|
46
|
+
}
|
47
|
+
}
|
48
|
+
TEST_CLASS
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not detect any problems" do
|
52
|
+
expect(problems.size).to eq(0)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when file has a symbolic mode" do
|
57
|
+
let(:code) do
|
58
|
+
<<-TEST_CLASS
|
59
|
+
class symbolic_file_mode {
|
60
|
+
file { '/tmp/symbolic-mode':
|
61
|
+
mode => 'ug=rw,o=rx',
|
62
|
+
}
|
63
|
+
}
|
64
|
+
TEST_CLASS
|
65
|
+
end
|
66
|
+
|
67
|
+
it "detects a single problem" do
|
68
|
+
expect(problems.size).to eq(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "creates a warning" do
|
72
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(21)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "template_file_extension" do
|
4
|
+
context "when the manifest has no file resources" do
|
5
|
+
let(:code) do
|
6
|
+
<<-TEST_CLASS
|
7
|
+
class no_file_resource {
|
8
|
+
host { 'syslog':
|
9
|
+
ip => '10.10.10.10',
|
10
|
+
}
|
11
|
+
}
|
12
|
+
TEST_CLASS
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not detect any problems" do
|
16
|
+
expect(problems.size).to eq(0)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when a non-template function is called" do
|
21
|
+
let(:code) do
|
22
|
+
<<-TEST_CLASS
|
23
|
+
class random_function {
|
24
|
+
file { '/tmp/templated':
|
25
|
+
content => random_name('mymodule/single_file.erb'),
|
26
|
+
}
|
27
|
+
}
|
28
|
+
TEST_CLASS
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not detect any problems" do
|
32
|
+
expect(problems.size).to eq(0)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the template function is called with one valid file name" do
|
37
|
+
let(:code) do
|
38
|
+
<<-TEST_CLASS
|
39
|
+
class valid_template_filename {
|
40
|
+
file { '/tmp/templated':
|
41
|
+
content => template('mymodule/single_file.erb'),
|
42
|
+
}
|
43
|
+
}
|
44
|
+
TEST_CLASS
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not detect any problems" do
|
48
|
+
expect(problems.size).to eq(0)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the epp function is called with one valid file name" do
|
53
|
+
let(:code) do
|
54
|
+
<<-TEST_CLASS
|
55
|
+
class valid_epp_template_filename {
|
56
|
+
file { '/tmp/templated':
|
57
|
+
content => epp('mymodule/single_file.epp'),
|
58
|
+
}
|
59
|
+
}
|
60
|
+
TEST_CLASS
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not detect any problems" do
|
64
|
+
expect(problems.size).to eq(0)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the epp function is called with one valid file name and parameters" do
|
69
|
+
let(:code) do
|
70
|
+
<<-TEST_CLASS
|
71
|
+
class valid_epp_template_filename {
|
72
|
+
file { '/tmp/templated':
|
73
|
+
content => epp('mymodule/single_file.epp', {'key' => 'val'}),
|
74
|
+
}
|
75
|
+
}
|
76
|
+
TEST_CLASS
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not detect any problems" do
|
80
|
+
expect(problems.size).to eq(0)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when a space it present between the template function and opening paren" do
|
85
|
+
let(:code) do
|
86
|
+
<<-TEST_CLASS
|
87
|
+
class space_between_template_and_opening_paren {
|
88
|
+
file { '/tmp/templated':
|
89
|
+
content => template ('mymodule/a_file.erb'),
|
90
|
+
}
|
91
|
+
}
|
92
|
+
TEST_CLASS
|
93
|
+
end
|
94
|
+
|
95
|
+
it "does not detect any problems" do
|
96
|
+
expect(problems.size).to eq(0)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when the template function is called with a single invalid file name" do
|
101
|
+
let(:template_msg) { "all template file names should end with .erb" }
|
102
|
+
let(:code) do
|
103
|
+
<<-TEST_CLASS
|
104
|
+
class multi_templated_file {
|
105
|
+
file { '/tmp/templated':
|
106
|
+
content => template('mymodule/first_file.erb', 'mymodule/second_file.conf'),
|
107
|
+
}
|
108
|
+
}
|
109
|
+
TEST_CLASS
|
110
|
+
end
|
111
|
+
|
112
|
+
it "detects a single problem" do
|
113
|
+
expect(problems.size).to eq(1)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "creates a warning" do
|
117
|
+
expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when the epp function is called with a single invalid file name" do
|
122
|
+
let(:epp_msg) { "all epp file names should end with .epp" }
|
123
|
+
|
124
|
+
let(:code) do
|
125
|
+
<<-TEST_CLASS
|
126
|
+
class epp_multi_templated_file {
|
127
|
+
file { '/tmp/templated':
|
128
|
+
content => epp('mymodule/first_file', {'key' => 'val'}),
|
129
|
+
}
|
130
|
+
}
|
131
|
+
TEST_CLASS
|
132
|
+
end
|
133
|
+
|
134
|
+
it "detects a single problem" do
|
135
|
+
expect(problems.size).to eq(1)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "creates a warning" do
|
139
|
+
expect(problems).to contain_warning(epp_msg).on_line(3).in_column(24)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when there is a space between the template function and opening paren, and no extension is provided" do
|
144
|
+
let(:template_msg) { "all template file names should end with .erb" }
|
145
|
+
|
146
|
+
let(:code) do
|
147
|
+
<<-TEST_CLASS
|
148
|
+
class space_between_template_and_opening_paren {
|
149
|
+
file { '/tmp/templated':
|
150
|
+
content => template ('mymodule/a_file'),
|
151
|
+
}
|
152
|
+
}
|
153
|
+
TEST_CLASS
|
154
|
+
end
|
155
|
+
|
156
|
+
it "detects a single problem" do
|
157
|
+
expect(problems.size).to eq(1)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "creates a warning" do
|
161
|
+
expect(problems).to contain_warning(template_msg).on_line(3).in_column(24)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
## https://github.com/deanwilson/puppet-lint-template_file_extension-check/issues/48
|
166
|
+
context "when the paramater type is DQPOST not SSTRING and no extension is provided (issue #48)" do
|
167
|
+
let(:template_msg) { "all template file names should end with .erb" }
|
168
|
+
|
169
|
+
let(:code) do
|
170
|
+
<<-TEST_CLASS
|
171
|
+
class space_between_template_and_opening_paren {
|
172
|
+
file { "/etc/${package_name}.conf":
|
173
|
+
ensure => file,
|
174
|
+
content => template("allknowingdns/${package_name}.conf"),
|
175
|
+
}
|
176
|
+
}
|
177
|
+
TEST_CLASS
|
178
|
+
end
|
179
|
+
|
180
|
+
it "detects a single problem" do
|
181
|
+
expect(problems.size).to eq(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "creates a warning" do
|
185
|
+
expect(problems).to contain_warning(template_msg).on_line(4).in_column(24)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-nine-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nine Internet Solutions AG
|
@@ -108,8 +108,22 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: standardrb
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: |2
|
112
|
-
A pupet-lint to check you are not using Nine legacy facts like `$::nine_location`
|
126
|
+
A pupet-lint to check to ensure you are not using Nine legacy facts like `$::nine_location`
|
113
127
|
or `$facts['nine_location']`. You should use the new structured facts like
|
114
128
|
`$facts['nine_metadata']['location']` instead.
|
115
129
|
email:
|
@@ -123,11 +137,15 @@ files:
|
|
123
137
|
- lib/puppet-lint/plugins/concatenated_template_files.rb
|
124
138
|
- lib/puppet-lint/plugins/explicit_hiera_class_param_lookup.rb
|
125
139
|
- lib/puppet-lint/plugins/nine_legacy_facts.rb
|
140
|
+
- lib/puppet-lint/plugins/no_symbolic_file_modes.rb
|
141
|
+
- lib/puppet-lint/plugins/template_file_extension.rb
|
126
142
|
- lib/puppet-lint/plugins/trailing_newline.rb
|
127
143
|
- lib/puppet-lint/plugins/world_writable_files.rb
|
128
144
|
- spec/puppet-lint/plugins/concatenated_template_files_spec.rb
|
129
145
|
- spec/puppet-lint/plugins/explicit_hiera_class_param_lookup_spec.rb
|
130
146
|
- spec/puppet-lint/plugins/nine_legacy_facts_spec.rb
|
147
|
+
- spec/puppet-lint/plugins/no_symbolic_file_modes_spec.rb
|
148
|
+
- spec/puppet-lint/plugins/template_file_extension_spec.rb
|
131
149
|
- spec/puppet-lint/plugins/trailing_newline_spec.rb
|
132
150
|
- spec/puppet-lint/plugins/world_writable_files_spec.rb
|
133
151
|
- spec/spec_helper.rb
|