abide-data-processor 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1cf0d51193e415d28a53c2a7df576732981eb3f1c29525c0a44877f2e93e72c9
4
+ data.tar.gz: cd92db097e219d4c11fa72ee7d170d31e3b19681aba9344d8fb2ef0ba18add43
5
+ SHA512:
6
+ metadata.gz: 42c937bf2d75784db736ab8a13e9e0bc5295efa897c33a6bf9c9a4e0c89504860864b4f12db8632017e6cdce9e8ba339885df01e4271eacacc6244c68cb6858f
7
+ data.tar.gz: 2fe1ef9eeaeaa77ff578e3d53f41a46c73f181d81db0b4e133823c961ec8d1cd2c04f12ebbfb048d53d7caa0f67c6cabd2ce80270a0ac4875b4f97e0f7e3f919
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,193 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ abide-data-processor (0.0.0)
5
+ puppet (>= 6.23)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.4.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ addressable (2.8.0)
17
+ public_suffix (>= 2.0.2, < 5.0)
18
+ ast (2.4.2)
19
+ async (1.30.1)
20
+ console (~> 1.10)
21
+ nio4r (~> 2.3)
22
+ timers (~> 4.1)
23
+ async-http (0.56.5)
24
+ async (>= 1.25)
25
+ async-io (>= 1.28)
26
+ async-pool (>= 0.2)
27
+ protocol-http (~> 0.22.0)
28
+ protocol-http1 (~> 0.14.0)
29
+ protocol-http2 (~> 0.14.0)
30
+ async-http-faraday (0.11.0)
31
+ async-http (~> 0.42)
32
+ faraday
33
+ async-io (1.32.2)
34
+ async
35
+ async-pool (0.3.9)
36
+ async (>= 1.25)
37
+ byebug (11.1.3)
38
+ coderay (1.1.3)
39
+ concurrent-ruby (1.1.9)
40
+ console (1.13.1)
41
+ fiber-local
42
+ deep_merge (1.2.1)
43
+ diff-lcs (1.4.4)
44
+ facter (4.2.5)
45
+ hocon (~> 1.3)
46
+ thor (>= 1.0.1, < 2.0)
47
+ faraday (1.8.0)
48
+ faraday-em_http (~> 1.0)
49
+ faraday-em_synchrony (~> 1.0)
50
+ faraday-excon (~> 1.1)
51
+ faraday-httpclient (~> 1.0.1)
52
+ faraday-net_http (~> 1.0)
53
+ faraday-net_http_persistent (~> 1.1)
54
+ faraday-patron (~> 1.0)
55
+ faraday-rack (~> 1.0)
56
+ multipart-post (>= 1.2, < 3)
57
+ ruby2_keywords (>= 0.0.4)
58
+ faraday-em_http (1.0.0)
59
+ faraday-em_synchrony (1.0.0)
60
+ faraday-excon (1.1.0)
61
+ faraday-http-cache (2.2.0)
62
+ faraday (>= 0.8)
63
+ faraday-httpclient (1.0.1)
64
+ faraday-net_http (1.0.1)
65
+ faraday-net_http_persistent (1.2.0)
66
+ faraday-patron (1.0.0)
67
+ faraday-rack (1.0.0)
68
+ fast_gettext (1.8.0)
69
+ fiber-local (1.0.0)
70
+ gem-release (2.2.2)
71
+ github_changelog_generator (1.16.4)
72
+ activesupport
73
+ async (>= 1.25.0)
74
+ async-http-faraday
75
+ faraday-http-cache
76
+ multi_json
77
+ octokit (~> 4.6)
78
+ rainbow (>= 2.2.1)
79
+ rake (>= 10.0)
80
+ hiera (3.7.0)
81
+ hocon (1.3.1)
82
+ i18n (1.8.10)
83
+ concurrent-ruby (~> 1.0)
84
+ locale (2.1.3)
85
+ method_source (1.0.0)
86
+ minitest (5.14.4)
87
+ multi_json (1.15.0)
88
+ multipart-post (2.1.1)
89
+ nio4r (2.5.8)
90
+ octokit (4.21.0)
91
+ faraday (>= 0.9)
92
+ sawyer (~> 0.8.0, >= 0.5.3)
93
+ parallel (1.21.0)
94
+ parser (3.0.2.0)
95
+ ast (~> 2.4.1)
96
+ protocol-hpack (1.4.2)
97
+ protocol-http (0.22.5)
98
+ protocol-http1 (0.14.2)
99
+ protocol-http (~> 0.22)
100
+ protocol-http2 (0.14.2)
101
+ protocol-hpack (~> 1.4)
102
+ protocol-http (~> 0.18)
103
+ pry (0.14.1)
104
+ coderay (~> 1.1)
105
+ method_source (~> 1.0)
106
+ pry-byebug (3.8.0)
107
+ byebug (~> 11.0)
108
+ pry (~> 0.10)
109
+ public_suffix (4.0.6)
110
+ puppet (7.12.0)
111
+ concurrent-ruby (~> 1.0)
112
+ deep_merge (~> 1.0)
113
+ facter (> 2.0.1, < 5)
114
+ fast_gettext (~> 1.1)
115
+ hiera (>= 3.2.1, < 4)
116
+ locale (~> 2.1)
117
+ multi_json (~> 1.10)
118
+ puppet-resource_api (~> 1.5)
119
+ scanf (~> 1.0)
120
+ semantic_puppet (~> 1.0)
121
+ puppet-resource_api (1.8.14)
122
+ hocon (>= 1.0)
123
+ rainbow (3.0.0)
124
+ rake (12.3.3)
125
+ regexp_parser (2.1.1)
126
+ rexml (3.2.5)
127
+ rspec (3.10.0)
128
+ rspec-core (~> 3.10.0)
129
+ rspec-expectations (~> 3.10.0)
130
+ rspec-mocks (~> 3.10.0)
131
+ rspec-core (3.10.1)
132
+ rspec-support (~> 3.10.0)
133
+ rspec-expectations (3.10.1)
134
+ diff-lcs (>= 1.2.0, < 2.0)
135
+ rspec-support (~> 3.10.0)
136
+ rspec-mocks (3.10.2)
137
+ diff-lcs (>= 1.2.0, < 2.0)
138
+ rspec-support (~> 3.10.0)
139
+ rspec-support (3.10.2)
140
+ rubocop (1.22.3)
141
+ parallel (~> 1.10)
142
+ parser (>= 3.0.0.0)
143
+ rainbow (>= 2.2.2, < 4.0)
144
+ regexp_parser (>= 1.8, < 3.0)
145
+ rexml
146
+ rubocop-ast (>= 1.12.0, < 2.0)
147
+ ruby-progressbar (~> 1.7)
148
+ unicode-display_width (>= 1.4.0, < 3.0)
149
+ rubocop-ast (1.12.0)
150
+ parser (>= 3.0.1.1)
151
+ rubocop-i18n (3.0.0)
152
+ rubocop (~> 1.0)
153
+ rubocop-performance (1.11.5)
154
+ rubocop (>= 1.7.0, < 2.0)
155
+ rubocop-ast (>= 0.4.0)
156
+ rubocop-rspec (2.5.0)
157
+ rubocop (~> 1.19)
158
+ ruby-progressbar (1.11.0)
159
+ ruby2_keywords (0.0.5)
160
+ sawyer (0.8.2)
161
+ addressable (>= 2.3.5)
162
+ faraday (> 0.8, < 2.0)
163
+ scanf (1.0.0)
164
+ semantic_puppet (1.0.4)
165
+ thor (1.1.0)
166
+ timers (4.3.3)
167
+ tzinfo (2.0.4)
168
+ concurrent-ruby (~> 1.0)
169
+ unicode-display_width (2.1.0)
170
+ zeitwerk (2.5.1)
171
+
172
+ PLATFORMS
173
+ ruby
174
+
175
+ DEPENDENCIES
176
+ abide-data-processor!
177
+ bundler
178
+ console
179
+ fast_gettext (~> 1.8)
180
+ gem-release
181
+ github_changelog_generator
182
+ pry
183
+ pry-byebug
184
+ rake (~> 12.0)
185
+ rspec (~> 3.0)
186
+ rubocop (~> 1.8)
187
+ rubocop-ast (~> 1.4)
188
+ rubocop-i18n (~> 3.0)
189
+ rubocop-performance (~> 1.9)
190
+ rubocop-rspec (~> 2.1)
191
+
192
+ BUNDLED WITH
193
+ 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,37 @@
1
+ # Abide-Data-Processor
2
+
3
+ This gem provides the functionality to process data parsed from a Hiera file for Puppetlabs CEM modules.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'abide-data-processor'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install abide-data-processor
20
+
21
+ ## Usage
22
+
23
+ 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.
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/puppetlabs/abide-data-processor.
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Abide-Data-Processor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/puppetlabs/abide-data-processor/blob/main/CODE_OF_CONDUCT.md).
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
@@ -0,0 +1,49 @@
1
+ require_relative 'lib/abide-data-processor/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "abide-data-processor"
5
+ spec.version = AbideDataProcessor::VERSION
6
+ spec.authors = ["abide-team"]
7
+ spec.email = ["abide-team@puppet.com"]
8
+
9
+ spec.summary = "Helper to process data for Puppetlabs CEM modules."
10
+ spec.description = "Provides functions that help with extracting out information from Hiera file."
11
+ spec.homepage = "https://github.com/puppetlabs/abide-data-processor"
12
+ spec.license = "Proprietary"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Prod dependencies
31
+ # I'm not too sure about this version
32
+ spec.add_dependency 'puppet', '>= 6.23'
33
+
34
+ # Dev dependencies
35
+ spec.add_development_dependency 'bundler'
36
+ spec.add_development_dependency 'rake'
37
+ spec.add_development_dependency 'console'
38
+ spec.add_development_dependency 'github_changelog_generator'
39
+ spec.add_development_dependency 'gem-release'
40
+ spec.add_development_dependency 'pry'
41
+ spec.add_development_dependency 'pry-byebug'
42
+ spec.add_development_dependency 'rspec', '~> 3.10'
43
+ spec.add_development_dependency 'rubocop', '~> 1.8'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
45
+ spec.add_development_dependency 'rubocop-ast', '~> 1.4'
46
+ spec.add_development_dependency 'rubocop-performance', '~> 1.9'
47
+ spec.add_development_dependency 'rubocop-i18n', '~> 3.0'
48
+ spec.add_development_dependency 'fast_gettext', '~> 1.8'
49
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "abide/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
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbideDataProcessor
4
+ module Processor
5
+ class Logger
6
+ LEVELS = {error: 1, warning: 2, info: 3, debug: 4}
7
+
8
+ def initialize(level = :info, out = STDOUT, err = STDERR)
9
+ @level = LEVELS[level]
10
+ if @level.nil?
11
+ raise ArgumentError, "Unknown log level at #{level}"
12
+ end
13
+
14
+ @out = out
15
+ @err = err
16
+ end
17
+
18
+ def debug(message)
19
+ if @level >= LEVELS[:debug]
20
+ @out.puts(message)
21
+ end
22
+ end
23
+
24
+ def inform(message)
25
+ if @level >= LEVELS[:info]
26
+ @out.puts(message)
27
+ end
28
+ end
29
+
30
+ def warn(message)
31
+ if @level >= LEVELS[:warning]
32
+ @out.puts(message)
33
+ end
34
+ end
35
+
36
+ def err(message)
37
+ if @level >= LEVELS[:error]
38
+ @err.puts(message)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,283 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'deep_merge'
4
+ require 'set'
5
+ require 'pry'
6
+
7
+ module AbideDataProcessor
8
+ module Processor
9
+ # Here lies the class that will be use to create/extract resources
10
+ class ResourceCreator
11
+
12
+ # @param control_maps: The control mappings to valid IDs
13
+ # @param module_name: The name of the module
14
+ # @param logger: The logger that we will use to log information for the user
15
+ def initialize(control_maps, module_name, logger)
16
+ @module_name = module_name
17
+ @control_maps = control_maps
18
+ @logger = logger
19
+ end
20
+
21
+ # control_key_maps
22
+ # Gets all control key maps from Hiera for indexed control ID permutation searches
23
+ # @return An array of four control ID maps, each indexed by one of the four different valid permutations of a control ID
24
+ def control_key_maps
25
+ key_prefix = "#{@module_name}::mappings::cis"
26
+ %w[hiera_title hiera_title_num number title].each_with_object([]) do |key, ary|
27
+ ary << [key_prefix, key].join('::')
28
+ end
29
+ end
30
+
31
+ def cis_hiera_key(prefix, key)
32
+ "#{prefix}::#{key}"
33
+ end
34
+
35
+ # create_resources
36
+ # @param resources_hash: the hash of controls to be enforces, user will provide this
37
+ # @param only: the list of controls to be enforce only, pulled from cis.pp
38
+ # @param ignore: the list of controls to be ignore, pulled from cis.pp
39
+ # @param control_configs: the custom control configurations pulled from cis.pp
40
+ # Return a hash to be convert to Puppet code.
41
+ def create_resources(resources_hash, only, ignore, control_configs)
42
+ resources = real_resources(resources_hash, only.to_set, ignore.to_set, control_configs)
43
+ ordered_resources = order_resources(resources)
44
+
45
+ mutate_ordering_params!(ordered_resources[1])
46
+ ordered_resources
47
+ end
48
+
49
+ # Everything else except the create_resource function will be private
50
+ private
51
+
52
+ # real_resources
53
+ # Formats a Hiera resources hash into a hash used by order_resources()
54
+ # @param resources_hash The raw resources hash pulled from hiera
55
+ # @param only The $only parameter from cis.pp
56
+ # @param ignore The $ignore parameter from cis.pp
57
+ # @param control_configs The $control_configs parameter from cis.pp
58
+ def real_resources(resources_hash, only, ignore, control_configs)
59
+ real_resources = {}
60
+ all_controls_name = Set.new # subject to change
61
+
62
+ # Grabbing all the control name here into a set
63
+ resources_hash.each do |_title, data|
64
+ all_controls_name |= data['controls'].keys.to_set
65
+ end
66
+
67
+ resources_hash.each do |title, data|
68
+ resource_params = if data.key?('controls')
69
+ extract_control_params(data['controls'], only, ignore, control_configs, all_controls_name)
70
+ else
71
+ {}
72
+ end
73
+ if real_resources.key?(data['type']) && real_resources[data['type']].key?(title)
74
+ real_resources[data['type']][title].deep_merge!(resource_params, merge_hash_arrays: true)
75
+ else
76
+ real_resources[data['type']] = { title => resource_params }
77
+ end
78
+ end
79
+ real_resources
80
+ end
81
+
82
+ # extract_control_params
83
+ # Extracts resource parameters from a Hiera resource hash item's `controls` key
84
+ # @param control_data The resource hash item's `controls` key-value pair (i.e. data['controls'])
85
+ # @param only The $only parameter from cis.pp
86
+ # @param ignore The $ignore parameter from cis.pp
87
+ # @param control_configs The $control_configs parameter from cis.pp
88
+ # @param all_controls_name: All of the controls name
89
+ def extract_control_params(control_data, only, ignore, control_configs, all_controls_name)
90
+ control_params = {}
91
+ control_data.each do |name, params|
92
+ name_map = map_for_control_name(name, @control_maps)
93
+
94
+ # Only and ignore list check
95
+ next unless only_and_ignore_check(name, name_map, only, ignore)
96
+
97
+ # Control dependent check
98
+ if params.key?('dependent')
99
+ unless dependent_check(all_controls_name, params['dependent'], ignore, only)
100
+ # Below is just a sure fire way to make sure that we will never use the resource
101
+ only.delete(name) # Remove from the only list
102
+ ignore.add(name) # Add the name of the current control to the ignore list if we're not gonna enforce it
103
+ @logger.inform("Control #{name} will not be enforced because the controls that it depends on is invalid.")
104
+ next
105
+ end
106
+ end
107
+ # Find if there are any custom control configs from the cis.pp based on the control's name and its permutation
108
+ customized = find_control_customization(name, name_map[name], control_configs)
109
+ params.deep_merge!(customized, merge_hash_arrays: true)
110
+ control_params.deep_merge!(params, merge_hash_arrays: true)
111
+ end
112
+ control_params
113
+ end
114
+
115
+ # dependent_check
116
+ # @param all_controls_name: Set of all controls name that parsed from the hiera data
117
+ # @param all_dependent_resources: An array of all the resources that is relied upon
118
+ # @param ignore: List of controls to be ignore
119
+ # @param only: List of only controls that need to be enforce
120
+ # return true if a dependent control is
121
+ def dependent_check(all_controls_name, all_dependent_resources, ignore, only)
122
+ all_dependent_resources.each do |resource_name|
123
+ valid_resource_name = map_for_control_name(resource_name, @control_maps)
124
+ # Bounce immediately if it is not a part of the controls we're enforcing
125
+ return false unless filter_function(resource_name, valid_resource_name, all_controls_name)
126
+
127
+ if !ignore.empty?
128
+ return false if filter_function(resource_name, valid_resource_name, ignore)
129
+ elsif !only.empty?
130
+ return false unless filter_function(resource_name, valid_resource_name, only)
131
+ end
132
+ end
133
+ end
134
+
135
+ # order_resources
136
+ # A work in progress to integrate more metaparamenters in
137
+ # Checks for and creates resources based off of `before`, `after`, `notify`, `require` parameters
138
+ # specified in a controls hash
139
+ # @param resources Output of real_resources()
140
+ # @return An array of resource hashes indexed in the order their contents should be created
141
+ def order_resources(resources)
142
+ before = {}
143
+ after = {}
144
+ req = {}
145
+ notify = {}
146
+ resources.each do |_, data|
147
+ create_ordered_resource!('before', before, data)
148
+ create_ordered_resource!('notify', notify, data)
149
+ create_ordered_resource!('after', after, data)
150
+ create_ordered_resource!('require', req, data)
151
+ end
152
+
153
+ before.deep_merge!(notify)
154
+ after.deep_merge!(req)
155
+
156
+ [before, resources, after]
157
+ end
158
+
159
+ # filter_function
160
+ # A general function to see if a control name is in a supply list of control name
161
+ # @param name: The name of the control that we have
162
+ # @param name_map: All valid control ID permutation of the param name
163
+ # @set_of_control: Either the ignore or the only list to go through
164
+ # return true if control ID is found in set_of_control
165
+ def filter_function(name, name_map, set_of_control)
166
+ name_list = name_map[name]
167
+ return true if set_of_control.include?(name)
168
+
169
+ name_list.each do |n|
170
+ return true if set_of_control.include?(n)
171
+ end
172
+
173
+ false
174
+ end
175
+
176
+ # only_and_ignore_check
177
+ # @param name: name of the control to check if it's in either only or ignore list
178
+ # @param name_map: the name map of valid ID permutation for the `name` param
179
+ # @param only: the list of controls that will get enforced only
180
+ # @param ignore: the list of controls that will be ignored
181
+ # @return false when control is either not in the only list or is in the ignore list.
182
+ # else return true
183
+ def only_and_ignore_check(name, name_map, only, ignore)
184
+ if !only.empty? && !filter_function(name, name_map, only)
185
+ @logger.inform("Control #{name} will be skipped because it is not in the only list.")
186
+ return false
187
+ end
188
+
189
+ if !ignore.empty? && filter_function(name, name_map, ignore)
190
+ @logger.inform("Control #{name} will be skipped because it is in the ignore list.")
191
+ return false
192
+ end
193
+ true
194
+ end
195
+
196
+ # create_ordered_resource!
197
+ # Creates a resource hash from a resource declaration found in a `before`, `after`, `require`, or `notify` parameter
198
+ # @param order_key Either 'before', 'after', `notify`, or `require`
199
+ # @param container Either the before hash, the notify hash, the require hash or the after hash.
200
+ # The container is modified in place.
201
+ # @param res_data Resource data from the real_resources hash
202
+ def create_ordered_resource!(order_key, container, res_data)
203
+ res_data.each do |_, data|
204
+ next unless data.key?(order_key)
205
+
206
+ data[order_key].each do |title, params|
207
+ container[params['type']] = {} unless container.key?(params['type'])
208
+ container[params['type']][title] = params.reject { |k, _| k == 'type' }
209
+ end
210
+ end
211
+ end
212
+
213
+ # mutate_ordering_params!
214
+ # This takes the Hiera resource declarations in a `before` or `after` param and transforms
215
+ # them into and array of Puppet resource references. Puppet resource references take the
216
+ # form: Resource::Type['<resource title'].
217
+ # @param resources Output from real_resources()
218
+ def mutate_ordering_params!(resources)
219
+ resources.each do |res_type, res_data|
220
+ %w[before notify after require].each do |order_key|
221
+ res_data.each do |res_title, params|
222
+ next unless params.key?(order_key)
223
+
224
+ references = []
225
+ params[order_key].each do |k, v|
226
+ references << resource_reference(v['type'], k)
227
+ end
228
+ resources[res_type][res_title][order_key] = references
229
+ end
230
+ end
231
+ end
232
+ end
233
+
234
+ # resource_reference
235
+ # Returns a Puppet resource reference string
236
+ # @param res_type A Puppet resource type
237
+ # @param title A Puppet resource title
238
+ def resource_reference(res_type, title)
239
+ type_ref = res_type.split('::').map(&:capitalize).join('::')
240
+ "#{type_ref}[#{title}]"
241
+ end
242
+
243
+ # find_control_customization
244
+ # Finds any control parameter customizations passed in via control_configs
245
+ # @param name The control name (or other valid permutation)
246
+ # @param control_configs The $control_configs parameter from cis.pp
247
+ # @param name_map: The array of valid permutation of name
248
+ # @return A hash of customized parameters. If none were found, nil
249
+ def find_control_customization(name, name_map, control_configs)
250
+ return {} if control_configs.empty?
251
+
252
+ mapped_key(control_configs, name, name_map)
253
+ end
254
+
255
+ # map_for_control_name
256
+ # Returns a hash of all valid permutations of the given control id
257
+ # @param name The control name or other valid permutation
258
+ # @param maps All maps
259
+ def map_for_control_name(name, maps)
260
+ maps.each do |map|
261
+ return map if map&.fetch(name, false) # returns the map if fetch returns false
262
+ end
263
+ nil
264
+ end
265
+
266
+ # mapped_key
267
+ # Finds an item in the given hash that matches one of the values in name_map
268
+ # @param hsh The hash to search i.e the custom config hash
269
+ # @param name The name of the current control that we're looking to see if it has any custom configs
270
+ # @param name_map An array name for valid control permutations
271
+ # @return The value from the hash if found, or nil
272
+ def mapped_key(hsh, name, name_map)
273
+ return hsh[name] if hsh&.fetch(name, false)
274
+
275
+ name_map.each do |pkey|
276
+ return hsh[pkey] if hsh&.fetch(pkey, false)
277
+ end
278
+ nil
279
+ end
280
+
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,3 @@
1
+ module AbideDataProcessor
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'abide-data-processor/version'
2
+ require 'abide-data-processor/processor'
3
+ # Root namespace for all modules / classes
4
+ module AbideDataProcessor; end
metadata ADDED
@@ -0,0 +1,272 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abide-data-processor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - abide-team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.23'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.23'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: console
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github_changelog_generator
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: gem-release
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: pry
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: pry-byebug
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
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.10'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.10'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.8'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-ast
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.4'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-performance
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.9'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.9'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-i18n
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '3.0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '3.0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: fast_gettext
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '1.8'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '1.8'
223
+ description: Provides functions that help with extracting out information from Hiera
224
+ file.
225
+ email:
226
+ - abide-team@puppet.com
227
+ executables: []
228
+ extensions: []
229
+ extra_rdoc_files: []
230
+ files:
231
+ - ".gitignore"
232
+ - ".rspec"
233
+ - CODE_OF_CONDUCT.md
234
+ - Gemfile
235
+ - Gemfile.lock
236
+ - LICENSE.txt
237
+ - README.md
238
+ - Rakefile
239
+ - abide-data-processor.gemspec
240
+ - bin/console
241
+ - bin/setup
242
+ - lib/abide-data-processor.rb
243
+ - lib/abide-data-processor/logger.rb
244
+ - lib/abide-data-processor/processor.rb
245
+ - lib/abide-data-processor/version.rb
246
+ homepage: https://github.com/puppetlabs/abide-data-processor
247
+ licenses:
248
+ - Proprietary
249
+ metadata:
250
+ homepage_uri: https://github.com/puppetlabs/abide-data-processor
251
+ source_code_uri: https://github.com/puppetlabs/abide-data-processor
252
+ changelog_uri: https://github.com/puppetlabs/abide-data-processor
253
+ post_install_message:
254
+ rdoc_options: []
255
+ require_paths:
256
+ - lib
257
+ required_ruby_version: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ">="
260
+ - !ruby/object:Gem::Version
261
+ version: 2.3.0
262
+ required_rubygems_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: '0'
267
+ requirements: []
268
+ rubygems_version: 3.1.6
269
+ signing_key:
270
+ specification_version: 4
271
+ summary: Helper to process data for Puppetlabs CEM modules.
272
+ test_files: []