puppet-lint-no_file_path_attribute-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/LICENSE +21 -0
- data/README.md +44 -0
- data/lib/puppet-lint/plugins/no_file_path_attribute.rb +22 -0
- data/spec/puppet-lint/plugins/puppet-lint-no_file_path_attribute_spec.rb +44 -0
- data/spec/spec_helper.rb +3 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb2751bd28f9b92acbc47870d6c78d8d7082bdbe
|
4
|
+
data.tar.gz: c02caa1719ea793d48ca0c5c0e6e065a15949e3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c33fa5643ce3e9ec4adb3c0d6c7cf61efaeda750a851f21548f738074c27af2b474a5c3c5eafb8cb1cc008cef1b5284dc6504ef9323b87ba6f6a42de71d2ba52
|
7
|
+
data.tar.gz: adedca22595ab5066165c23004be9454b8594305bd1419f40df9d8a4823f37cab7c81bb097825ab34a4b75b116b8fd42370f7a204f7b2d43e0ed4c9ecef0dffc
|
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,44 @@
|
|
1
|
+
# puppet-lint no file resource path attributes
|
2
|
+
|
3
|
+
Extends puppet-lint to ensure all file resources use the resource
|
4
|
+
title to indicate the file to manage rather than a symbolic name
|
5
|
+
and the `path` attribute.
|
6
|
+
|
7
|
+
Instead of this:
|
8
|
+
|
9
|
+
class path_attribute {
|
10
|
+
file { 'ssh_config_file':
|
11
|
+
path => '/etc/ssh/sshd_config',
|
12
|
+
content => 'Bad path attribute, bad.',
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
I think, and this check complains unless, you use this format:
|
17
|
+
|
18
|
+
class good_namevar {
|
19
|
+
file { '/etc/ssh/sshd_config':
|
20
|
+
content => 'Good namevar',
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
There is nothing technically wrong with the first form but I'd rather
|
25
|
+
know what the resource type is, and what it manages, without having to read further in to the resouece.
|
26
|
+
Oddly I have no issues with `exec` resources with `command` attributes being
|
27
|
+
[written in this style](http://www.puppetcookbook.com/posts/nicer-exec-names.html).
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
To use this plugin add the following line to your Gemfile
|
32
|
+
|
33
|
+
gem 'puppet-lint-no_file_path_attribute-check'
|
34
|
+
|
35
|
+
and then run `bundle install`.
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
This plugin provides a new check to `puppet-lint`.
|
40
|
+
|
41
|
+
file resources should not have a path attribute. Use the title instead
|
42
|
+
|
43
|
+
### Author
|
44
|
+
[Dean Wilson](http://www.unixdaemon.net)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
PuppetLint.new_check(:no_file_path_attribute) 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 == 'path'
|
8
|
+
}.each do |param_token|
|
9
|
+
value_token = param_token.next_code_token.next_code_token
|
10
|
+
|
11
|
+
notify :warning, {
|
12
|
+
message: 'file resources should not have a path attribute. Use the title instead',
|
13
|
+
line: value_token.line,
|
14
|
+
column: value_token.column,
|
15
|
+
token: value_token
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'no_file_path_attribute' do
|
4
|
+
|
5
|
+
let(:msg) { 'file resources should not have a path attribute. Use the title instead' }
|
6
|
+
|
7
|
+
context 'file with a full path title' do
|
8
|
+
let(:code) do
|
9
|
+
<<-EOS
|
10
|
+
class good_namevar {
|
11
|
+
file { '/tmp/good_namevar':
|
12
|
+
content => 'Good namevar',
|
13
|
+
}
|
14
|
+
}
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not detect any problems' do
|
19
|
+
expect(problems).to have(0).problems
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'file with path attribute' do
|
24
|
+
let(:code) do
|
25
|
+
<<-EOS
|
26
|
+
class path_attribute {
|
27
|
+
file { 'bad_namevar':
|
28
|
+
path => '/tmp/bad_path_attr',
|
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(21)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-no_file_path_attribute-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-08-04 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
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-its
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-collection_matchers
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: |2
|
90
|
+
Extends puppet-lint to ensure file resources do not have a path attribute.
|
91
|
+
email: dean.wilson@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- lib/puppet-lint/plugins/no_file_path_attribute.rb
|
99
|
+
- spec/puppet-lint/plugins/puppet-lint-no_file_path_attribute_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: https://github.com/deanwilson/puppet-lint-no_file_path_attribute-check
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.8
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: puppet-lint no_file_path_attribute check
|
125
|
+
test_files:
|
126
|
+
- spec/puppet-lint/plugins/puppet-lint-no_file_path_attribute_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
has_rdoc:
|