puppet-lint-fileserver-check 1.0.0

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
+ SHA1:
3
+ metadata.gz: 722b51fc3ed0c18a55430a47c7fde2e6fa629517
4
+ data.tar.gz: c40f988cb66cda5c83c829b2ccb175abf30c0954
5
+ SHA512:
6
+ metadata.gz: 62e4400749b9f814c77242c525fdc92a5c2be7179dffdfd73583193582dc320d04b74f2a50bacb3d368c6c4a05e8c5011ae64b2183287df117e670f77992956b
7
+ data.tar.gz: ff5e9562e3e317b255ee8c8541f0cfed458baeb16f1cc0d75ec7ed99e9d978a33b58357d210bd2f543eaa8e31b599c9b51699e94490b7ac23720d2ec93ffea71
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ puppet-lint-fileserver-check
2
+ =================================
3
+
4
+ [![Build Status](https://travis-ci.org/camptocamp/puppet-lint-fileserver-check.svg)](https://travis-ci.org/camptocamp/puppet-lint-fileserver-check)
5
+
6
+ A puppet-lint plugin to check that you use the `file()` function instead of the Puppet Fileserver.
7
+
8
+
9
+ ## Checks
10
+
11
+ ### Fileserver use
12
+
13
+ Fileserver use is very slow and for small files (<16KB)
14
+
15
+ #### What you have done
16
+
17
+ ```puppet
18
+ file { 'foo':
19
+ ensure => file,
20
+ source => 'puppet:///modules/foo/bar',
21
+ }
22
+ ```
23
+
24
+ #### What you should have done
25
+
26
+ ```puppet
27
+ file { 'foo':
28
+ ensure => file,
29
+ content => file('foo/bar'),
30
+ }
31
+ ```
32
+
33
+ #### Disabling the check
34
+
35
+ To disable this check, you can add `--no-fileserver-check` to your puppet-lint command line.
36
+
37
+ ```shell
38
+ $ puppet-lint --no-fileserver-check path/to/file.pp
39
+ ```
40
+
41
+ Alternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your `Rakefile`.
42
+
43
+ ```ruby
44
+ PuppetLint.configuration.send('disable_fileserver')
45
+ ```
@@ -0,0 +1,27 @@
1
+ PuppetLint.new_check(:fileserver) do
2
+ def check
3
+ resource_indexes.each do |resource|
4
+ attr = resource[:tokens].select do |t|
5
+ t.prev_code_token && t.prev_code_token.type == :FARROW && t.value =~ %r{^puppet:///}
6
+ end
7
+ next if attr.empty?
8
+ notify :warning, {
9
+ :message => 'expected file() instead of fileserver',
10
+ :line => attr[0].line,
11
+ :column => attr[0].column,
12
+ :token => attr[0],
13
+ :resource => resource,
14
+ }
15
+ end
16
+ end
17
+
18
+ def fix(problem)
19
+ if problem[:resource][:type].value == 'file' && problem[:token].type == :SSTRING
20
+ problem[:token].prev_code_token.prev_code_token.value = 'content'
21
+ problem[:token].value.sub!(%r{^puppet:///modules/(.*)}, "file('\\1')")
22
+ problem[:token].type = :NAME
23
+ else
24
+ raise PuppetLint::NoFix, "Not fixing"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'fileserver' do
4
+ let(:msg) { 'expected file() instead of fileserver' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code using file()' do
8
+ let(:code) {
9
+ <<-EOS
10
+ file { 'foo':
11
+ ensure => file,
12
+ content => file('foo/bar'),
13
+ }
14
+ EOS
15
+ }
16
+
17
+ it 'should not detect any problems' do
18
+ expect(problems).to have(0).problems
19
+ end
20
+ end
21
+
22
+ context 'code using source with file:///' do
23
+ let(:code) {
24
+ <<-EOS
25
+ file { 'foo':
26
+ ensure => file,
27
+ source => 'file:///foo/bar',
28
+ }
29
+ EOS
30
+ }
31
+
32
+ it 'should detect a single problem' do
33
+ expect(problems).to have(0).problem
34
+ end
35
+ end
36
+
37
+ context 'code using fileserver with puppet:///' do
38
+ let(:code) {
39
+ <<-EOS
40
+ file { 'foo':
41
+ ensure => file,
42
+ source => 'puppet:///modules/foo/bar',
43
+ }
44
+ EOS
45
+ }
46
+
47
+ it 'should detect a single problem' do
48
+ expect(problems).to have(1).problem
49
+ end
50
+
51
+ it 'should create a warning' do
52
+ expect(problems).to contain_warning(msg).on_line(3).in_column(21)
53
+ end
54
+ end
55
+
56
+ context 'code using $module_name' do
57
+ let(:code) {
58
+ <<-EOS
59
+ file { 'foo':
60
+ ensure => file,
61
+ source => "puppet:///modules/${module_name}/bar",
62
+ }
63
+ EOS
64
+ }
65
+
66
+ it 'should detect a single problem' do
67
+ expect(problems).to have(1).problem
68
+ end
69
+
70
+ it 'should create a warning' do
71
+ expect(problems).to contain_warning(msg).on_line(3).in_column(21)
72
+ end
73
+ end
74
+
75
+ context 'when using fileserver not in file resource' do
76
+ let(:code) {
77
+ <<-EOS
78
+ foo { 'foo':
79
+ file_source => 'puppet:///modules/foo/bar',
80
+ }
81
+ EOS
82
+ }
83
+
84
+ it 'should detect a single problem' do
85
+ expect(problems).to have(1).problem
86
+ end
87
+
88
+ it 'should create a warning' do
89
+ expect(problems).to contain_warning(msg).on_line(2).in_column(26)
90
+ end
91
+ end
92
+ end
93
+
94
+ context 'with fix enabled' do
95
+ before do
96
+ PuppetLint.configuration.fix = true
97
+ end
98
+
99
+ after do
100
+ PuppetLint.configuration.fix = false
101
+ end
102
+
103
+ context 'code using file()' do
104
+ let(:code) {
105
+ <<-EOS
106
+ file { 'foo':
107
+ ensure => file,
108
+ content => file('foo/bar'),
109
+ }
110
+ EOS
111
+ }
112
+
113
+ it 'should not detect any problems' do
114
+ expect(problems).to have(0).problems
115
+ end
116
+
117
+ it 'should not modify the manifest' do
118
+ expect(manifest).to eq(code)
119
+ end
120
+ end
121
+
122
+ context 'code using source with file:///' do
123
+ let(:code) {
124
+ <<-EOS
125
+ file { 'foo':
126
+ ensure => file,
127
+ source => 'file:///foo/bar',
128
+ }
129
+ EOS
130
+ }
131
+
132
+ it 'should detect a single problem' do
133
+ expect(problems).to have(0).problem
134
+ end
135
+
136
+ it 'should not modify the manifest' do
137
+ expect(manifest).to eq(code)
138
+ end
139
+ end
140
+
141
+ context 'code using fileserver with puppet:///' do
142
+ let(:code) {
143
+ <<-EOS
144
+ file { 'foo':
145
+ ensure => file,
146
+ source => 'puppet:///modules/foo/bar',
147
+ }
148
+ EOS
149
+ }
150
+
151
+ it 'should detect a single problem' do
152
+ expect(problems).to have(1).problem
153
+ end
154
+
155
+ it 'should fix the problem' do
156
+ expect(problems).to contain_fixed(msg).on_line(3).in_column(21)
157
+ end
158
+
159
+ it 'should add a newline to the end of the manifest' do
160
+ expect(manifest).to eq(
161
+ <<-EOS
162
+ file { 'foo':
163
+ ensure => file,
164
+ content => file('foo/bar'),
165
+ }
166
+ EOS
167
+ )
168
+ end
169
+ end
170
+
171
+ context 'code using $module_name' do
172
+ let(:code) {
173
+ <<-EOS
174
+ file { 'foo':
175
+ ensure => file,
176
+ source => "puppet:///modules/${module_name}/bar",
177
+ }
178
+ EOS
179
+ }
180
+
181
+ it 'should detect a single problem' do
182
+ expect(problems).to have(1).problem
183
+ end
184
+
185
+ it 'should create a warning' do
186
+ expect(problems).to contain_warning(msg).on_line(3).in_column(21)
187
+ end
188
+
189
+ it 'should not modify the manifest' do
190
+ expect(manifest).to eq(code)
191
+ end
192
+ end
193
+
194
+ context 'when using fileserver not in file resource' do
195
+ let(:code) {
196
+ <<-EOS
197
+ foo { 'foo':
198
+ file_source => 'puppet:///modules/foo/bar',
199
+ }
200
+ EOS
201
+ }
202
+
203
+ it 'should detect a single problem' do
204
+ expect(problems).to have(1).problem
205
+ end
206
+
207
+ it 'should create a warning' do
208
+ expect(problems).to contain_warning(msg).on_line(2).in_column(26)
209
+ end
210
+
211
+ it 'should not modify the manifest' do
212
+ expect(manifest).to eq(code)
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-fileserver-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mickaël Canévet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-17 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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: |2
84
+ A puppet-lint plugin to check if puppet:/// is used instead of file().
85
+ email: mickael.canevet@camptocamp.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - lib/puppet-lint/plugins/check-fileserver.rb
92
+ - spec/puppet-lint/plugins/check_fileserver_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/camptocamp/puppet-lint-fileserver-check
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A puppet-lint plugin to check if puppet:/// is used instead of file().
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ - spec/puppet-lint/plugins/check_fileserver_spec.rb