puppet-lint-wmf_styleguide-check 1.1.2 → 1.1.4

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: 54c6fe22c9d84651ff87c3731d412676e09b531e395ce3124dac997550db5b7a
4
+ data.tar.gz: 47143edec121e62799273e771c77ae1fe82711708da154363f311f6427f4348a
5
5
  SHA512:
6
- metadata.gz: c8056b429179de7156ecdb3ccb09bad40c9c4ae0c487a2177ca8073b204e4de935da30ac993b3c94ebf896f0140f9bee36707cf045cfeb5e3617c34142debeb2
7
- data.tar.gz: 96531a80875d9aa641a8a34ac3a541ab1ad75c0b4fb37228324c6312e2ba736749e3532de77bb6d8412ea5b3c5d973977f69f09a83d2ec10310d9cd3f028f9b4
6
+ metadata.gz: e9c1db9492965bf77d8705ab9b2220a47cae1d66cf6a34981fca517f2fe80937d63da80844f463faac22245729036ba0a7dc92a5b8b6984484a216701d23d863
7
+ data.tar.gz: 0cfad3cc8ce589560568ab5ec796dc8b35010e11482e6f2540ce8d2af08844d037be3f0c180dbe2d19b8bf23c8a5195abf96d3194c71747006512287112ac4bf
@@ -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?
@@ -218,8 +218,6 @@ def check_role(klass)
218
218
  lookup klass
219
219
  # A role should only include profiles
220
220
  include_not_profile klass
221
- # A call, and only one, to system::role will be done
222
- check_system_role klass
223
221
  # No defines should be present in a role
224
222
  check_no_defines klass
225
223
  end
@@ -395,17 +393,6 @@ def check_no_system_role(klass)
395
393
  end
396
394
  end
397
395
 
398
- def check_system_role(klass)
399
- # Check that a role does indeed declare system::role
400
- return if klass.resource?('system::role').length == 1
401
- msg = {
402
- message: "wmf-style: role '#{klass.name}' should declare system::role once",
403
- line: 1,
404
- column: 1
405
- }
406
- notify :error, msg
407
- end
408
-
409
396
  def check_no_defines(klass)
410
397
  # In a role, check if there is any define apart from one system::role call
411
398
  return if klass.declared_resources == klass.resource?('system::role')
@@ -493,9 +480,40 @@ PuppetLint.new_check(:wmf_styleguide) do
493
480
  next unless in_node_def
494
481
  case token.type
495
482
  when :REGEX
496
- if !token.value.start_with?('^') || !token.value.end_with?('$')
483
+ unless token.value.start_with?('^')
484
+ msg = {
485
+ message: "wmf-style: node regex must match the start of the hostname with '^' got: #{token.value}",
486
+ line: token.line,
487
+ column: token.column,
488
+ token: token,
489
+ problem: 'node_regex'
490
+ }
491
+ notify :error, msg
492
+ end
493
+ if token.value.end_with?('$')
494
+ msg = {
495
+ message: "wmf-style: node regex must not match the end of the hostname with '$' got: #{token.value}",
496
+ line: token.line,
497
+ column: token.column,
498
+ token: token,
499
+ problem: 'node_regex'
500
+ }
501
+ notify :error, msg
502
+ end
503
+ ['.wmnet', '.org'].each do |tld|
504
+ next unless token.value.index(tld)
497
505
  msg = {
498
- message: "wmf-style: regex node matching must match the whole string (^...$), got: #{token.value}",
506
+ message: "wmf-style: node regex must not contain the '#{tld}' tld got: #{token.value}",
507
+ line: token.line,
508
+ column: token.column,
509
+ token: token,
510
+ problem: 'node_regex'
511
+ }
512
+ notify :error, msg
513
+ end
514
+ if !token.value.match(/\\?\.wikimedia\\?\.org/) && !token.value.end_with?('\.')
515
+ msg = {
516
+ message: "wmf-style: datacenter node regex must match subdomain end with '\.': #{token.value}",
499
517
  line: token.line,
500
518
  column: token.column,
501
519
  token: token,
@@ -504,7 +522,19 @@ PuppetLint.new_check(:wmf_styleguide) do
504
522
  notify :error, msg
505
523
  end
506
524
  when :LBRACE
507
- title_tokens = tokens[start + 1..(i - 1)].select(&:node_def?) if braces_level.zero?
525
+ if braces_level.zero?
526
+ title_tokens = tokens[start + 1..(i - 1)].select(&:node_def?)
527
+ unless title_tokens[0].type == :REGEX || title_tokens[0].type == :DEFAULT
528
+ msg = {
529
+ message: "wmf-style: node definition must use a regex, got: #{title_tokens[0].value}",
530
+ line: token.line,
531
+ column: token.column,
532
+ token: token,
533
+ problem: 'node_regex'
534
+ }
535
+ notify :error, msg
536
+ end
537
+ end
508
538
  braces_level += 1
509
539
  when :RBRACE
510
540
  braces_level -= 1
@@ -549,10 +579,15 @@ PuppetLint.new_check(:wmf_styleguide) do
549
579
  end
550
580
  end
551
581
 
582
+ # rubocop:disable Metrics/AbcSize
552
583
  def fix_node_regex(problem)
553
584
  problem[:token].value.insert(0, '^') unless problem[:token].value.start_with?('^')
554
- problem[:token].value << '$' unless problem[:token].value.end_with?('$')
585
+ problem[:token].value.chop! if problem[:token].value.end_with?('$')
586
+ ['wmnet', 'org'].each do |tld|
587
+ problem[:token].value.slice!(/#{tld}/) if problem[:token].value =~ /\\?\.#{tld}/
588
+ end
555
589
  end
590
+ # rubocop:enable Metrics/AbcSize
556
591
 
557
592
  def fix(problem)
558
593
  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,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.2
4
+ version: 1.1.4
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: 2023-08-11 00:00:00.000000000 Z
11
+ date: 2024-01-05 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,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.4.20
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