puppet-lint-hiera 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca0a683393755155dc9b77047a86910ae4e249731bafcf4373e32cb34078cec9
4
+ data.tar.gz: cdd44ed624b0d996e5ce045be413fd5ca1e94511b8ff8fdcd8d26fef60e56644
5
+ SHA512:
6
+ metadata.gz: 9609186ce6b65883b2912a8e20e2c7fc7ef65fe9b7c882d3d0977acda1767c0fa51619315bb67222ccb72ed4526b23ab5a2e93f88c68e15af16c914804ded34b
7
+ data.tar.gz: ffb90799218ec423b58cc842219197db5510182e352b92c02f99e90959dae0de5be685753fc34e90d0d1c30f81a885fc9418bfe786857fde244e07b2be1ea62a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dean Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # puppet-lint hiera functions check
2
+
3
+ ## Installation
4
+ To add the provided lint checks into a module utilizing the PDK:
5
+
6
+ 1. Add the following to the `.sync.yml` in the root of your module
7
+ ``` yaml
8
+ ---
9
+ Gemfile:
10
+ optional:
11
+ ':development':
12
+ - gem: 'puppet-lint-hiera'
13
+ git: 'git@github.com:garrettrowell/puppet-lint-hiera.git'
14
+ ```
15
+ 2. Run `pdk update` from the root of the module
16
+ 3. `pdk validate` will now also use the lint checks provided by this plugin
17
+
18
+ ## Usage
19
+ This plugin provides two new checks to `puppet-lint`
20
+
21
+ ### **no_hiera**
22
+ `--fix` support: No
23
+
24
+ This check raises an error if the `hiera()` function is used.
25
+ ```
26
+ error: hiera() function call. Use lookup() instead.
27
+ ```
28
+
29
+ ### **lookup**
30
+ `--fix` support: No
31
+
32
+ This check raises an error if the `lookup()` function is used outside of profile parameters.
33
+ ```
34
+ error: lookup() function call found in profile class. Only use in profile params.
35
+ error: lookup() function call found in class params.
36
+ error: lookup() function call found in class.
37
+ ```
@@ -0,0 +1,45 @@
1
+ PuppetLint.new_check(:lookup) do
2
+ def check
3
+ functions = ['lookup']
4
+
5
+ lookups_in_parameters = Array.new
6
+ parent_class = String.new
7
+ class_indexes.each do |class_idx|
8
+ parent_class = class_idx[:name_token]
9
+ # return early if no params
10
+ next if class_idx[:param_tokens].nil?
11
+
12
+ # iterate over each parameter token
13
+ class_idx[:param_tokens].each do |p_token|
14
+ lookups_in_parameters << p_token if ((p_token.type == :NAME or p_token.type == :FUNCTION_NAME) and functions.include? p_token.value)
15
+ end
16
+ end
17
+
18
+ tokens.select { |t| (t.type == :NAME or t.type == :FUNCTION_NAME) and functions.include? t.value }.each do |function_token|
19
+ parent_class_name = parent_class.value
20
+ is_profile = parent_class_name.match(/^profile::.*/)
21
+ in_params = lookups_in_parameters.include? function_token
22
+ next unless function_token.next_code_token.type == :LPAREN
23
+ next if in_params && is_profile
24
+
25
+ key_token = function_token.next_code_token.next_code_token
26
+ lookup_key_token = function_token.prev_code_token.prev_code_token
27
+
28
+ error_message = "#{function_token.value}() function call found in"
29
+ if in_params && !is_profile
30
+ error_message = error_message + " class params."
31
+ elsif is_profile && !in_params
32
+ error_message = error_message + " profile class. Only use in profile params."
33
+ else
34
+ error_message = error_message + " class."
35
+ end
36
+
37
+ notify :error, {
38
+ # message: "#{function_token.value}() function call found in class. Only use in class params.",
39
+ message: error_message,
40
+ line: key_token.line,
41
+ column: key_token.column,
42
+ }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ PuppetLint.new_check(:no_hiera) do
2
+ def check
3
+ functions = ['hiera']
4
+
5
+ tokens.select { |t| (t.type == :NAME or t.type == :FUNCTION_NAME) and functions.include? t.value }.each do |function_token|
6
+ next unless function_token.next_code_token.type == :LPAREN
7
+
8
+ key_token = function_token.next_code_token.next_code_token
9
+ original_function = function_token.value
10
+
11
+ notify :error, {
12
+ message: "#{original_function}() function call. Use lookup() instead.",
13
+ line: key_token.line,
14
+ column: key_token.column,
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'lookup' do
4
+ context 'class with no lookup calls' do
5
+ let(:code) do
6
+ <<-EOS
7
+ class no_lookup_calls {
8
+ file { '/tmp/foo':
9
+ content => 'bar',
10
+ }
11
+ }
12
+ EOS
13
+ end
14
+
15
+ it 'should not detect any problems' do
16
+ expect(problems).to have(0).problems
17
+ end
18
+ end
19
+
20
+ context 'profile with a lookup call in params' do
21
+ let(:code) do
22
+ <<-EOS
23
+ class profile::lookup_call_params (
24
+ $content = lookup('some_key')
25
+ ) {
26
+ file { '/tmp/foo':
27
+ content => $content,
28
+ }
29
+ }
30
+ EOS
31
+ end
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
37
+
38
+ # and these should cause failiures
39
+ context 'profile with a lookup call in class' do
40
+ let(:msg) { 'lookup() function call found in profile class. Only use in profile params.' }
41
+
42
+ let(:code) do
43
+ <<-EOS
44
+ class profile::lookup_call_class {
45
+ file { '/tmp/foo':
46
+ content => lookup('some_key'),
47
+ }
48
+ }
49
+ EOS
50
+ end
51
+
52
+ it 'should detect a single problem' do
53
+ expect(problems).to have(1).problems
54
+ end
55
+
56
+ it 'should create an error' do
57
+ expect(problems).to contain_error(msg).on_line(3).in_column(31)
58
+ end
59
+ end
60
+
61
+ context 'class with a lookup call in params' do
62
+ let(:msg) { 'lookup() function call found in class params.' }
63
+
64
+ let(:code) do
65
+ <<-EOS
66
+ class lookup_call_params (
67
+ $content = lookup('some_key')
68
+ ) {
69
+ file { '/tmp/foo':
70
+ content => $content,
71
+ }
72
+ }
73
+ EOS
74
+ end
75
+
76
+ it 'should detect a single problem' do
77
+ expect(problems).to have(1).problems
78
+ end
79
+
80
+ it 'should create an error' do
81
+ expect(problems).to contain_error(msg).on_line(2).in_column(29)
82
+ end
83
+ end
84
+
85
+ context 'class with a lookup call in class' do
86
+ let(:msg) { 'lookup() function call found in class.' }
87
+
88
+ let(:code) do
89
+ <<-EOS
90
+ class lookup_call_class {
91
+ file { '/tmp/foo':
92
+ content => lookup('some_key'),
93
+ }
94
+ }
95
+ EOS
96
+ end
97
+
98
+ it 'should detect a single problem' do
99
+ expect(problems).to have(1).problem
100
+ end
101
+
102
+ it 'should create an error' do
103
+ expect(problems).to contain_error(msg).on_line(3).in_column(31)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'no_hiera' do
4
+ context 'class with no hiera calls' do
5
+ let(:code) do
6
+ <<-EOS
7
+ class no_hiera_calls {
8
+ file { '/tmp/foo':
9
+ content => 'bar',
10
+ }
11
+ }
12
+ EOS
13
+ end
14
+
15
+ it 'should not detect any problems' do
16
+ expect(problems).to have(0).problems
17
+ end
18
+ end
19
+
20
+ # and these should cause failiures
21
+
22
+ context 'class with a hiera call in class' do
23
+ let(:msg) { 'hiera() function call. Use lookup() instead.' }
24
+
25
+ let(:code) do
26
+ <<-EOS
27
+ class hiera_call {
28
+ file { '/tmp/foo':
29
+ content => hiera('some_key'),
30
+ }
31
+ }
32
+ EOS
33
+ end
34
+
35
+ it 'should detect a single problem' do
36
+ expect(problems).to have(1).problem
37
+ end
38
+
39
+ it 'should create an error' do
40
+ expect(problems).to contain_error(msg).on_line(3).in_column(30)
41
+ end
42
+ end
43
+
44
+ context 'class with a hiera call in params' do
45
+ let(:msg) { 'hiera() function call. Use lookup() instead.' }
46
+
47
+ let(:code) do
48
+ <<-EOS
49
+ class hiera_call (
50
+ $content = hiera('some_key')
51
+ ){
52
+ file { '/tmp/foo':
53
+ content => $content,
54
+ }
55
+ }
56
+ EOS
57
+ end
58
+
59
+ it 'should detect a single problem' do
60
+ expect(problems).to have(1).problem
61
+ end
62
+
63
+ it 'should create an error' do
64
+ expect(problems).to contain_error(msg).on_line(2).in_column(28)
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-hiera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Garrett Rowell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.9.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.9.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-its
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-collection_matchers
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.80.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.80.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 13.0.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 13.0.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-json_expectations
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.2'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.2'
117
+ - !ruby/object:Gem::Dependency
118
+ name: simplecov
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.18.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.18.0
131
+ description: " Extends puppet-lint to ensure no hiera functions are called and
132
+ that lookups are only used in class parameters.\n"
133
+ email: garrett@puppet.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - LICENSE
139
+ - README.md
140
+ - lib/puppet-lint/plugins/lookup.rb
141
+ - lib/puppet-lint/plugins/no_hiera.rb
142
+ - spec/puppet-lint/plugins/lookup_spec.rb
143
+ - spec/puppet-lint/plugins/no_hiera_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage:
146
+ licenses: []
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.7.6
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: puppet-lint hiera and lookup function checks
168
+ test_files:
169
+ - spec/spec_helper.rb
170
+ - spec/puppet-lint/plugins/no_hiera_spec.rb
171
+ - spec/puppet-lint/plugins/lookup_spec.rb