puppet-lint-legacy_facts-check 0.0.1 → 0.0.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzMwOGE1YmM4ZWI4ODExNTA1ZGZmYTc2ZDcwNWEyMDA3MmY2NGFkNg==
4
+ OTM0ZDNlZDRmMzk4MzVkYzMzNDJmMzA5YTEzNDNkOTI1M2FkMzI3YQ==
5
5
  data.tar.gz: !binary |-
6
- OTZmMWQxNTgyZDA2YmZmODI5NTAyMTQyNDA3MWQwMjIxNDA5Y2NhOA==
6
+ NTc3MTg5NWQ3MmQwMTA3M2I3NGUwNTNkOGE4ZjQxNDI2NjM0MDQ2MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGM4ZjI1M2M3NmZkMTYxNGZlZGJkNmFlZjBjZGI0NDI3ODJlYTVkNDlkNGEw
10
- YmMzNzBkMWEwYzdhYjU3M2VjNDc0MWMzMjY1NDllM2I3YjAwNWZhOWQzZTNj
11
- MTdmNDI0MmE3ZDYwM2ExZWY5ZmY4OWE5MzBlZGUzNDlmODY5OWI=
9
+ OTgyZDM1MzQwODEzYjBjYjQwOWQ5Y2I1OGY1M2Y5MTg5ZWFjYmU4OGYxYzhk
10
+ OGQ2NGIyNWM1ODY4OWVmNDlmZTg3MTdjNGVhMDMxNDQwYzkwMTljMTU5NTc2
11
+ ZWMyZjFkZGY0MGRlOGMyN2Y5MDY0NDRhYzAyM2Q1YTJhODM0ZWU=
12
12
  data.tar.gz: !binary |-
13
- YTViODU4MTU3ZDIzNTliOGMwMGEyYzhkZWVlYTIyMTQxOTgxMzE3ZTA5NDI0
14
- YjljNzViODZmMjA2ZTI1MGY2N2ZiZTAxNjhiNWU2ZTI5ZmNkYzQyOGNhY2Zi
15
- ZGMzY2I5MGY0NTMyYjViYTljZWNmMjhmY2ZiNmJiOGUzNThmMzk=
13
+ M2I4Y2I4YjU2MDY2YWEyNjRjZDFmZTkwMTA4ODhjODVmYmVjMWU3ZDQ2NWMz
14
+ ZWVlZjliY2Y0YmY5ZTQyNjgzNWJlMTU2ZWJlNzg1Y2QzYmJjNTEwNTJlYzMy
15
+ MzA4YzlhMTliYjI4MGM0MGY4YzcwZmI4YTNjYjBiNmIwYzc1NzY=
data/README.md CHANGED
@@ -1,11 +1,68 @@
1
1
  [![Build Status](https://travis-ci.org/mmckinst/puppet-lint-legacy_facts-check.svg?branch=master)](https://travis-ci.org/mmckinst/puppet-lint-legacy_facts-check)
2
2
  [![Gem](https://img.shields.io/gem/v/puppet-lint-legacy_facts-check.svg?maxAge=2592000)](https://rubygems.org/gems/puppet-lint-legacy_facts-check)
3
3
 
4
+ ## Overview
5
+
4
6
  A pupet-lint to check you are not using legacy facts like `$::operatingsystem`
5
7
  or `$facts['operatingsystem']`. You should use the new structured facts like
6
8
  `$facts['os']['name']` instead
7
9
 
8
- ## Overview
10
+ ## Installing
11
+
12
+ ### From the command line
13
+
14
+ ```shell
15
+ $ gem install puppet-lint-legacy_facts-check
16
+ ```
17
+
18
+ ### In a Gemfile
19
+
20
+ ```ruby
21
+ gem 'puppet-lint-legacy_facts-check', :require => false
22
+ ```
23
+
24
+ ## Checks
25
+
26
+ #### What you have done
27
+
28
+ ```puppet
29
+ $package_name = $::operatingsystem {
30
+ 'CentOS' => 'httpd',
31
+ 'Debian' => 'apache2',
32
+ }
33
+ ```
34
+
35
+ ```puppet
36
+ $package_name = $facts['operatingsystem'] {
37
+ 'CentOS' => 'httpd',
38
+ 'Debian' => 'apache2',
39
+ }
40
+ ```
41
+
42
+ #### What you should have done
43
+
44
+ ```puppet
45
+ $service_name = $facts['os']['name'] {
46
+ 'CentOS' => 'httpd',
47
+ 'Debian' => 'apache2',
48
+ }
49
+ ```
50
+
51
+ #### Disabling the check
52
+
53
+ To disable this check, you can add `--no-legacy_facts` to your puppet-lint
54
+ command line.
55
+
56
+ ```shell
57
+ $ puppet-lint --no-legacy_facts path/to/file.pp
58
+ ```
59
+
60
+ Alternatively, if you’re calling puppet-lint via the Rake task, you should
61
+ insert the following line to your `Rakefile`.
62
+
63
+ ```ruby
64
+ PuppetLint.configuration.send('disable_legacy_facts')
65
+ ```
9
66
 
10
67
  ## Limitations
11
68
 
@@ -108,63 +165,6 @@ This can be duplicated using the following string:
108
165
  `"$facts['ssh']['rsa']['fingerprints']['sha1']
109
166
  $facts['ssh']['rsa']['fingerprints']['sha256']"`
110
167
 
111
- ## Installing
112
-
113
- ### From the command line
114
-
115
- ```shell
116
- $ gem install puppet-lint-legacy_facts-check
117
- ```
118
-
119
- ### In a Gemfile
120
-
121
- ```ruby
122
- gem 'puppet-lint-legacy_facts-check', :require => false
123
- ```
124
-
125
- ## Checks
126
-
127
- #### What you have done
128
-
129
- ```puppet
130
- $package_name = $::operatingsystem {
131
- 'CentOS' => 'httpd',
132
- 'Debian' => 'apache2',
133
- }
134
- ```
135
-
136
- ```puppet
137
- $package_name = $facts['operatingsystem'] {
138
- 'CentOS' => 'httpd',
139
- 'Debian' => 'apache2',
140
- }
141
- ```
142
-
143
- #### What you should have done
144
-
145
- ```puppet
146
- $service_name = $facts['os']['name'] {
147
- 'CentOS' => 'httpd',
148
- 'Debian' => 'apache2',
149
- }
150
- ```
151
-
152
- #### Disabling the check
153
-
154
- To disable this check, you can add `--no-legacy_facts` to your puppet-lint
155
- command line.
156
-
157
- ```shell
158
- $ puppet-lint --no-legacy_facts path/to/file.pp
159
- ```
160
-
161
- Alternatively, if you’re calling puppet-lint via the Rake task, you should
162
- insert the following line to your `Rakefile`.
163
-
164
- ```ruby
165
- PuppetLint.configuration.send('disable_legacy_facts')
166
- ```
167
-
168
168
  ## License
169
169
 
170
170
  ```
@@ -84,7 +84,12 @@ PuppetLint.new_check(:legacy_facts) do
84
84
  }
85
85
  def check
86
86
  tokens.select { |x| x.type == :VARIABLE}.each do |token|
87
- fact_name = token.value.sub(/^(::)?(facts|trusted)?\[?['"]?/, '').sub(/['"]?\]?$/ ,'')
87
+ fact_name = ''
88
+ if token.value.start_with?('::') then
89
+ fact_name = token.value.sub(/^::/, '')
90
+ elsif token.value.start_with?('facts[') then
91
+ fact_name = token.value.match(/facts\['(.*)'\]/)[1]
92
+ end
88
93
  if EASY_FACTS.include?(fact_name) or UNCONVERTIBLE_FACTS.include?(fact_name) or fact_name.match(Regexp.union(REGEX_FACTS)) then
89
94
  notify :warning, {
90
95
  :message => 'legacy fact',
@@ -97,7 +102,11 @@ PuppetLint.new_check(:legacy_facts) do
97
102
  end
98
103
 
99
104
  def fix(problem)
100
- fact_name = problem[:token].value.sub(/^(::)?(facts|trusted)?\[?['"]?/, '').sub(/['"]?\]?$/ ,'')
105
+ if problem[:token].value.start_with?('::') then
106
+ fact_name = problem[:token].value.sub(/^::/, '')
107
+ elsif problem[:token].value.start_with?('facts[') then
108
+ fact_name = problem[:token].value.match(/facts\['(.*)'\]/)[1]
109
+ end
101
110
  if EASY_FACTS.include?(fact_name)
102
111
  problem[:token].value = EASY_FACTS[fact_name]
103
112
  elsif fact_name.match(Regexp.union(REGEX_FACTS))
@@ -11,16 +11,16 @@ describe 'legacy_facts' do
11
11
  end
12
12
  end
13
13
 
14
- context "fact variable using legacy $facts['osfamily']" do
15
- let(:code) { "$facts['osfamily']" }
14
+ context "fact variable using legacy $osfamily" do
15
+ let(:code) { "$osfamily" }
16
16
 
17
17
  it 'should only detect a single problem' do
18
- expect(problems).to have(1).problem
18
+ expect(problems).to have(0).problem
19
19
  end
20
20
  end
21
21
 
22
- context "fact variable using legacy $osfamily" do
23
- let(:code) { "$osfamily" }
22
+ context "fact variable using legacy $facts['osfamily']" do
23
+ let(:code) { "$facts['osfamily']" }
24
24
 
25
25
  it 'should only detect a single problem' do
26
26
  expect(problems).to have(1).problem
@@ -102,24 +102,16 @@ describe 'legacy_facts' do
102
102
  end
103
103
  end
104
104
 
105
- context "fact variable using legacy $facts['osfamily']" do
106
- let(:code) { "$facts['osfamily']" }
105
+ context "fact variable using legacy $osfamily" do
106
+ let(:code) { "$osfamily" }
107
107
 
108
108
  it 'should only detect a single problem' do
109
- expect(problems).to have(1).problem
110
- end
111
-
112
- it 'should fix the problem' do
113
- expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
114
- end
115
-
116
- it 'should use the facts hash' do
117
- expect(manifest).to eq("$facts['os']['family']")
109
+ expect(problems).to have(0).problem
118
110
  end
119
111
  end
120
112
 
121
- context "fact variable using legacy $osfamily" do
122
- let(:code) { "$osfamily" }
113
+ context "fact variable using legacy $facts['osfamily']" do
114
+ let(:code) { "$facts['osfamily']" }
123
115
 
124
116
  it 'should only detect a single problem' do
125
117
  expect(problems).to have(1).problem
@@ -132,7 +124,6 @@ describe 'legacy_facts' do
132
124
  it 'should use the facts hash' do
133
125
  expect(manifest).to eq("$facts['os']['family']")
134
126
  end
135
-
136
127
  end
137
128
 
138
129
  context "fact variable using legacy $::osfamily" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-legacy_facts-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark McKinstry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-20 00:00:00.000000000 Z
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint