puppet-lint-recurse_file-check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +13 -0
- data/Gemfile +17 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +10 -0
- data/lib/puppet-lint/plugins/recurse_file.rb +28 -0
- data/puppet-lint-no_file_path_attribute-check.gemspec +16 -0
- data/spec/puppet-lint/plugins/recurse_file_spec.rb +59 -0
- data/spec/spec_helper.rb +3 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6c9ff780d75c28be7c4c375c5a4ac7239acd62f88ba74bf8ff5cbbe13b9e24d
|
4
|
+
data.tar.gz: f91e2c4676e3a85131a92da6c6c2558bd5a93c3529c12d43ca0978f41d3dc959
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b04ac436b64ed60d57b4f757f224691fe206d944fc55a8169ce78f2bb778381d2bae49c5d5805d0a78d2c586615916c0da76a721512772bfa95036fdc74db61
|
7
|
+
data.tar.gz: 68782dff257ce95c356b1c9e98fe8c51a2781ac7eacbc2cacd856ccecffbaba61b29b1af35341b7fed8df0225c24c8160e82203db203b660500a2973a68aae4a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'rake', '~> 10.0'
|
7
|
+
gem 'rspec-its', '~> 1.0'
|
8
|
+
gem 'rspec-collection_matchers', '~> 1.0'
|
9
|
+
gem 'rspec', '~> 3.0'
|
10
|
+
gem 'json'
|
11
|
+
gem 'rubocop'
|
12
|
+
gem 'simplecov', :require => false
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
|
17
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jarret Lavallee
|
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,46 @@
|
|
1
|
+
# puppet-lint recurse file check
|
2
|
+
|
3
|
+
Extends puppet-lint to ensure that file resources do not have `recurse` enabled. This can lead to performance issues in Puppetserver and PuppetDB when there are thousands of subdirectories or files that are managed. It is suggested to use an alternate approach for managing those directories.
|
4
|
+
|
5
|
+
This plug-in to `puppet-lint` will flag the a file resource that has `recurse => true` similar to the following.
|
6
|
+
|
7
|
+
```
|
8
|
+
file { '/tmp/installer':
|
9
|
+
ensure => absent,
|
10
|
+
recurse => true,
|
11
|
+
}
|
12
|
+
```
|
13
|
+
|
14
|
+
Or something like the following.
|
15
|
+
|
16
|
+
```
|
17
|
+
file { '/data':
|
18
|
+
owner => 'root',
|
19
|
+
recurse => true,
|
20
|
+
}
|
21
|
+
```
|
22
|
+
|
23
|
+
While the code above is functional, it will create a resource event for each file or directory under the `/tmp/installer` directory when it is being removed. This artificially bloats the report as the number of files increases. We have seen this done with directories of hundreds or thousands of files, which has created reports of over 256MB. An `exec` resource may be a better solution for this type of file management.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
To install this for the local `puppet-lint` command line utility it can be installed with the following.
|
28
|
+
|
29
|
+
```
|
30
|
+
gem install puppet-lint-recurse_file-check
|
31
|
+
```
|
32
|
+
|
33
|
+
To use this plug-in with `bundler`, add the following line to your Gemfile.
|
34
|
+
|
35
|
+
```
|
36
|
+
gem 'puppet-lint-recurse_file-check'
|
37
|
+
```
|
38
|
+
|
39
|
+
and then run `bundle install`.
|
40
|
+
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
This plug-in provides a new check to `puppet-lint`. The following is the output which will be shown.
|
45
|
+
|
46
|
+
> recurse file resources can cause decreased performance
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Public: Check the tokens of each File resource instance for a recurse
|
2
|
+
# true parameter and if found, record a warning about the potential
|
3
|
+
# performance impact.
|
4
|
+
#
|
5
|
+
# https://puppet.com/docs/puppet/latest/types/file.html#file-attribute-recurse
|
6
|
+
PuppetLint.new_check(:recurse_file) do
|
7
|
+
|
8
|
+
def check
|
9
|
+
resource_indexes.each do |resource|
|
10
|
+
next unless resource[:type].value == 'file'
|
11
|
+
|
12
|
+
resource[:param_tokens].select { |param_token|
|
13
|
+
param_token.value == 'recurse'
|
14
|
+
}.each do |param_token|
|
15
|
+
value_token = param_token.next_code_token.next_code_token
|
16
|
+
|
17
|
+
next unless value_token.value == 'true'
|
18
|
+
notify(
|
19
|
+
:warning,
|
20
|
+
:message => 'recurse file resources can cause decreased performance',
|
21
|
+
:line => value_token.line,
|
22
|
+
:column => value_token.column,
|
23
|
+
:token => value_token
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'puppet-lint-recurse_file-check'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.homepage = 'https://github.com/jarretlavallee/puppet-recurse_file-check'
|
5
|
+
s.license = 'MIT'
|
6
|
+
s.author = 'Jarret Lavallee'
|
7
|
+
s.email = 'jarret.lavallee@gmail.com'
|
8
|
+
s.files = `git ls-files`.split("\n")
|
9
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
10
|
+
s.summary = 'puppet-lint recurse_file check'
|
11
|
+
s.description = <<-EOF
|
12
|
+
Extends puppet-lint to ensure file resources do not recurse enabled.
|
13
|
+
EOF
|
14
|
+
|
15
|
+
s.add_dependency 'puppet-lint', '>= 1.1', '< 3.0'
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recurse_file' do
|
4
|
+
let(:msg) { 'recurse file resources can cause decreased performance' }
|
5
|
+
|
6
|
+
context 'recurse is enabled' do
|
7
|
+
let(:code) { "file { 'foo': recurse => true }" }
|
8
|
+
|
9
|
+
it 'should only detect a single problem' do
|
10
|
+
expect(problems).to have(1).problem
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create a warning' do
|
14
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(26)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'recurse is disabled' do
|
19
|
+
let(:code) { "file { 'foo': recurse => false }" }
|
20
|
+
|
21
|
+
it 'should not detect any problems' do
|
22
|
+
expect(problems).to have(0).problems
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'recurse is not defined' do
|
27
|
+
let(:code) { "file { 'foo': }" }
|
28
|
+
|
29
|
+
it 'should not detect any problems' do
|
30
|
+
expect(problems).to have(0).problems
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'multi body file recurse selector' do
|
35
|
+
let(:code) do
|
36
|
+
<<-END
|
37
|
+
file {
|
38
|
+
'/tmp/foo1':
|
39
|
+
ensure => $foo ? { default => absent },
|
40
|
+
recurse => true;
|
41
|
+
'/tmp/foo2':
|
42
|
+
recurse => true;
|
43
|
+
'/tmp/foo3':
|
44
|
+
recurse => true;
|
45
|
+
}
|
46
|
+
END
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should detect 3 problems' do
|
50
|
+
expect(problems).to have(3).problems
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should create three warnings' do
|
54
|
+
expect(problems).to contain_warning(sprintf(msg)).on_line(4).in_column(26)
|
55
|
+
expect(problems).to contain_warning(sprintf(msg)).on_line(6).in_column(26)
|
56
|
+
expect(problems).to contain_warning(sprintf(msg)).on_line(8).in_column(26)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-recurse_file-check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jarret Lavallee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-26 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
|
+
description: " Extends puppet-lint to ensure file resources do not recurse enabled.\n"
|
34
|
+
email: jarret.lavallee@gmail.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- ".gitignore"
|
40
|
+
- ".travis.yml"
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- lib/puppet-lint/plugins/recurse_file.rb
|
46
|
+
- puppet-lint-no_file_path_attribute-check.gemspec
|
47
|
+
- spec/puppet-lint/plugins/recurse_file_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
homepage: https://github.com/jarretlavallee/puppet-recurse_file-check
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.7.6
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: puppet-lint recurse_file check
|
73
|
+
test_files:
|
74
|
+
- spec/puppet-lint/plugins/recurse_file_spec.rb
|
75
|
+
- spec/spec_helper.rb
|