puppet-syntax 4.0.1 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +22 -0
- data/lib/puppet-syntax/hiera.rb +61 -0
- data/lib/puppet-syntax/version.rb +1 -1
- data/lib/puppet-syntax.rb +3 -1
- data/puppet-syntax.gemspec +1 -1
- data/spec/fixtures/hiera/hiera_badkey.yaml +8 -0
- data/spec/puppet-syntax/hiera_spec.rb +6 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f7f1ca6475068159902b6dbe227d6ac486336d2fc2ad1c8b00e38b71082597
|
4
|
+
data.tar.gz: 725e830cc518515bf10605391de65a324eb7caafc38c37f32f252cafe1f18ace
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a677df82c7a0a758a8184bb8158a422105be48f9552d21bec36f9c1f5f0e67380559318f3dbc6dda464ea18d9e8ed4b515ac68416220bcaf826e2816790f98cf
|
7
|
+
data.tar.gz: 6f9849ab4f2f99ab59f0dbdcff21b31e8c76e0bdc8920c8cf0edabe2d4882e07d4f29e7cdd6b8a4a32e8539b19a7a1b6b4cfa8002e666835ba92ac0358110eb2
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-03-08
|
3
|
+
# on 2024-03-08 16:09:27 UTC using RuboCop version 1.61.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -86,7 +86,7 @@ RSpec/DescribedClass:
|
|
86
86
|
# Offense count: 7
|
87
87
|
# Configuration parameters: CountAsOne.
|
88
88
|
RSpec/ExampleLength:
|
89
|
-
Max:
|
89
|
+
Max: 17
|
90
90
|
|
91
91
|
# Offense count: 4
|
92
92
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
@@ -100,7 +100,7 @@ RSpec/FilePath:
|
|
100
100
|
|
101
101
|
# Offense count: 29
|
102
102
|
RSpec/MultipleExpectations:
|
103
|
-
Max:
|
103
|
+
Max: 11
|
104
104
|
|
105
105
|
# Offense count: 30
|
106
106
|
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
@@ -244,7 +244,7 @@ Style/SymbolProc:
|
|
244
244
|
- 'lib/puppet-syntax/manifests.rb'
|
245
245
|
- 'lib/puppet-syntax/templates.rb'
|
246
246
|
|
247
|
-
# Offense count:
|
247
|
+
# Offense count: 3
|
248
248
|
# This cop supports safe autocorrection (--autocorrect).
|
249
249
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
250
250
|
# URISchemes: http, https
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [v4.1.1](https://github.com/voxpupuli/puppet-syntax/tree/v4.1.1) (2024-04-04)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v4.1.0...v4.1.1)
|
8
|
+
|
9
|
+
**Fixed bugs:**
|
10
|
+
|
11
|
+
- fix too greedy regular expression [\#171](https://github.com/voxpupuli/puppet-syntax/pull/171) ([tmu-sprd](https://github.com/tmu-sprd))
|
12
|
+
|
13
|
+
## [v4.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v4.1.0) (2024-03-12)
|
14
|
+
|
15
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v4.0.1...v4.1.0)
|
16
|
+
|
17
|
+
**Implemented enhancements:**
|
18
|
+
|
19
|
+
- Hiera: Test for wrong interpolation syntax [\#143](https://github.com/voxpupuli/puppet-syntax/pull/143) ([bastelfreak](https://github.com/bastelfreak))
|
20
|
+
|
5
21
|
## [v4.0.1](https://github.com/voxpupuli/puppet-syntax/tree/v4.0.1) (2024-03-12)
|
6
22
|
|
7
23
|
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v4.0.0...v4.0.1)
|
data/README.md
CHANGED
@@ -85,6 +85,13 @@ This reports common mistakes in key names in Hiera files, such as:
|
|
85
85
|
* Invalid camel casing, such as: `noCamelCase::warning3: true`.
|
86
86
|
* Use of hyphens, such as: `no-hyphens::warning4: true`.
|
87
87
|
|
88
|
+
|
89
|
+
* To enable a syntax check on Hiera values, set:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
PuppetSyntax.check_hiera_data = true
|
93
|
+
```
|
94
|
+
|
88
95
|
## Usage
|
89
96
|
|
90
97
|
* To enable Puppet::Syntax, include the following in your module's `Rakefile`:
|
@@ -139,6 +146,21 @@ By default, this rake task looks for all `.yaml` files in a single module under:
|
|
139
146
|
* `hieradata/**/*.yaml`
|
140
147
|
* `hiera*.yaml`
|
141
148
|
|
149
|
+
It will validate the syntax of each Hiera *key*. for values, it will check if
|
150
|
+
the interpolation function syntax is correct. Wrong:
|
151
|
+
|
152
|
+
```
|
153
|
+
foo:
|
154
|
+
"%{lookup('baz'):3306}": []
|
155
|
+
```
|
156
|
+
|
157
|
+
correct would be:
|
158
|
+
|
159
|
+
```
|
160
|
+
foo:
|
161
|
+
"%{lookup('baz')}:3306": []
|
162
|
+
```
|
163
|
+
|
142
164
|
### manifests
|
143
165
|
|
144
166
|
Checks all `.pp` files in the module for syntax errors.
|
data/lib/puppet-syntax/hiera.rb
CHANGED
@@ -20,6 +20,16 @@ module PuppetSyntax
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def check_hiera_data(_key, value)
|
24
|
+
# using filter_map to remove nil values
|
25
|
+
# there will be nil values if check_broken_function_call didn't return a string
|
26
|
+
# this is a shorthand for filter.compact
|
27
|
+
# https://blog.saeloun.com/2019/05/25/ruby-2-7-enumerable-filter-map/
|
28
|
+
keys_and_values(value).filter_map do |element|
|
29
|
+
check_broken_function_call(element)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
23
33
|
# Recurse through complex data structures. Return on first error.
|
24
34
|
def check_eyaml_data(name, val)
|
25
35
|
error = nil
|
@@ -87,6 +97,11 @@ module PuppetSyntax
|
|
87
97
|
key_msg = check_hiera_key(k)
|
88
98
|
errors << "WARNING: #{hiera_file}: Key :#{k}: #{key_msg}" if key_msg
|
89
99
|
end
|
100
|
+
if PuppetSyntax.check_hiera_data
|
101
|
+
check_hiera_data(k, v).each do |value_msg|
|
102
|
+
errors << "WARNING: #{hiera_file}: Key :#{k}: #{value_msg}"
|
103
|
+
end
|
104
|
+
end
|
90
105
|
eyaml_msg = check_eyaml_data(k, v)
|
91
106
|
errors << "WARNING: #{hiera_file}: #{eyaml_msg}" if eyaml_msg
|
92
107
|
end
|
@@ -96,5 +111,51 @@ module PuppetSyntax
|
|
96
111
|
|
97
112
|
errors
|
98
113
|
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
# you can call functions in hiera, like this:
|
118
|
+
# "%{lookup('this_is_ok')}"
|
119
|
+
# you can do this in everywhere in a hiera value
|
120
|
+
# you cannot do string concatenation within {}:
|
121
|
+
# "%{lookup('this_is_ok'):3306}"
|
122
|
+
# You can do string concatenation outside of {}:
|
123
|
+
# "%{lookup('this_is_ok')}:3306"
|
124
|
+
def check_broken_function_call(element)
|
125
|
+
'string after a function call but before `}` in the value' if element.is_a?(String) && /%{[^}]+\('[^}]*'\)[^}\s]+}/.match?(element)
|
126
|
+
end
|
127
|
+
|
128
|
+
# gets a hash or array, returns all keys + values as array
|
129
|
+
def flatten_data(data, parent_key = [])
|
130
|
+
if data.is_a?(Hash)
|
131
|
+
data.flat_map do |key, value|
|
132
|
+
current_key = parent_key + [key.to_s]
|
133
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
134
|
+
flatten_data(value, current_key)
|
135
|
+
else
|
136
|
+
[current_key.join('.'), value]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
elsif data.is_a?(Array) && !data.empty?
|
140
|
+
data.flat_map do |value|
|
141
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
142
|
+
flatten_data(value, parent_key)
|
143
|
+
else
|
144
|
+
[parent_key.join('.'), value]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
else
|
148
|
+
[parent_key.join('.')]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# gets a string, hash or array, returns all keys + values as flattened + unique array
|
153
|
+
def keys_and_values(value)
|
154
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
155
|
+
flatten_data(value).flatten.uniq
|
156
|
+
else
|
157
|
+
[value]
|
158
|
+
end
|
159
|
+
end
|
99
160
|
end
|
100
161
|
end
|
data/lib/puppet-syntax.rb
CHANGED
@@ -20,6 +20,7 @@ module PuppetSyntax
|
|
20
20
|
]
|
21
21
|
@fail_on_deprecation_notices = true
|
22
22
|
@check_hiera_keys = false
|
23
|
+
@check_hiera_data = false
|
23
24
|
|
24
25
|
class << self
|
25
26
|
attr_accessor :exclude_paths,
|
@@ -28,6 +29,7 @@ module PuppetSyntax
|
|
28
29
|
:templates_paths,
|
29
30
|
:fail_on_deprecation_notices,
|
30
31
|
:epp_only,
|
31
|
-
:check_hiera_keys
|
32
|
+
:check_hiera_keys,
|
33
|
+
:check_hiera_data
|
32
34
|
end
|
33
35
|
end
|
data/puppet-syntax.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'pry', '~> 0.14.2'
|
25
25
|
spec.add_development_dependency 'rb-readline', '~> 0.5.5'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'voxpupuli-rubocop', '~> 2.
|
27
|
+
spec.add_development_dependency 'voxpupuli-rubocop', '~> 2.6.0'
|
28
28
|
end
|
@@ -3,9 +3,17 @@ this_is_ok: 0
|
|
3
3
|
this_is_ok::too: 0
|
4
4
|
th1s_is_ok::two3: 0
|
5
5
|
:eventhis: 0
|
6
|
+
this_is_ok::concat_func: "%{lookup('foo')}%{lookup('bar')}"
|
6
7
|
|
7
8
|
typical:typo::warning1: true
|
8
9
|
::notsotypical::warning2: true
|
9
10
|
noCamelCase::warning3: true
|
10
11
|
no-hyphens::warning4: true
|
11
12
|
:picky::warning5: true
|
13
|
+
this_is::warning6:
|
14
|
+
"%{lookup('foobar'):3306}": []
|
15
|
+
this_is::warning7:
|
16
|
+
- "%{lookup('foobar'):3306}"
|
17
|
+
this_is::warning8:
|
18
|
+
foo: "%{lookup('foobar'):3306}"
|
19
|
+
this_is::warning9: "%{lookup('foo'):3306}%{lookup('bar')}"
|
@@ -24,11 +24,12 @@ describe PuppetSyntax::Hiera do
|
|
24
24
|
context 'check_hiera_keys = true' do
|
25
25
|
before do
|
26
26
|
PuppetSyntax.check_hiera_keys = true
|
27
|
+
PuppetSyntax.check_hiera_data = true
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'returns warnings for invalid keys' do
|
30
31
|
hiera_yaml = 'hiera_badkey.yaml'
|
31
|
-
examples =
|
32
|
+
examples = 9
|
32
33
|
files = fixture_hiera(hiera_yaml)
|
33
34
|
res = subject.check(files)
|
34
35
|
(1..examples).each do |n|
|
@@ -40,6 +41,10 @@ describe PuppetSyntax::Hiera do
|
|
40
41
|
expect(res[2]).to match('Key :noCamelCase::warning3: Not a valid Puppet variable name for automatic lookup')
|
41
42
|
expect(res[3]).to match('Key :no-hyphens::warning4: Not a valid Puppet variable name for automatic lookup')
|
42
43
|
expect(res[4]).to match('Key :picky::warning5: Puppet automatic lookup will not look up symbols')
|
44
|
+
expect(res[5]).to match('Key :this_is::warning6: string after a function call but before `}` in the value')
|
45
|
+
expect(res[6]).to match('Key :this_is::warning7: string after a function call but before `}` in the value')
|
46
|
+
expect(res[7]).to match('Key :this_is::warning8: string after a function call but before `}` in the value')
|
47
|
+
expect(res[8]).to match('Key :this_is::warning9: string after a function call but before `}` in the value')
|
43
48
|
end
|
44
49
|
|
45
50
|
it 'returns warnings for bad eyaml values' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 2.
|
81
|
+
version: 2.6.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
88
|
+
version: 2.6.0
|
89
89
|
description: Syntax checks for Puppet manifests and templates
|
90
90
|
email:
|
91
91
|
- voxpupuli@groups.io
|