puppet-lint-wmf_styleguide-check 1.1.0 → 1.1.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: d19787901dc3b130c947494d15441a83a3554456f2bb999f7612667d2c01556d
|
4
|
+
data.tar.gz: 331e919394e9c138cc432ea935d8fa7b3f632b987a27f84bae5858371a76c493
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed879dd47323e5098ba8f8ea7301ff917ffe249209df05fbe1d95194a3409cdcf8c3218fb2473c47dffde5aa46fa663e16bfc5e71187421f3cbceb0a2417ec11
|
7
|
+
data.tar.gz: f6552ff1c0da1f1cdad84f76a3316d78674eab5490b0a5c6a16ec734125769c90a7372b7b452cb953af207f11b2406ab510b3544dafdd4fbc5f62bd4f0d22ddb
|
@@ -190,7 +190,7 @@ class PuppetLint
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def node_def?
|
193
|
-
[:SSTRING, :STRING, :NAME, :REGEX].include?(@type)
|
193
|
+
[:SSTRING, :STRING, :NAME, :REGEX, :DEFAULT].include?(@type)
|
194
194
|
end
|
195
195
|
|
196
196
|
def role_keyword?
|
@@ -280,7 +280,6 @@ end
|
|
280
280
|
|
281
281
|
def lookup_not_in_params(klass)
|
282
282
|
# Checks if a lookup call is not in a parameter declaration. Used to check profiles
|
283
|
-
|
284
283
|
# Any lookup call that is not inside a parameter declaration is a violation
|
285
284
|
tokens = klass.lookup_calls.reject do |token|
|
286
285
|
maybe_param = token.prev_code_token.prev_code_token
|
@@ -493,8 +492,62 @@ PuppetLint.new_check(:wmf_styleguide) do
|
|
493
492
|
# If we're not within a node definition, skip this token
|
494
493
|
next unless in_node_def
|
495
494
|
case token.type
|
495
|
+
when :REGEX
|
496
|
+
unless token.value.start_with?('^')
|
497
|
+
msg = {
|
498
|
+
message: "wmf-style: node regex must match the start of the hostname with '^' got: #{token.value}",
|
499
|
+
line: token.line,
|
500
|
+
column: token.column,
|
501
|
+
token: token,
|
502
|
+
problem: 'node_regex'
|
503
|
+
}
|
504
|
+
notify :error, msg
|
505
|
+
end
|
506
|
+
if token.value.end_with?('$')
|
507
|
+
msg = {
|
508
|
+
message: "wmf-style: node regex must not match the end of the hostname with '$' got: #{token.value}",
|
509
|
+
line: token.line,
|
510
|
+
column: token.column,
|
511
|
+
token: token,
|
512
|
+
problem: 'node_regex'
|
513
|
+
}
|
514
|
+
notify :error, msg
|
515
|
+
end
|
516
|
+
['.wmnet', '.org'].each do |tld|
|
517
|
+
next unless token.value.index(tld)
|
518
|
+
msg = {
|
519
|
+
message: "wmf-style: node regex must not contain the '#{tld}' tld got: #{token.value}",
|
520
|
+
line: token.line,
|
521
|
+
column: token.column,
|
522
|
+
token: token,
|
523
|
+
problem: 'node_regex'
|
524
|
+
}
|
525
|
+
notify :error, msg
|
526
|
+
end
|
527
|
+
if !token.value.match(/\\?\.wikimedia\\?\.org/) && !token.value.end_with?('\.')
|
528
|
+
msg = {
|
529
|
+
message: "wmf-style: datacenter node regex must match subdomain end with '\.': #{token.value}",
|
530
|
+
line: token.line,
|
531
|
+
column: token.column,
|
532
|
+
token: token,
|
533
|
+
problem: 'node_regex'
|
534
|
+
}
|
535
|
+
notify :error, msg
|
536
|
+
end
|
496
537
|
when :LBRACE
|
497
|
-
|
538
|
+
if braces_level.zero?
|
539
|
+
title_tokens = tokens[start + 1..(i - 1)].select(&:node_def?)
|
540
|
+
unless title_tokens[0].type == :REGEX || title_tokens[0].type == :DEFAULT
|
541
|
+
msg = {
|
542
|
+
message: "wmf-style: node definition must use a regex, got: #{title_tokens[0].value}",
|
543
|
+
line: token.line,
|
544
|
+
column: token.column,
|
545
|
+
token: token,
|
546
|
+
problem: 'node_regex'
|
547
|
+
}
|
548
|
+
notify :error, msg
|
549
|
+
end
|
550
|
+
end
|
498
551
|
braces_level += 1
|
499
552
|
when :RBRACE
|
500
553
|
braces_level -= 1
|
@@ -538,4 +591,20 @@ PuppetLint.new_check(:wmf_styleguide) do
|
|
538
591
|
check_node node
|
539
592
|
end
|
540
593
|
end
|
594
|
+
|
595
|
+
# rubocop:disable Metrics/AbcSize
|
596
|
+
def fix_node_regex(problem)
|
597
|
+
problem[:token].value.insert(0, '^') unless problem[:token].value.start_with?('^')
|
598
|
+
problem[:token].value.chop! if problem[:token].value.end_with?('$')
|
599
|
+
['wmnet', 'org'].each do |tld|
|
600
|
+
problem[:token].value.slice!(/#{tld}/) if problem[:token].value =~ /\\?\.#{tld}/
|
601
|
+
end
|
602
|
+
end
|
603
|
+
# rubocop:enable Metrics/AbcSize
|
604
|
+
|
605
|
+
def fix(problem)
|
606
|
+
raise PuppetLint::NoFix unless problem[:problem] == 'node_regex'
|
607
|
+
method = "fix_#{problem[:problem]}"
|
608
|
+
send(method, problem) if respond_to? method
|
609
|
+
end
|
541
610
|
end
|
@@ -88,7 +88,19 @@ define foo::fixme ($a=hiera('something')) {
|
|
88
88
|
EOF
|
89
89
|
|
90
90
|
node_ok = <<-EOF
|
91
|
-
node /^test1
|
91
|
+
node /^test1.*\\.eqiad\\./ {
|
92
|
+
role(spare::system)
|
93
|
+
}
|
94
|
+
EOF
|
95
|
+
|
96
|
+
node_ok_wikimedia = <<-EOF
|
97
|
+
node /^test1.*\\.wikimedia\\./ {
|
98
|
+
role(spare::system)
|
99
|
+
}
|
100
|
+
EOF
|
101
|
+
|
102
|
+
node_default = <<-EOF
|
103
|
+
node default {
|
92
104
|
role(spare::system)
|
93
105
|
}
|
94
106
|
EOF
|
@@ -106,6 +118,42 @@ node 'fixme' {
|
|
106
118
|
}
|
107
119
|
EOF
|
108
120
|
|
121
|
+
node_regex_with_wmf_tld = <<-EOF
|
122
|
+
node /^test1.*\\.eqiad\\.wmnet/ {
|
123
|
+
role(spare::system)
|
124
|
+
}
|
125
|
+
EOF
|
126
|
+
|
127
|
+
node_regex_with_org_tld = <<-EOF
|
128
|
+
node /^test1.*\\.wikimedia\\.org/ {
|
129
|
+
role(spare::system)
|
130
|
+
}
|
131
|
+
EOF
|
132
|
+
|
133
|
+
node_regex_missing_start = <<-EOF
|
134
|
+
node /test1.*\\.eqiad\\./ {
|
135
|
+
role(spare::system)
|
136
|
+
}
|
137
|
+
EOF
|
138
|
+
|
139
|
+
node_regex_with_end = <<-EOF
|
140
|
+
node /^test1.*\\.eqiad\\.wmnet$/ {
|
141
|
+
role(spare::system)
|
142
|
+
}
|
143
|
+
EOF
|
144
|
+
|
145
|
+
node_regex_fixed = <<-EOF
|
146
|
+
node /^test1.*\\.eqiad\\./ {
|
147
|
+
role(spare::system)
|
148
|
+
}
|
149
|
+
EOF
|
150
|
+
|
151
|
+
node_regex_fixed_wmf_tld = <<-EOF
|
152
|
+
node /^test1.*\\.eqiad\\./ {
|
153
|
+
role(spare::system)
|
154
|
+
}
|
155
|
+
EOF
|
156
|
+
|
109
157
|
deprecation_ko = <<-EOF
|
110
158
|
define test() {
|
111
159
|
base::service_unit{ 'test2': }
|
@@ -218,6 +266,21 @@ describe 'wmf_styleguide' do
|
|
218
266
|
expect(problems).to have(0).problems
|
219
267
|
end
|
220
268
|
end
|
269
|
+
|
270
|
+
context 'node wikimedia.org with no errors' do
|
271
|
+
let(:code) { node_ok_wikimedia }
|
272
|
+
it 'should not detect any problems' do
|
273
|
+
expect(problems).to have(0).problems
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'node default with no errors' do
|
278
|
+
let(:code) { node_default }
|
279
|
+
it 'should not detect any problems' do
|
280
|
+
expect(problems).to have(0).problems
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
221
284
|
context 'node with violations' do
|
222
285
|
let(:code) { node_ko }
|
223
286
|
it 'should not include classes directly' do
|
@@ -238,6 +301,37 @@ describe 'wmf_styleguide' do
|
|
238
301
|
it 'should not call hiera_hash' do
|
239
302
|
expect(problems).to contain_error("wmf-style: node 'fixme' calls legacy hiera_hash function")
|
240
303
|
end
|
304
|
+
it 'should use a regex' do
|
305
|
+
expect(problems).to contain_error('wmf-style: node definition must use a regex, got: fixme')
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'node regex with wmnet tld violation' do
|
310
|
+
let(:code) { node_regex_with_wmf_tld }
|
311
|
+
it 'should not contain the wmnet tld' do
|
312
|
+
expect(problems).to contain_error("wmf-style: node regex must not contain the '.wmnet' tld got: ^test1.*\\.eqiad\\.wmnet")
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context 'node regex with org tld violation' do
|
317
|
+
let(:code) { node_regex_with_org_tld }
|
318
|
+
it 'should not contain the wmnet tld' do
|
319
|
+
expect(problems).to contain_error("wmf-style: node regex must not contain the '.org' tld got: ^test1.*\\.wikimedia\\.org")
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'node regex with start violation' do
|
324
|
+
let(:code) { node_regex_missing_start }
|
325
|
+
it 'should start the regex with ^' do
|
326
|
+
expect(problems).to contain_error("wmf-style: node regex must match the start of the hostname with '^' got: test1.*\\.eqiad\\.")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'node regex with end violation' do
|
331
|
+
let(:code) { node_regex_with_end }
|
332
|
+
it 'should not end the regex with $' do
|
333
|
+
expect(problems).to contain_error("wmf-style: node regex must not match the end of the hostname with '$' got: ^test1.*\\.eqiad\\.wmnet$")
|
334
|
+
end
|
241
335
|
end
|
242
336
|
|
243
337
|
context 'defined type with deprecations' do
|
@@ -246,4 +340,27 @@ describe 'wmf_styleguide' do
|
|
246
340
|
expect(problems).to contain_error("wmf-style: 'test' should not include the deprecated define 'base::service_unit'")
|
247
341
|
end
|
248
342
|
end
|
343
|
+
|
344
|
+
context 'with fix enabled' do
|
345
|
+
before do
|
346
|
+
PuppetLint.configuration.fix = true
|
347
|
+
end
|
348
|
+
|
349
|
+
after do
|
350
|
+
PuppetLint.configuration.fix = false
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'node regex with start violation' do
|
354
|
+
let(:code) { node_regex_missing_start }
|
355
|
+
it { expect(manifest).to eq(node_regex_fixed) }
|
356
|
+
end
|
357
|
+
context 'node regex with end violation' do
|
358
|
+
let(:code) { node_regex_with_end }
|
359
|
+
it { expect(manifest).to eq(node_regex_fixed) }
|
360
|
+
end
|
361
|
+
context 'node regex with tld violation' do
|
362
|
+
let(:code) { node_regex_with_wmf_tld }
|
363
|
+
it { expect(manifest).to eq(node_regex_fixed_wmf_tld) }
|
364
|
+
end
|
365
|
+
end
|
249
366
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-wmf_styleguide-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Lavagetto
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -148,7 +148,7 @@ homepage: https://github.com/lavagetto/puppet-lint-wmf_styleguide-check
|
|
148
148
|
licenses:
|
149
149
|
- GPL-3.0
|
150
150
|
metadata: {}
|
151
|
-
post_install_message:
|
151
|
+
post_install_message:
|
152
152
|
rdoc_options: []
|
153
153
|
require_paths:
|
154
154
|
- lib
|
@@ -163,9 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
|
167
|
-
|
168
|
-
signing_key:
|
166
|
+
rubygems_version: 3.3.15
|
167
|
+
signing_key:
|
169
168
|
specification_version: 4
|
170
169
|
summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
|
171
170
|
test_files:
|