puppet-lint-file_line_match-check 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0da08b397ff2bdee2ad4166ef3ab35aef98f4dd
4
+ data.tar.gz: 8dd4b743d771e576584ae72c99d2f7deb3ab5806
5
+ SHA512:
6
+ metadata.gz: 27c49f6836c6c79254e354dfdc56337e1e10f3d76cba005f7859dc838350568f3945836ea4a2fbe2d91768b63d74320b44a3202dbf94c08085f017a0ff2b6c7b
7
+ data.tar.gz: f8a2f17efa13db1a00436bd2c66598b558b2f4b7a28486da1c3c183be6e95a170c14f1df19d324343ea8cd5ae1db83236f6f40da2c7540c8ff1240ce4389b688
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Chris Spence
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.
@@ -0,0 +1,7 @@
1
+ # Puppet lint check for file_line resources
2
+
3
+ [![Build Status](https://travis-ci.org/tolleiv/puppet-lint-file_line_match-check.png?branch=master)](https://travis-ci.org/tolleiv/puppet-lint-file_line_match-check)
4
+
5
+ We found that using file\_line without a match attrbite is dangerous in our setup.
6
+ Therefore this check implements a warning in case the match is missing.
7
+
@@ -0,0 +1,20 @@
1
+ PuppetLint.new_check(:file_line_match) do
2
+ def check
3
+
4
+ resource_indexes.each do |resource|
5
+ if resource[:type].value == "file_line"
6
+ matches = resource[:param_tokens].select { |param_token|
7
+ param_token.value == 'match'
8
+ }
9
+ unless matches.length == 1
10
+ tkn = resource[:tokens].first
11
+ notify :warning, {
12
+ :message => 'expected one match attribute for file_line resource',
13
+ :line => tkn.line,
14
+ :column => tkn.column,
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'file_line_match' do
4
+ let(:msg) { 'expected one match attribute for file_line resource' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'code with missing match attribute' do
8
+ let(:code) { "
9
+ file { '/tmp/foo':
10
+ ensure => present,
11
+ foo => bar,
12
+ baz => gronk,
13
+ foo => meh,
14
+ }
15
+ file_line { 'sudo_rule':
16
+ path => '/etc/sudoers',
17
+ line => '%sudo ALL=(ALL) ALL',
18
+ }" }
19
+
20
+ it 'should detect a single problem' do
21
+ expect(problems).to have(1).problem
22
+ end
23
+
24
+ it 'should create a warning' do
25
+ expect(problems).to contain_warning(msg).on_line(8).in_column(31)
26
+ end
27
+ end
28
+ context 'code with duplicate match attribute' do
29
+ let(:code) { "
30
+ file_line { 'sudo_rule':
31
+ path => '/etc/sudoers',
32
+ match => '^export\\ HTTP_PROXY\\=',
33
+ line => '%sudo ALL=(ALL) ALL',
34
+ match => '^export\\ HTTP_PROXY\\=',
35
+ }" }
36
+
37
+ it 'should detect a single problem' do
38
+ expect(problems).to have(1).problem
39
+ end
40
+
41
+ it 'should create a warning' do
42
+ expect(problems).to contain_warning(msg).on_line(2).in_column(31)
43
+ end
44
+ end
45
+
46
+ context 'code with a match attribute' do
47
+ let(:code) { "
48
+ file_line { 'bashrc_proxy':
49
+ ensure => present,
50
+ path => '/etc/bashrc',
51
+ line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
52
+ match => '^export\\ HTTP_PROXY\\=',
53
+ }" }
54
+
55
+ it 'should not detect any problems' do
56
+ expect(problems).to have(0).problems
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,4 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
4
+
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-file_line_match-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tolleiv Nietsch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-22 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 whether all file_line resources have a match condition.
85
+ That's important to avoid that file_line screws up the file-content.
86
+ email: tolleiv.nietsch@aoe.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - LICENSE
92
+ - README.md
93
+ - lib/puppet-lint/plugins/check_file_line_match.rb
94
+ - spec/puppet-lint/plugins/check_file_line_match_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/tolleiv/puppet-lint-file_line_match-check
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.6
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A puppet-lint plugin to check whether all file_line resources have a match
120
+ condition.
121
+ test_files:
122
+ - spec/puppet-lint/plugins/check_file_line_match_spec.rb
123
+ - spec/spec_helper.rb