puppet-lint-top_scope_facts-check 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +202 -0
- data/README.md +110 -0
- data/lib/puppet-lint/plugins/top_scope_facts.rb +21 -0
- data/spec/puppet-lint/plugins/top_scope_facts_spec.rb +169 -0
- data/spec/spec_helper.rb +3 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjYwZWI4NDcwOTIyMmJhMjQ0ZGZmMjgwZmNmZDk0ZjE2ZmI4MWM1ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWVjOWFjODU4MzYzNWQ4M2FhMWIyODdlNmQyYjM0Y2VkYzIxYTdiNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmE5ZmQ1NjJlODUwNjFlMTVmMTIzZDg1NTExMWE3ZDI5OTJmZGY0MjZjMzk0
|
10
|
+
MGI5OTk3YTFkYjJlZjIwZGFmYzkzYjE4YWJmYWIzYjJmOTg3YzQzOWU4Yzk1
|
11
|
+
MzAwYTMxN2I4NWRhMjI3OGU0YTg0MWY0OWMyNGUzYTc2NzMyYmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjU4YzFkNDYxOGNjNDI5NTA2NDQ1YjAxZmEwYzQ4YTY0Mjc4M2YxMTk3NGUx
|
14
|
+
ODI1YjQxZjg5YmNkYzUzMzhlMGU5YzRhYzdhNjI5NzI4NTBhYzFlOGI2ZTc4
|
15
|
+
YzdmYTc0NTA2ZmQzNzE2ZTBjZjc2YzZjODRiMTk1NjVkNzRlZjI=
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/mmckinst/puppet-lint-top_scope_facts-check.svg?branch=master)](https://travis-ci.org/mmckinst/puppet-lint-top_scope_facts-check)
|
2
|
+
|
3
|
+
A puppet-lint plugin to check you are not using top scope fact variables like
|
4
|
+
`$::operatingsystem`. You should use the $facts hash like
|
5
|
+
`$facts['operatingsystem']` instead.
|
6
|
+
|
7
|
+
## Overview
|
8
|
+
|
9
|
+
In puppet 2.x facts were top scope variables and accessed as `$operatingsystem`
|
10
|
+
or `$::operatingsystem`, the
|
11
|
+
[latter being far more common](https://docs.puppet.com/puppet/3.8/reference/lang_facts_and_builtin_vars.html#historical-note-about-)
|
12
|
+
especially because the
|
13
|
+
[linter enforces that convention](http://puppet-lint.com/checks/variable_scope/).
|
14
|
+
|
15
|
+
Puppet 3.5 added a `$facts` hash to access facts like
|
16
|
+
`$facts['operatingsystem']`. This works if you set `trusted_node_data = true`
|
17
|
+
but it was
|
18
|
+
[not enabled by default](https://docs.puppet.com/puppet/3.5/reference/release_notes.html#global-facts-hash). Puppet
|
19
|
+
4 has it enabled by default.
|
20
|
+
|
21
|
+
This puppet-lint plugin will help find facts referenced as top scope variables
|
22
|
+
and replace them with the `$facts` hash to improve readability of code. Its only
|
23
|
+
useful if you're running puppet 3.5 to 3.8 with trusted_node_data enabled, or if
|
24
|
+
you're running puppet 4.
|
25
|
+
|
26
|
+
## Limitations
|
27
|
+
|
28
|
+
* It only finds facts using the top-scope: ie it will find `$::operatingsystem`
|
29
|
+
but not `$operatingsystem`.
|
30
|
+
* It assumes all top scope variables are facts. If you have top scope variables
|
31
|
+
that aren't facts you should configure the
|
32
|
+
[linter to ignore them](https://github.com/mmckinst/puppet-lint-top_scope_facts-check#configuring-the-check).
|
33
|
+
|
34
|
+
|
35
|
+
## Installing
|
36
|
+
|
37
|
+
### From the command line
|
38
|
+
|
39
|
+
```shell
|
40
|
+
$ gem install puppet-lint-top_scope_facts-check
|
41
|
+
```
|
42
|
+
|
43
|
+
### In a Gemfile
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'puppet-lint-top_scope_facts-check', :require => false
|
47
|
+
```
|
48
|
+
|
49
|
+
## Checks
|
50
|
+
|
51
|
+
#### What you have done
|
52
|
+
|
53
|
+
```puppet
|
54
|
+
$service_name = $::operatingsystem {
|
55
|
+
'CentOS' => 'httpd',
|
56
|
+
'Debian' => 'apache2',
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
#### What you should have done
|
61
|
+
|
62
|
+
```puppet
|
63
|
+
$service_name = $facts['operatingsystem'] {
|
64
|
+
'CentOS' => 'httpd',
|
65
|
+
'Debian' => 'apache2',
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
#### Configuring the check
|
70
|
+
|
71
|
+
You can whitelist top scope variables to ignore via the Rake task. You should
|
72
|
+
insert the following line to your `Rakefile`.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
PuppetLint.configuration.top_scope_variables = ['location', 'role']
|
76
|
+
```
|
77
|
+
|
78
|
+
#### Disabling the check
|
79
|
+
|
80
|
+
To disable this check, you can add `--no-top_scope_facts` to your puppet-lint
|
81
|
+
command line.
|
82
|
+
|
83
|
+
```shell
|
84
|
+
$ puppet-lint --no-top_scope_facts path/to/file.pp
|
85
|
+
```
|
86
|
+
|
87
|
+
Alternatively, if you’re calling puppet-lint via the Rake task, you should
|
88
|
+
insert the following line to your `Rakefile`.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
PuppetLint.configuration.send('disable_top_scope_facts')
|
92
|
+
```
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
```
|
97
|
+
Copyright 2016 Mark McKinstry
|
98
|
+
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
100
|
+
you may not use this file except in compliance with the License.
|
101
|
+
You may obtain a copy of the License at
|
102
|
+
|
103
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
104
|
+
|
105
|
+
Unless required by applicable law or agreed to in writing, software
|
106
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
107
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
108
|
+
See the License for the specific language governing permissions and
|
109
|
+
limitations under the License.
|
110
|
+
```
|
@@ -0,0 +1,21 @@
|
|
1
|
+
PuppetLint.new_check(:top_scope_facts) do
|
2
|
+
def check
|
3
|
+
whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || [])
|
4
|
+
whitelist = whitelist.join('|')
|
5
|
+
tokens.select { |x| x.type == :VARIABLE}.each do |token|
|
6
|
+
if token.value.match(/^::/) and not token.value.match(/^::(#{whitelist})\[?/)
|
7
|
+
notify :warning, {
|
8
|
+
:message => 'top scope fact instead of facts hash',
|
9
|
+
:line => token.line,
|
10
|
+
:column => token.column,
|
11
|
+
:token => token,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def fix(problem)
|
19
|
+
problem[:token].value = "facts['" + problem[:token].value.sub(/^::/, '') + "']"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'top_scope_facts' do
|
4
|
+
let(:msg) { 'top scope fact instead of facts hash' }
|
5
|
+
context 'with fix disabled' do
|
6
|
+
context 'fact variable using $facts hash' do
|
7
|
+
let(:code) { "$facts['operatingsystem']" }
|
8
|
+
|
9
|
+
it 'should not detect any problems' do
|
10
|
+
expect(problems).to have(0).problem
|
11
|
+
end
|
12
|
+
end
|
13
|
+
context 'non-fact variable with two colons' do
|
14
|
+
let(:code) { "$foo::bar" }
|
15
|
+
|
16
|
+
it 'should not detect any problems' do
|
17
|
+
expect(problems).to have(0).problem
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'top scope $::facts hash' do
|
22
|
+
let(:code) { "$::facts['os']['family']" }
|
23
|
+
|
24
|
+
it 'should not detect any problems' do
|
25
|
+
expect(problems).to have(0).problem
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'top scope $::trusted hash' do
|
30
|
+
let(:code) { "$::trusted['certname']" }
|
31
|
+
|
32
|
+
it 'should not detect any problems' do
|
33
|
+
expect(problems).to have(0).problem
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'fact variable using top scope' do
|
38
|
+
let(:code) { '$::operatingsystem' }
|
39
|
+
|
40
|
+
it 'should only detect a single problem' do
|
41
|
+
expect(problems).to have(1).problem
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should create a warning' do
|
45
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'fact variable using top scope with curly braces in double quote' do
|
50
|
+
let(:code) { '"${::operatingsystem}"' }
|
51
|
+
|
52
|
+
it 'should only detect a single problem' do
|
53
|
+
expect(problems).to have(1).problem
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should create a warning' do
|
57
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(3)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with fix enabled' do
|
64
|
+
before do
|
65
|
+
PuppetLint.configuration.fix = true
|
66
|
+
end
|
67
|
+
|
68
|
+
after do
|
69
|
+
PuppetLint.configuration.fix = false
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'fact variable using $facts hash' do
|
73
|
+
let(:code) { "$facts['operatingsystem']" }
|
74
|
+
|
75
|
+
it 'should not detect any problems' do
|
76
|
+
expect(problems).to have(0).problem
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context 'non-fact variable with two colons' do
|
80
|
+
let(:code) { "$foo::bar" }
|
81
|
+
|
82
|
+
it 'should not detect any problems' do
|
83
|
+
expect(problems).to have(0).problem
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'top scope $::facts hash' do
|
88
|
+
let(:code) { "$::facts['os']['family']" }
|
89
|
+
|
90
|
+
it 'should not detect any problems' do
|
91
|
+
expect(problems).to have(0).problem
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'top scope $::trusted hash' do
|
96
|
+
let(:code) { "$::trusted['certname']" }
|
97
|
+
|
98
|
+
it 'should not detect any problems' do
|
99
|
+
expect(problems).to have(0).problem
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'fact variable using top scope' do
|
104
|
+
let(:code) { '$::operatingsystem' }
|
105
|
+
|
106
|
+
it 'should only detect a single problem' do
|
107
|
+
expect(problems).to have(1).problem
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should fix the problem' do
|
111
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should should use the facts hash' do
|
115
|
+
expect(manifest).to eq("$facts['operatingsystem']")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'fact variable using top scope with curly braces in double quote' do
|
120
|
+
let(:code) { '"${::operatingsystem}"' }
|
121
|
+
|
122
|
+
it 'should fix the problem' do
|
123
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should should use the facts hash' do
|
127
|
+
expect(manifest).to eq('"${facts[\'operatingsystem\']}"')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with custom top scope fact variables' do
|
132
|
+
before do
|
133
|
+
PuppetLint.configuration.top_scope_variables = ['location', 'role']
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'fact variable using $facts hash' do
|
137
|
+
let(:code) { "$facts['operatingsystem']" }
|
138
|
+
|
139
|
+
it 'should not detect any problems' do
|
140
|
+
expect(problems).to have(0).problem
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'fact variable using $trusted hash' do
|
145
|
+
let(:code) { "$trusted['certname']" }
|
146
|
+
|
147
|
+
it 'should not detect any problems' do
|
148
|
+
expect(problems).to have(0).problem
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'whitelisted top scope variable $::location' do
|
153
|
+
let(:code) { "$::location" }
|
154
|
+
|
155
|
+
it 'should not detect any problems' do
|
156
|
+
expect(problems).to have(0).problem
|
157
|
+
end
|
158
|
+
end
|
159
|
+
context 'non-whitelisted top scope variable $::application' do
|
160
|
+
let(:code) { "$::application" }
|
161
|
+
|
162
|
+
it 'should not detect any problems' do
|
163
|
+
expect(problems).to have(1).problem
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-top_scope_facts-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark McKinstry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-13 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-its
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-collection_matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ! " A puppet-lint plugin to check you are not using top scope fact variables
|
84
|
+
like\n $::operatingsystem. You should use the $facts hash like\n $facts['operatingsystem']
|
85
|
+
instead.\n"
|
86
|
+
email: mmckinst@umich.edu
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- lib/puppet-lint/plugins/top_scope_facts.rb
|
94
|
+
- spec/puppet-lint/plugins/top_scope_facts_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: https://github.com/mmckinst/puppet-lint-top_scope_facts-check
|
97
|
+
licenses:
|
98
|
+
- Apache-2.0
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A puppet-lint plugin to check you are not using top scope fact variables
|
120
|
+
like $::operatingsystem
|
121
|
+
test_files:
|
122
|
+
- spec/puppet-lint/plugins/top_scope_facts_spec.rb
|
123
|
+
- spec/spec_helper.rb
|