puppet-lint-concatenated_template_files-check 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/lib/puppet-lint/plugins/concatenated_template_files.rb +39 -0
- data/spec/puppet-lint/plugins/puppet-lint-concatenated_template_files_spec.rb +44 -0
- data/spec/spec_helper.rb +3 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 336f4fd9a668d6e19e5fd91f121e759aaf1c45e2
|
4
|
+
data.tar.gz: 239a8525f3537186f71c6693c28d7c24f9a087c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61f8e714b8a73b6ad5e8714670d08190f0a8a234aed0777c434fa1ade0a5b398e7bceb77ff2f2d593abb062b21ca53a4cfaeb19923508b5fb6e1b4587a8a8a8d
|
7
|
+
data.tar.gz: fc1a563fb2e2acedc3178ab775ba90c6aebc3b3daf57cdb27c4da73252f390184f1559922b8442cf3a670926024f3772ea0b403366065b6ef4071337be5017bf
|
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,57 @@
|
|
1
|
+
# puppet-lint concatenated template files check
|
2
|
+
|
3
|
+
Extends puppet-lint to ensure all `template` functions expand a single
|
4
|
+
file, rather than unexpectedly concatenating multiple template files in
|
5
|
+
to a single string.
|
6
|
+
|
7
|
+
There is a slightly obscure difference in the way that puppet handles
|
8
|
+
multiple file names when calling the `file` or `template` functions. In
|
9
|
+
the case of the `file` function it will return the contents of the first
|
10
|
+
file found from those given, skipping any that don’t exist. The
|
11
|
+
`template` function on the other hand will evaluate all of the specified
|
12
|
+
templates and return their outputs concatenated into a single string.
|
13
|
+
|
14
|
+
This is very rarely what you want. Assuming absent_file is, well absent,
|
15
|
+
and real_file is in the correct place this will return the content of real_file.
|
16
|
+
|
17
|
+
class multi_templated_file {
|
18
|
+
file { '/tmp/symbolic-mode':
|
19
|
+
content => file('mymodule/absent_file.erb', 'mymodule/real_file.erb'),
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
However if both of these files exist then the contents will be
|
24
|
+
concatenated and the combination of all given files will be returned to
|
25
|
+
`content`.
|
26
|
+
|
27
|
+
class multi_templated_file {
|
28
|
+
file { '/tmp/symbolic-mode':
|
29
|
+
content => template('mymodule/first_file.erb', 'mymodule/second_file.erb'),
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
If you do want to select from multiple templates then
|
34
|
+
[puppet-multitemplate](https://github.com/deanwilson/puppet-multitemplate)
|
35
|
+
will give you a new function that behaves as you'd expect.
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
To use this plugin add the following line to your Gemfile
|
40
|
+
|
41
|
+
gem 'puppet-lint-concatenated_template_files-check'
|
42
|
+
|
43
|
+
and then run `bundle install`.
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
This plugin provides a new check to `puppet-lint`.
|
48
|
+
|
49
|
+
calling "template" with multiple files concatenates them into a single string
|
50
|
+
|
51
|
+
#### Author
|
52
|
+
|
53
|
+
[Dean Wilson](http://www.unixdaemon.net)
|
54
|
+
|
55
|
+
### License
|
56
|
+
|
57
|
+
* MIT
|
@@ -0,0 +1,39 @@
|
|
1
|
+
PuppetLint.new_check(:concatenated_template_files) do
|
2
|
+
|
3
|
+
def check
|
4
|
+
resource_indexes.each do |resource|
|
5
|
+
if resource[:type].value == 'file'
|
6
|
+
resource[:param_tokens].select { |param_token|
|
7
|
+
param_token.value == 'content'
|
8
|
+
}.each do |content_token|
|
9
|
+
|
10
|
+
value_token = content_token.next_code_token.next_code_token
|
11
|
+
|
12
|
+
if value_token.value == 'template'
|
13
|
+
|
14
|
+
file_names = []
|
15
|
+
|
16
|
+
current_token = value_token.next_token
|
17
|
+
until current_token.type == :RPAREN
|
18
|
+
current_token = current_token.next_code_token
|
19
|
+
file_names << current_token.value if current_token.type == :SSTRING
|
20
|
+
end
|
21
|
+
|
22
|
+
if file_names.length > 1
|
23
|
+
|
24
|
+
warning = 'calling "template" with multiple files concatenates them into a single string'
|
25
|
+
|
26
|
+
notify :warning, {
|
27
|
+
:message => warning,
|
28
|
+
:line => value_token.line,
|
29
|
+
:column => value_token.column,
|
30
|
+
:param_token => content_token,
|
31
|
+
:value_token => value_token,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'concatenated_template_files' do
|
4
|
+
let(:msg) { 'calling "template" with multiple files concatenates them into a single string' }
|
5
|
+
|
6
|
+
context 'template function with one filename' do
|
7
|
+
let(:code) do
|
8
|
+
<<-EOS
|
9
|
+
class single_templated_file {
|
10
|
+
file { '/tmp/templated':
|
11
|
+
content => template('mymodule/single_file.erb'),
|
12
|
+
}
|
13
|
+
}
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not detect any problems' do
|
18
|
+
expect(problems).to have(0).problems
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
context 'template function with multiple filenames' do
|
24
|
+
let(:code) do
|
25
|
+
<<-EOS
|
26
|
+
class multi_templated_file {
|
27
|
+
file { '/tmp/templated':
|
28
|
+
content => template('mymodule/first_file.erb', 'mymodule/second_file.erb'),
|
29
|
+
}
|
30
|
+
}
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should detect a single problem' do
|
35
|
+
expect(problems).to have(1).problem
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should create a warning' do
|
39
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(24)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-concatenated_template_files-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-27 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
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: |2
|
112
|
+
Extends puppet-lint to ensure all template functions expand a single
|
113
|
+
file, rather than unexpectedly concatenating multiple template files in
|
114
|
+
to a single string.
|
115
|
+
email: dean.wilson@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- LICENSE
|
121
|
+
- README.md
|
122
|
+
- lib/puppet-lint/plugins/concatenated_template_files.rb
|
123
|
+
- spec/puppet-lint/plugins/puppet-lint-concatenated_template_files_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
homepage: https://github.com/deanwilson/puppet-lint-concatenated_template_files-check
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.8
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: puppet-lint concatenated_template_files check
|
149
|
+
test_files:
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/puppet-lint/plugins/puppet-lint-concatenated_template_files_spec.rb
|
152
|
+
has_rdoc:
|