cem_data_processor 1.1.1

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: 30b9716893437609b27c5d18d4aa912e5c04b5a27b6f5ab98eefa4d9c76b5787
4
+ data.tar.gz: 615317f6b263cb0d48ee756fd713d626dc66e42fa9be2f67f9e4efcf1676dc15
5
+ SHA512:
6
+ metadata.gz: d9b3008b8df80393129d015c87027f3d9bd845529070867d1d11e7680379d4ee24e869751ba47bf094e4f11f2d2db6d2ce5579700fc320fefc38c9539f013887
7
+ data.tar.gz: 812cd1760f6e80045f6060a3f4c11e627347ea69c5ba8d3c8ee6e7c73b6c940353d603fcc7201ac39d7b155cfeec08ee39abac88bbef1da390f075c3ffbbb18f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at abide-team@puppet.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source ENV['GEM_SOURCE'] || "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in abide-data-processor.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+
data/Gemfile.lock ADDED
@@ -0,0 +1,179 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cem_data_processor (1.1.1)
5
+ deep_merge (~> 1.2)
6
+ rgl (~> 0.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.4.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ addressable (2.8.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ ast (2.4.2)
20
+ async (1.30.1)
21
+ console (~> 1.10)
22
+ nio4r (~> 2.3)
23
+ timers (~> 4.1)
24
+ async-http (0.56.5)
25
+ async (>= 1.25)
26
+ async-io (>= 1.28)
27
+ async-pool (>= 0.2)
28
+ protocol-http (~> 0.22.0)
29
+ protocol-http1 (~> 0.14.0)
30
+ protocol-http2 (~> 0.14.0)
31
+ async-http-faraday (0.11.0)
32
+ async-http (~> 0.42)
33
+ faraday
34
+ async-io (1.32.2)
35
+ async
36
+ async-pool (0.3.9)
37
+ async (>= 1.25)
38
+ byebug (11.1.3)
39
+ coderay (1.1.3)
40
+ concurrent-ruby (1.1.9)
41
+ console (1.13.1)
42
+ fiber-local
43
+ deep_merge (1.2.2)
44
+ diff-lcs (1.4.4)
45
+ faraday (1.8.0)
46
+ faraday-em_http (~> 1.0)
47
+ faraday-em_synchrony (~> 1.0)
48
+ faraday-excon (~> 1.1)
49
+ faraday-httpclient (~> 1.0.1)
50
+ faraday-net_http (~> 1.0)
51
+ faraday-net_http_persistent (~> 1.1)
52
+ faraday-patron (~> 1.0)
53
+ faraday-rack (~> 1.0)
54
+ multipart-post (>= 1.2, < 3)
55
+ ruby2_keywords (>= 0.0.4)
56
+ faraday-em_http (1.0.0)
57
+ faraday-em_synchrony (1.0.0)
58
+ faraday-excon (1.1.0)
59
+ faraday-http-cache (2.2.0)
60
+ faraday (>= 0.8)
61
+ faraday-httpclient (1.0.1)
62
+ faraday-net_http (1.0.1)
63
+ faraday-net_http_persistent (1.2.0)
64
+ faraday-patron (1.0.0)
65
+ faraday-rack (1.0.0)
66
+ fast_gettext (1.8.0)
67
+ fiber-local (1.0.0)
68
+ gem-release (2.2.2)
69
+ generator (0.0.1)
70
+ github_changelog_generator (1.16.4)
71
+ activesupport
72
+ async (>= 1.25.0)
73
+ async-http-faraday
74
+ faraday-http-cache
75
+ multi_json
76
+ octokit (~> 4.6)
77
+ rainbow (>= 2.2.1)
78
+ rake (>= 10.0)
79
+ i18n (1.8.10)
80
+ concurrent-ruby (~> 1.0)
81
+ lazy_priority_queue (0.1.1)
82
+ method_source (1.0.0)
83
+ minitest (5.14.4)
84
+ multi_json (1.15.0)
85
+ multipart-post (2.1.1)
86
+ nio4r (2.5.8)
87
+ octokit (4.21.0)
88
+ faraday (>= 0.9)
89
+ sawyer (~> 0.8.0, >= 0.5.3)
90
+ parallel (1.21.0)
91
+ parser (3.0.2.0)
92
+ ast (~> 2.4.1)
93
+ protocol-hpack (1.4.2)
94
+ protocol-http (0.22.5)
95
+ protocol-http1 (0.14.2)
96
+ protocol-http (~> 0.22)
97
+ protocol-http2 (0.14.2)
98
+ protocol-hpack (~> 1.4)
99
+ protocol-http (~> 0.18)
100
+ pry (0.14.1)
101
+ coderay (~> 1.1)
102
+ method_source (~> 1.0)
103
+ pry-byebug (3.8.0)
104
+ byebug (~> 11.0)
105
+ pry (~> 0.10)
106
+ public_suffix (4.0.6)
107
+ rainbow (3.0.0)
108
+ rake (12.3.3)
109
+ regexp_parser (2.1.1)
110
+ rexml (3.2.5)
111
+ rgl (0.5.7)
112
+ lazy_priority_queue (~> 0.1.0)
113
+ stream (~> 0.5.3)
114
+ rspec (3.10.0)
115
+ rspec-core (~> 3.10.0)
116
+ rspec-expectations (~> 3.10.0)
117
+ rspec-mocks (~> 3.10.0)
118
+ rspec-core (3.10.1)
119
+ rspec-support (~> 3.10.0)
120
+ rspec-expectations (3.10.1)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.10.0)
123
+ rspec-mocks (3.10.2)
124
+ diff-lcs (>= 1.2.0, < 2.0)
125
+ rspec-support (~> 3.10.0)
126
+ rspec-support (3.10.2)
127
+ rubocop (1.22.3)
128
+ parallel (~> 1.10)
129
+ parser (>= 3.0.0.0)
130
+ rainbow (>= 2.2.2, < 4.0)
131
+ regexp_parser (>= 1.8, < 3.0)
132
+ rexml
133
+ rubocop-ast (>= 1.12.0, < 2.0)
134
+ ruby-progressbar (~> 1.7)
135
+ unicode-display_width (>= 1.4.0, < 3.0)
136
+ rubocop-ast (1.12.0)
137
+ parser (>= 3.0.1.1)
138
+ rubocop-i18n (3.0.0)
139
+ rubocop (~> 1.0)
140
+ rubocop-performance (1.11.5)
141
+ rubocop (>= 1.7.0, < 2.0)
142
+ rubocop-ast (>= 0.4.0)
143
+ rubocop-rspec (2.5.0)
144
+ rubocop (~> 1.19)
145
+ ruby-progressbar (1.11.0)
146
+ ruby2_keywords (0.0.5)
147
+ sawyer (0.8.2)
148
+ addressable (>= 2.3.5)
149
+ faraday (> 0.8, < 2.0)
150
+ stream (0.5.3)
151
+ generator
152
+ timers (4.3.3)
153
+ tzinfo (2.0.4)
154
+ concurrent-ruby (~> 1.0)
155
+ unicode-display_width (2.1.0)
156
+ zeitwerk (2.5.1)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ bundler
163
+ cem_data_processor!
164
+ console
165
+ fast_gettext (~> 1.8)
166
+ gem-release
167
+ github_changelog_generator
168
+ pry
169
+ pry-byebug
170
+ rake (~> 12.0)
171
+ rspec (~> 3.0)
172
+ rubocop (~> 1.8)
173
+ rubocop-ast (~> 1.4)
174
+ rubocop-i18n (~> 3.0)
175
+ rubocop-performance (~> 1.9)
176
+ rubocop-rspec (~> 2.1)
177
+
178
+ BUNDLED WITH
179
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tu2607
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,308 @@
1
+ # Cem_Data_Processor
2
+
3
+ This gem provides the functionality to process data parsed from a Hiera file for Puppetlabs CEM modules.
4
+
5
+ - [Cem_Data_Processor](#cem_data_processor)
6
+ - [About the Gem](#about-the-gem)
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [Development](#development)
10
+ - [CEM Resource Data Specification](#cem-resource-data-specification)
11
+ - [1: Meta Information](#1-meta-information)
12
+ - [2: Common.yaml](#2-commonyaml)
13
+ - [3: Top-level key](#3-top-level-key)
14
+ - [4: Resources](#4-resources)
15
+ - [4.1: Tile Key](#41-tile-key)
16
+ - [Example 4.1.1 - Basic plain-text title key](#example-411---basic-plain-text-title-key)
17
+ - [Example 4.1.2 - File path title key](#example-412---file-path-title-key)
18
+ - [4.2: Type](#42-type)
19
+ - [Example 4.2.1 - Basic type property](#example-421---basic-type-property)
20
+ - [Example 4.2.2 - Complex type property](#example-422---complex-type-property)
21
+ - [5: Controls](#5-controls)
22
+ - [Example 5.1 - Basic controls property](#example-51---basic-controls-property)
23
+ - [Example 5.2 - Multiple controls map to the same parameter and value](#example-52---multiple-controls-map-to-the-same-parameter-and-value)
24
+ - [Example 5.3 - Multiple controls map to the same parameter with different values](#example-53---multiple-controls-map-to-the-same-parameter-with-different-values)
25
+ - [Example 5.4 - One control maps to multiple different parameters](#example-54---one-control-maps-to-multiple-different-parameters)
26
+ - [Example 5.5 - A control does not supply parameters, but maps to the whole resource](#example-55---a-control-does-not-supply-parameters-but-maps-to-the-whole-resource)
27
+ - [6: Metaparameters](#6-metaparameters)
28
+ - [Example 6.0.1 - Declaring metaparameters](#example-601---declaring-metaparameters)
29
+ - [Example 6.0.1.1 - Declaring a metaparameter at the resource level](#example-6011---declaring-a-metaparameter-at-the-resource-level)
30
+ - [Example 6.0.1.2 - Declaring a metaparameter at the control level](#example-6012---declaring-a-metaparameter-at-the-control-level)
31
+ - [6.1: Dependent](#61-dependent)
32
+
33
+ ## About the Gem
34
+
35
+ ### Installation
36
+
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'cem_data_processor'
41
+ ```
42
+
43
+ And then execute:
44
+
45
+ $ bundle install
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install cem_data_processor
50
+
51
+ ### Usage
52
+
53
+ Since this gem is more of a library, there is no executable to run it. This gem is designed to be use by Puppetlabs CEM modules to process the data that those modules generate.
54
+
55
+ ### Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## CEM Resource Data Specification
62
+
63
+ CEM resource data is the basis for how the CEM modules know what code to enforce, and how, for each of our supported compliance frameworks. Resource data is implemented as module-level Hiera data in each of the CEM modules. The goal of resource data is to provide detailed information about how specific Puppet resources and their parameters enforce compliance standards, which is then used in the modules to include the correct Puppet resources and values in the catalog. This is included in this repo because the data processor is the parser for CEM resource data.
64
+
65
+ ### 1: Meta Information
66
+
67
+ - File Type: [YAML version 1.2](https://yaml.org/spec/1.2.2)
68
+ - File Extension: `.yaml`
69
+ - Base Directory: `data/`
70
+ - Hiera hierarchy levels:
71
+ - `%{facts.os.family}/%{facts.os.name}/%{facts.os.release.major}.yaml`
72
+ - `%{facts.os.family}/%{facts.os.name}.yaml`
73
+ - `%{facts.os.family}/%{facts.os.release.major}.yaml`
74
+ - `%{facts.os.family}.yaml`
75
+ - `common.yaml`
76
+
77
+ ### 2: Common.yaml
78
+
79
+ `common.yaml` must declare lookup options for the key `<module name>::resources:` as follows:
80
+
81
+ ```yaml
82
+ lookup_options:
83
+ <module name>::resources:
84
+ merge:
85
+ strategy: deep
86
+ merge_hash_arrays: true
87
+ ```
88
+
89
+ ### 3: Top-level key
90
+
91
+ There must only be one top-level key in each resource data file. This key serves as a universal lookup key for the entire data structure. The top-level key in each resource data file must follow the convention: `<module name>::resources:`.
92
+
93
+ ### 4: Resources
94
+
95
+ Under the top-level key, all sub-hashes constitute a singular Puppet resource, whether that resource is a `class`, a `defined type`, etc. Each resource consists of a [title-key](#41-title-key), a [type](#42-type), various [controls](#5-controls), and optional [metaparameters](#6-metaparameters).
96
+
97
+ #### 4.1: Tile Key
98
+
99
+ Title keys exist beneath the top-level key. There may be any amount of title keys. Title keys must consist of resource titles. A resource title is the unique string assigned to a Puppet resource after it's type declaration:
100
+
101
+ ```ruby
102
+ exec { 'This is the resource title':
103
+ ...
104
+ }
105
+ ```
106
+
107
+ Title keys must be unique once the entire data structure is resolved via Hiera lookup. This is partially because Puppet resource names must be unique in Puppet manifests, but also because keys at the same level in Ruby hashes must be unique. This requirement is less flexible than resource naming in Puppet itself, because types with multiple name variables that are combined to make the actual resource name are not considered.
108
+
109
+ ##### Example 4.1.1 - Basic plain-text title key
110
+
111
+ ```yaml
112
+ <module name>::resources:
113
+ 'This is the resource title':
114
+ ...
115
+ ```
116
+
117
+ ##### Example 4.1.2 - File path title key
118
+
119
+ ```yaml
120
+ <module name>::resources:
121
+ '/opt/puppetlabs/cem/test_file.txt':
122
+ ```
123
+
124
+ In this example, we specify a file path that would be used by a Puppet resource such as `file`. However, we cannot use the file path `/opt/puppetlabs/cem/test_file.txt` again as a title key.
125
+
126
+ #### 4.2: Type
127
+
128
+ Type is a property of a resource defined by a title key. Type must be a Puppet resource type. When Puppet resources are created during catalog compilation, this is the type of resource that will be created.
129
+
130
+ ```ruby
131
+ this_is_the_resource_type { 'This is the resource title':
132
+ ...
133
+ }
134
+ ```
135
+
136
+ Type is defined as a single key-value pair under the title key.
137
+
138
+ #### Example 4.2.1 - Basic type property
139
+
140
+ ```yaml
141
+ <module name>::resources:
142
+ 'This is the resource title':
143
+ type: exec
144
+ ```
145
+
146
+ #### Example 4.2.2 - Complex type property
147
+
148
+ ```yaml
149
+ <module name>::resources:
150
+ 'This is the resource title':
151
+ type: 'cem_linux::utils::bootloader::grub2::password'
152
+ ```
153
+
154
+ ### 5: Controls
155
+
156
+ Controls is a property of a resource that maps compliance framework controls to the various Puppet resource parameters that those controls are concerned with. Each mapping in controls consists of one or more keys that use an compliance control identifier.
157
+
158
+ #### Example 5.1 - Basic controls property
159
+
160
+ We have a compliance framework that defines a control 'Ensure you run the ls command'. The Puppet code to enforce this control looks like this:
161
+
162
+ ```ruby
163
+ # Enforces 'Ensure you run the ls command
164
+ exec { 'This is the resource title':
165
+ command => 'ls',
166
+ }
167
+ ```
168
+
169
+ The above Puppet code translates to the following resource data:
170
+
171
+ ```yaml
172
+ <module name>::resources:
173
+ 'This is the resource title':
174
+ type: exec
175
+ controls:
176
+ 'Ensure you run the ls command':
177
+ command: 'ls'
178
+ ```
179
+
180
+ #### Example 5.2 - Multiple controls map to the same parameter and value
181
+
182
+ We have two compliance frameworks. Both frameworks define a control that is equal in all but name. Framework 1 defines the control 'Ensure you run the ls command' and Framework 2 defines the control 'The ls command must be ran'. The Puppet code to enforce this control looks like this:
183
+
184
+ ```ruby
185
+ # Framework 1 - Enforces 'Ensure you run the ls command
186
+ # Framework 2 - The ls command must be ran
187
+ exec { 'This is the resource title':
188
+ command => 'ls',
189
+ }
190
+ ```
191
+
192
+ The above Puppet code translates to the following resource data:
193
+
194
+ ```yaml
195
+ <module name>::resources:
196
+ 'This is the resource title':
197
+ type: exec
198
+ controls:
199
+ ? - 'Ensure you run the ls command'
200
+ - 'The ls command must be ran'
201
+ : command: 'ls'
202
+ ```
203
+
204
+ When two or more controls map to the same parameter and the same value, [YAML complex mapping keys](https://yaml.org/spec/1.2.2/#22-structures) must be used.
205
+
206
+ #### Example 5.3 - Multiple controls map to the same parameter with different values
207
+
208
+ ```yaml
209
+ <module name>::resources:
210
+ 'This is the resource title':
211
+ type: exec
212
+ controls:
213
+ 'Ensure you run the ls command':
214
+ command: 'ls'
215
+ 'The ls -l command must be ran':
216
+ command: 'ls -l'
217
+ ```
218
+
219
+ #### Example 5.4 - One control maps to multiple different parameters
220
+
221
+ ```yaml
222
+ <module name>::resources:
223
+ 'This is the resource title':
224
+ type: exec
225
+ controls:
226
+ 'Ensure you run the ls command only if test.txt exists':
227
+ command: 'ls'
228
+ onlyif: 'test -f test.txt'
229
+ ```
230
+
231
+ When the Puppet resources are created from resource data during catalog compilation, the resources `cem_linux::utils::packages::absenter { 'avahi': }` and `cem_linux::utils::packages::absenter { 'avahi-autoipd': }` will be created before the resource `cem_linux::utils::disable_service { 'avahi-daemon': }`. You do not need any other resource data to specify `cem_linux::utils::packages::absenter { 'avahi': }` and `cem_linux::utils::packages::absenter { 'avahi-autoipd': }`.
232
+
233
+ #### Example 5.5 - A control does not supply parameters, but maps to the whole resource
234
+
235
+ Sometimes, controls will not map to specific resource parameters but to the whole resource itself. This is often the case with resources that represent defined types with very specific functionality. In this case, the `controls` key must be an `Array`, not a `Hash`. Each item of that `Array` must be a control name that maps to the declared resource.
236
+
237
+ Below is an example of Puppet code where the control would not manage a parameter:
238
+
239
+ ```ruby
240
+ cem_linux::utils::disable_service { 'avahi-daemon': }
241
+ ```
242
+
243
+ With this particular defined type, the resource title can also serve as the one and only parameter. In resource data, we declares a resource with `control` as an `Array`.
244
+
245
+ ```yaml
246
+ cem_linux::resources:
247
+ 'avahi-daemon':
248
+ type: 'cem_linux::utils::disable_service'
249
+ controls:
250
+ - 'Ensure Avahi server is not installed'
251
+ ```
252
+
253
+ ### 6: Metaparameters
254
+
255
+ Both resources and controls support five metaparameters: [before](#61-before), [require](#62-require), [notify](#63-notify), [subscribe](#64-subscribe), and [dependent](#65-dependent). Metaparameters are used for ordering resources, and are used just as they are in Puppet code. Dependent is a special metaparameter with no Puppet code equivalent. Metaparameters are applied to a resource either directly, by declaring a metaparameter key at the same level as the `type` key or the `controls` key, or at the control level just as you would declare control parameters. Regardless of if a metaparameter is declared at the resource or control level, the metaparameter applies to the whole resource.
256
+
257
+ #### Example 6.0.1 - Declaring metaparameters
258
+
259
+ Below is an example of Puppet code that uses the Puppet metaparameter `before`:
260
+
261
+ ```ruby
262
+ cem_linux::utils::disable_service { 'avahi-daemon':
263
+ before => [
264
+ Cem_linux::Utils::Packages::Absenter['avahi'],
265
+ Cem_linux::Utils::Packages::Absenter['avahi-autoipd'],
266
+ ],
267
+ }
268
+ ```
269
+
270
+ This Puppet code infers, through the use of Puppet resource references, that the Puppet resources `cem_linux::utils::packages::absenter { 'avahi': }` and `cem_linux::utils::packages::absenter { 'avahi-autoipd': }` are declared somewhere in the manifest. In resource data, we declare the dependent resources in the metaparameter itself.
271
+
272
+ There is no need for resources declared in metaparameters to exist already in resource data. Additionally, if a resource declared in resource data is also declared in a metaparameter, only one copy of that resource will be created.
273
+
274
+ ##### Example 6.0.1.1 - Declaring a metaparameter at the resource level
275
+
276
+ ```yaml
277
+ cem_linux::resources:
278
+ 'avahi-daemon':
279
+ type: 'cem_linux::utils::disable_service'
280
+ before:
281
+ 'avahi-autoipd':
282
+ type: 'cem_linux::utils::packages::absenter'
283
+ 'avahi':
284
+ type: 'cem_linux::utils::packages::absenter'
285
+ controls:
286
+ - 'Ensure Avahi server is not installed'
287
+ ```
288
+
289
+ ##### Example 6.0.1.2 - Declaring a metaparameter at the control level
290
+
291
+ ```yaml
292
+ cem_linux::resources:
293
+ 'avahi-daemon':
294
+ type: 'cem_linux::utils::disable_service'
295
+ controls:
296
+ 'Ensure Avahi server is not installed':
297
+ before:
298
+ 'avahi-autoipd':
299
+ type: 'cem_linux::utils::packages::absenter'
300
+ 'avahi':
301
+ type: 'cem_linux::utils::packages::absenter'
302
+ ```
303
+
304
+ When the Puppet resources are created from resource data during catalog compilation, the resources `cem_linux::utils::packages::absenter { 'avahi': }` and `cem_linux::utils::packages::absenter { 'avahi-autoipd': }` will be created before the resource `cem_linux::utils::disable_service { 'avahi-daemon': }`.
305
+
306
+ #### 6.1: Dependent
307
+
308
+ Dependent is a special metaparameter used in resource data used to ensure mutual inclusion / exclusion of resources that depend on each other to function. When Resource A declares Resource B in the `dependent` metaparameter, Resource A will only be enforced if Resource B is included in the catalog as well. Dependent ensures that controls residing in the `ignore` list will not disrupt the entire catalog.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cem_data_processor"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here