puppet-lint-wmf_styleguide-check 1.1.2 → 1.1.3

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: '0996980289ea98e58b4da21e94d46732a5fec1cda561ddcd979ec647c91db633'
4
- data.tar.gz: d8b5d617cb4ba1f1765670171cf157b723d73428410b8f1e564d8f160f20a046
3
+ metadata.gz: d19787901dc3b130c947494d15441a83a3554456f2bb999f7612667d2c01556d
4
+ data.tar.gz: 331e919394e9c138cc432ea935d8fa7b3f632b987a27f84bae5858371a76c493
5
5
  SHA512:
6
- metadata.gz: c8056b429179de7156ecdb3ccb09bad40c9c4ae0c487a2177ca8073b204e4de935da30ac993b3c94ebf896f0140f9bee36707cf045cfeb5e3617c34142debeb2
7
- data.tar.gz: 96531a80875d9aa641a8a34ac3a541ab1ad75c0b4fb37228324c6312e2ba736749e3532de77bb6d8412ea5b3c5d973977f69f09a83d2ec10310d9cd3f028f9b4
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?
@@ -493,9 +493,40 @@ PuppetLint.new_check(:wmf_styleguide) do
493
493
  next unless in_node_def
494
494
  case token.type
495
495
  when :REGEX
496
- if !token.value.start_with?('^') || !token.value.end_with?('$')
496
+ unless token.value.start_with?('^')
497
497
  msg = {
498
- message: "wmf-style: regex node matching must match the whole string (^...$), got: #{token.value}",
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}",
499
530
  line: token.line,
500
531
  column: token.column,
501
532
  token: token,
@@ -504,7 +535,19 @@ PuppetLint.new_check(:wmf_styleguide) do
504
535
  notify :error, msg
505
536
  end
506
537
  when :LBRACE
507
- title_tokens = tokens[start + 1..(i - 1)].select(&:node_def?) if braces_level.zero?
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
508
551
  braces_level += 1
509
552
  when :RBRACE
510
553
  braces_level -= 1
@@ -549,10 +592,15 @@ PuppetLint.new_check(:wmf_styleguide) do
549
592
  end
550
593
  end
551
594
 
595
+ # rubocop:disable Metrics/AbcSize
552
596
  def fix_node_regex(problem)
553
597
  problem[:token].value.insert(0, '^') unless problem[:token].value.start_with?('^')
554
- problem[:token].value << '$' unless problem[:token].value.end_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
555
602
  end
603
+ # rubocop:enable Metrics/AbcSize
556
604
 
557
605
  def fix(problem)
558
606
  raise PuppetLint::NoFix unless problem[:problem] == 'node_regex'
@@ -88,7 +88,19 @@ define foo::fixme ($a=hiera('something')) {
88
88
  EOF
89
89
 
90
90
  node_ok = <<-EOF
91
- node /^test1.*\\.example\\.com$/ {
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,26 +118,38 @@ node 'fixme' {
106
118
  }
107
119
  EOF
108
120
 
109
- node_regex_missing_start = <<-EOF
110
- node /test1.*\\.example\\.com$/ {
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/ {
111
129
  role(spare::system)
112
130
  }
113
131
  EOF
114
132
 
115
- node_regex_missing_end = <<-EOF
116
- node /^test1.*\\.example\\.com/ {
133
+ node_regex_missing_start = <<-EOF
134
+ node /test1.*\\.eqiad\\./ {
117
135
  role(spare::system)
118
136
  }
119
137
  EOF
120
138
 
121
- node_regex_missing_both = <<-EOF
122
- node /test1.*\\.example\\.com/ {
139
+ node_regex_with_end = <<-EOF
140
+ node /^test1.*\\.eqiad\\.wmnet$/ {
123
141
  role(spare::system)
124
142
  }
125
143
  EOF
126
144
 
127
145
  node_regex_fixed = <<-EOF
128
- node /^test1.*\\.example\\.com$/ {
146
+ node /^test1.*\\.eqiad\\./ {
147
+ role(spare::system)
148
+ }
149
+ EOF
150
+
151
+ node_regex_fixed_wmf_tld = <<-EOF
152
+ node /^test1.*\\.eqiad\\./ {
129
153
  role(spare::system)
130
154
  }
131
155
  EOF
@@ -242,6 +266,21 @@ describe 'wmf_styleguide' do
242
266
  expect(problems).to have(0).problems
243
267
  end
244
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
+
245
284
  context 'node with violations' do
246
285
  let(:code) { node_ko }
247
286
  it 'should not include classes directly' do
@@ -262,24 +301,36 @@ describe 'wmf_styleguide' do
262
301
  it 'should not call hiera_hash' do
263
302
  expect(problems).to contain_error("wmf-style: node 'fixme' calls legacy hiera_hash function")
264
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
265
321
  end
266
322
 
267
323
  context 'node regex with start violation' do
268
324
  let(:code) { node_regex_missing_start }
269
325
  it 'should start the regex with ^' do
270
- expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: test1.*\\.example\\.com$')
326
+ expect(problems).to contain_error("wmf-style: node regex must match the start of the hostname with '^' got: test1.*\\.eqiad\\.")
271
327
  end
272
328
  end
329
+
273
330
  context 'node regex with end violation' do
274
- let(:code) { node_regex_missing_end }
275
- it 'should end the regex with $' do
276
- expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: ^test1.*\\.example\\.com')
277
- end
278
- end
279
- context 'node regex with start and end violations' do
280
- let(:code) { node_regex_missing_both }
281
- it 'should start the regex with ^ and end it with $' do
282
- expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: test1.*\\.example\\.com')
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$")
283
334
  end
284
335
  end
285
336
 
@@ -304,12 +355,12 @@ describe 'wmf_styleguide' do
304
355
  it { expect(manifest).to eq(node_regex_fixed) }
305
356
  end
306
357
  context 'node regex with end violation' do
307
- let(:code) { node_regex_missing_end }
358
+ let(:code) { node_regex_with_end }
308
359
  it { expect(manifest).to eq(node_regex_fixed) }
309
360
  end
310
- context 'node regex with start and end violations' do
311
- let(:code) { node_regex_missing_both }
312
- it { expect(manifest).to eq(node_regex_fixed) }
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) }
313
364
  end
314
365
  end
315
366
  end
metadata CHANGED
@@ -1,11 +1,11 @@
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.2
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
11
  date: 2023-08-11 00:00:00.000000000 Z
@@ -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,10 +163,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubygems_version: 3.2.5
167
- signing_key:
166
+ rubygems_version: 3.3.15
167
+ signing_key:
168
168
  specification_version: 4
169
169
  summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
170
170
  test_files:
171
- - spec/spec_helper.rb
172
171
  - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
172
+ - spec/spec_helper.rb