puppet-syntax 4.0.0 → 4.1.0
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 +6 -6
- data/CHANGELOG.md +22 -0
- data/README.md +24 -2
- data/lib/puppet-syntax/hiera.rb +61 -0
- data/lib/puppet-syntax/manifests.rb +1 -1
- data/lib/puppet-syntax/tasks/puppet-syntax.rb +2 -1
- 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 +6 -0
- data/spec/puppet-syntax/hiera_spec.rb +5 -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: 45c8f3b9275ea2f9c7cccb72c2b930a15079ff0618ee55d62d8b3d393ec3f8a1
|
4
|
+
data.tar.gz: 11d6e05a07d6932b9180a9e09eb1e5c7cf47b209c7c935bd4d5635e51ce11bba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e65a0f0e244ee179926e7e9b3904a5f0c77b87b6789a24f98efa18e78a8345312b434c5fbd051c92b9332572b19346a0bddad3623c341b6d9479ec6f55e094
|
7
|
+
data.tar.gz: 2bfd3fae9730595def3f1892a753279a7a081ab9ba4f09f8dafc1c798e7aaf67c469886c1fca22a994274d02343a9d838d90a02c56f16dd0c4b65099c28a9404
|
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-
|
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
|
@@ -31,6 +31,7 @@ Lint/SuppressedException:
|
|
31
31
|
|
32
32
|
# Offense count: 1
|
33
33
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
34
|
+
# Configuration parameters: AutoCorrect.
|
34
35
|
Lint/UselessAssignment:
|
35
36
|
Exclude:
|
36
37
|
- 'lib/puppet-syntax/templates.rb'
|
@@ -73,7 +74,7 @@ RSpec/DescribeClass:
|
|
73
74
|
|
74
75
|
# Offense count: 19
|
75
76
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
76
|
-
# Configuration parameters: SkipBlocks, EnforcedStyle.
|
77
|
+
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
|
77
78
|
# SupportedStyles: described_class, explicit
|
78
79
|
RSpec/DescribedClass:
|
79
80
|
Exclude:
|
@@ -85,7 +86,7 @@ RSpec/DescribedClass:
|
|
85
86
|
# Offense count: 7
|
86
87
|
# Configuration parameters: CountAsOne.
|
87
88
|
RSpec/ExampleLength:
|
88
|
-
Max:
|
89
|
+
Max: 16
|
89
90
|
|
90
91
|
# Offense count: 4
|
91
92
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
@@ -99,7 +100,7 @@ RSpec/FilePath:
|
|
99
100
|
|
100
101
|
# Offense count: 29
|
101
102
|
RSpec/MultipleExpectations:
|
102
|
-
Max:
|
103
|
+
Max: 10
|
103
104
|
|
104
105
|
# Offense count: 30
|
105
106
|
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
@@ -139,13 +140,12 @@ Rake/Desc:
|
|
139
140
|
Exclude:
|
140
141
|
- 'Rakefile'
|
141
142
|
|
142
|
-
# Offense count:
|
143
|
+
# Offense count: 1
|
143
144
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
144
145
|
# Configuration parameters: EnforcedStyle.
|
145
146
|
# SupportedStyles: always, conditionals
|
146
147
|
Style/AndOr:
|
147
148
|
Exclude:
|
148
|
-
- 'lib/puppet-syntax/manifests.rb'
|
149
149
|
- 'lib/puppet-syntax/templates.rb'
|
150
150
|
|
151
151
|
# Offense count: 1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [v4.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v4.1.0) (2024-03-12)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v4.0.1...v4.1.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- Hiera: Test for wrong interpolation syntax [\#143](https://github.com/voxpupuli/puppet-syntax/pull/143) ([bastelfreak](https://github.com/bastelfreak))
|
12
|
+
|
13
|
+
## [v4.0.1](https://github.com/voxpupuli/puppet-syntax/tree/v4.0.1) (2024-03-12)
|
14
|
+
|
15
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v4.0.0...v4.0.1)
|
16
|
+
|
17
|
+
**Fixed bugs:**
|
18
|
+
|
19
|
+
- Raise warning if hiera check is called but disabled [\#165](https://github.com/voxpupuli/puppet-syntax/pull/165) ([bastelfreak](https://github.com/bastelfreak))
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- Drop Puppet 5.4 check [\#166](https://github.com/voxpupuli/puppet-syntax/pull/166) ([bastelfreak](https://github.com/bastelfreak))
|
24
|
+
- README.md: Update required Puppet/Ruby versions [\#164](https://github.com/voxpupuli/puppet-syntax/pull/164) ([bastelfreak](https://github.com/bastelfreak))
|
25
|
+
- Update voxpupuli-rubocop requirement from ~\> 2.4.0 to ~\> 2.5.0 [\#163](https://github.com/voxpupuli/puppet-syntax/pull/163) ([dependabot[bot]](https://github.com/apps/dependabot))
|
26
|
+
|
5
27
|
## [v4.0.0](https://github.com/voxpupuli/puppet-syntax/tree/v4.0.0) (2024-02-07)
|
6
28
|
|
7
29
|
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.3.0...v4.0.0)
|
data/README.md
CHANGED
@@ -15,8 +15,8 @@ Hiera YAML.
|
|
15
15
|
|
16
16
|
Puppet::Syntax is supported with:
|
17
17
|
|
18
|
-
- Puppet >=
|
19
|
-
- Ruby >= 2.
|
18
|
+
- Puppet >= 7.0
|
19
|
+
- Ruby >= 2.7
|
20
20
|
|
21
21
|
For the specific versions that we test against, see the [GitHub Actions workflow](.github/workflows/test.yml).
|
22
22
|
|
@@ -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) && /%{.+\('.*'\).+}/.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
|
@@ -61,7 +61,7 @@ module PuppetSyntax
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def validate_manifest(file)
|
64
|
-
Puppet[:tasks] = true if
|
64
|
+
Puppet[:tasks] = true if %r{.*plans/.*\.pp$}.match?(file)
|
65
65
|
Puppet::Face[:parser, :current].validate(file)
|
66
66
|
end
|
67
67
|
end
|
@@ -26,7 +26,7 @@ module PuppetSyntax
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def initialize(*_args)
|
29
|
-
desc 'Syntax check Puppet manifests and
|
29
|
+
desc 'Syntax check for Puppet manifests, templates and Hiera'
|
30
30
|
task syntax: [
|
31
31
|
'syntax:manifests',
|
32
32
|
'syntax:templates',
|
@@ -69,6 +69,7 @@ module PuppetSyntax
|
|
69
69
|
namespace :hiera do
|
70
70
|
task :yaml do |t|
|
71
71
|
warn "---> #{t.name}"
|
72
|
+
warn "#{t.name} was called, but PuppetSyntax.check_hiera_keys is false. hiera syntax won't be checked" unless PuppetSyntax.check_hiera_keys
|
72
73
|
c = PuppetSyntax::Hiera.new
|
73
74
|
errors = c.check(filelist_hiera_yaml)
|
74
75
|
$stdout.puts "#{errors.join("\n")}\n" unless errors.empty?
|
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.5.0'
|
28
28
|
end
|
@@ -9,3 +9,9 @@ typical:typo::warning1: true
|
|
9
9
|
noCamelCase::warning3: true
|
10
10
|
no-hyphens::warning4: true
|
11
11
|
:picky::warning5: true
|
12
|
+
this_is::warning6:
|
13
|
+
"%{lookup('foobar'):3306}": []
|
14
|
+
this_is::warning7:
|
15
|
+
- "%{lookup('foobar'):3306}"
|
16
|
+
this_is::warning8:
|
17
|
+
foo: "%{lookup('foobar'):3306}"
|
@@ -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 = 8
|
32
33
|
files = fixture_hiera(hiera_yaml)
|
33
34
|
res = subject.check(files)
|
34
35
|
(1..examples).each do |n|
|
@@ -40,6 +41,9 @@ 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')
|
43
47
|
end
|
44
48
|
|
45
49
|
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.0
|
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-03-12 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.5.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.5.0
|
89
89
|
description: Syntax checks for Puppet manifests and templates
|
90
90
|
email:
|
91
91
|
- voxpupuli@groups.io
|