puppet-lint-global_definition-check 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83f49eb058c88589fba6ae40663949eedb9d23c76b4b0611b10b138569ad6a91
4
+ data.tar.gz: 41b8e536eb95df3fdc0d3755dae5195f15bd906dfdd54bb4409cbed17809ec6b
5
+ SHA512:
6
+ metadata.gz: 16bc7ad6b276ad7491dbc5200929c6bb58e9a13f7af17cb1b6f84782c947e0d61c051a1d4fb9ef603b90c3f91853a5b3427b7da9f59d523b9d0ab3d295c5f234
7
+ data.tar.gz: a955faeb4f1cef540723ab8f11c37e8c1fe96c3a52566a3c1e8809fe8026dab940b13c9a16b2bd2dc2b4debbc6499bc69e275b8cd052b7e8db0fa6b5b7bcfdec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # puppet-lint global definition check
2
+
3
+ [![rspec](https://github.com/ninech/puppet-lint-global_definition-check/actions/workflows/rspec.yml/badge.svg)](https://github.com/ninech/puppet-lint-global_definition-check/actions/workflows/rspec.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/puppet-lint-global_definition-check.svg)](https://badge.fury.io/rb/puppet-lint-global_definition-check)
5
+
6
+ ## Installation
7
+
8
+ To use this plugin, add the following like to the Gemfile in your Puppet code
9
+ base and run `bundle install`.
10
+
11
+ ```ruby
12
+ gem "puppet-lint-global_definition-check"
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ This plugin provides a new check to `puppet-lint`.
18
+
19
+ ### global_resource
20
+
21
+ **--fix support: No**
22
+
23
+ This check will raise a error for any global resource.
24
+
25
+ ```
26
+ ERROR: resource file in global space on line 19
27
+ ```
28
+
29
+ ### global_function
30
+
31
+ **--fix support: No**
32
+
33
+ This check will raise a error for any global function.
34
+
35
+ ```
36
+ ERROR: token ensure_resouce in global space on line 19
37
+ ```
38
+
39
+
@@ -0,0 +1,61 @@
1
+ module PuppetLintGlobalDefinionCheck
2
+ private
3
+
4
+ def check_for_global_token(type, value = nil)
5
+ global_tokens.each_with_index do |token, i|
6
+ next unless token.type == type
7
+ next unless value.nil? || token.value == value
8
+
9
+ message = value.nil? ? token.value : "#{token.value} #{token.next_code_token.value}"
10
+
11
+ notify :error,
12
+ message: "definition #{message} in global space",
13
+ line: token.line,
14
+ column: token.column
15
+ end
16
+ end
17
+
18
+ def global_tokens
19
+ @global_tokens ||= tokens.reject.with_index { |_, i| secure_ranges.any? { |s| s[0] < i && s[1] > i } }
20
+ end
21
+
22
+ def secure_ranges
23
+ return @secure_ranges if @secure_ranges
24
+
25
+ @secure_ranges = []
26
+
27
+ class_indexes.each { |c| @secure_ranges << [c[:start], c[:end]] }
28
+ defined_type_indexes.each { |d| @secure_ranges << [d[:start], d[:end]] }
29
+ node_indexes.each { |n| @secure_ranges << [n[:start], n[:end]] }
30
+
31
+ @secure_ranges
32
+ end
33
+ end
34
+
35
+ PuppetLint.new_check(:global_resource) do
36
+ include PuppetLintGlobalDefinionCheck
37
+
38
+ def check
39
+ check_for_global_resources
40
+ check_for_global_token(:NAME, "include")
41
+ end
42
+
43
+ def check_for_global_resources
44
+ resource_indexes.each do |r|
45
+ next if secure_ranges.any? { |s| s[0] < r[:start] && s[1] > r[:end] }
46
+
47
+ notify :error,
48
+ message: "resource #{r[:type].value} in global space",
49
+ line: r[:type].line,
50
+ column: r[:type].column
51
+ end
52
+ end
53
+ end
54
+
55
+ PuppetLint.new_check(:global_function) do
56
+ include PuppetLintGlobalDefinionCheck
57
+
58
+ def check
59
+ check_for_global_token(:FUNCTION_NAME)
60
+ end
61
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ describe "global_resource" do
4
+ context "just a class" do
5
+ let(:code) { "class test { file { 'file': } }" }
6
+
7
+ it "should not detect any problems" do
8
+ expect(problems).to have(0).problems
9
+ end
10
+ end
11
+
12
+ context "just a define" do
13
+ let(:code) { "define test ($param = undef) { file { 'file': } }" }
14
+
15
+ it "should not detect any problems" do
16
+ expect(problems).to have(0).problems
17
+ end
18
+ end
19
+
20
+ context "allow node resources" do
21
+ let(:code) { "node 'test' { file { 'file': } }" }
22
+
23
+ it "should not detect any problems" do
24
+ expect(problems).to have(0).problems
25
+ end
26
+ end
27
+
28
+ context "global file" do
29
+ let(:code) do
30
+ "file { 'file': } define test ($param = undef) { file { 'file': } }"
31
+ end
32
+
33
+ it "should detect a problem" do
34
+ expect(problems).to have(1).problems
35
+ end
36
+ end
37
+
38
+ context "global includes" do
39
+ let(:code) { "class test { file { 'file': } } \ninclude testclass" }
40
+
41
+ it "should detect a problem" do
42
+ expect(problems).to have(1).problems
43
+ end
44
+ end
45
+
46
+ context "global defaults" do
47
+ let(:code) do
48
+ <<-EOS
49
+ Exec {
50
+ path => '/usr/bin:/usr/sbin/:/bin:/sbin',
51
+ }
52
+ EOS
53
+ end
54
+
55
+ it "should not detect any problems" do
56
+ expect(problems).to have(0).problems
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe "global_function" do
4
+ context "just a function" do
5
+ let(:code) do
6
+ <<-EOS
7
+ class test {
8
+ ensure_packages(['wordpress']);
9
+ }
10
+ EOS
11
+ end
12
+
13
+ it "should not detect any problems" do
14
+ expect(problems).to have(0).problems
15
+ end
16
+ end
17
+
18
+ context "global functions" do
19
+ let(:code) do
20
+ <<-EOS
21
+ class test {
22
+ ensure_packages(['wordpress']);
23
+ }
24
+
25
+ ensure_packages(['wordpress']);
26
+ EOS
27
+ end
28
+
29
+ it "should detect a problem" do
30
+ expect(problems).to have(1).problems
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ require "puppet-lint"
2
+ require "simplecov"
3
+ require "simplecov-console"
4
+
5
+ PuppetLint::Plugins.load_spec_helper
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::Console
8
+ SimpleCov.start do
9
+ add_filter "/spec"
10
+ add_filter ".bundle"
11
+ add_filter "/vendor"
12
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-global_definition-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Nine Internet Solutions AG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-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: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
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.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-json_expectations
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: rake
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: standardrb
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
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-console
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: " Extends puppet-lint to ensure that your manifests have no global
126
+ resources.\n"
127
+ email: support@nine.ch
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - README.md
133
+ - lib/puppet-lint/plugins/check_global_definition.rb
134
+ - spec/puppet-lint/plugins/check_global_function_spec.rb
135
+ - spec/puppet-lint/plugins/check_global_resource_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: https://github.com/ninech/puppet-lint-global_definition-check
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubygems_version: 3.4.10
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: puppet-lint checks for global definions
160
+ test_files: []