abide_dev_utils 0.18.0 → 0.18.1
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 +4 -4
- data/.rspec +1 -1
- data/Gemfile.lock +4 -2
- data/lib/abide_dev_utils/cli/sce.rb +29 -1
- data/lib/abide_dev_utils/errors/sce.rb +7 -0
- data/lib/abide_dev_utils/markdown.rb +2 -2
- data/lib/abide_dev_utils/sce/benchmark.rb +35 -59
- data/lib/abide_dev_utils/sce/benchmark_loader.rb +107 -0
- data/lib/abide_dev_utils/sce/generate/coverage_report.rb +6 -6
- data/lib/abide_dev_utils/sce/generate/reference.rb +38 -110
- data/lib/abide_dev_utils/sce/hiera_data/{resource_data.rb → .resource_data.rb} +4 -4
- data/lib/abide_dev_utils/sce/hiera_data/resource_data/{control.rb → .control.rb} +1 -0
- data/lib/abide_dev_utils/sce/hiera_data/resource_data/{parameters.rb → .parameters.rb} +1 -0
- data/lib/abide_dev_utils/sce/hiera_data/resource_data/{resource.rb → .resource.rb} +1 -0
- data/lib/abide_dev_utils/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f28a2d22319f44e7479dab027b5e0590e78d3269477c89c0334cab4d909d5cfd
|
4
|
+
data.tar.gz: 163f4f18375cdbaa43425b3bd6c60c451cd0aa2f4a6fa115a170762b0c6349a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeec923bae51d8cb5729688acee925ab208bd942d06880b1009d20109b8bd01060f5726055927887f9735d33bb56409bff4e0fac38d6d739ff24fe239839935f
|
7
|
+
data.tar.gz: e61fd4a04bd82705bdb9267fc24c288aa77d35168849239c3a6b82d1760e934e7bb45cf97f8c6828c76c3b9856cdc6db5837daa55b8ed7742b153b3830b70e8b
|
data/.rspec
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abide_dev_utils (0.18.
|
4
|
+
abide_dev_utils (0.18.1)
|
5
5
|
cmdparse (~> 3.0)
|
6
6
|
facterdb (>= 1.21)
|
7
7
|
google-cloud-storage (~> 1.34)
|
@@ -208,7 +208,8 @@ GEM
|
|
208
208
|
trailblazer-option (>= 0.1.1, < 0.2.0)
|
209
209
|
uber (< 0.2.0)
|
210
210
|
retriable (3.1.2)
|
211
|
-
rexml (3.2.
|
211
|
+
rexml (3.2.8)
|
212
|
+
strscan (>= 3.0.9)
|
212
213
|
rgen (0.9.1)
|
213
214
|
rspec (3.11.0)
|
214
215
|
rspec-core (~> 3.11.0)
|
@@ -262,6 +263,7 @@ GEM
|
|
262
263
|
hashie
|
263
264
|
version_gem (~> 1.1, >= 1.1.1)
|
264
265
|
spdx-licenses (1.3.0)
|
266
|
+
strscan (3.1.0)
|
265
267
|
thor (1.2.2)
|
266
268
|
timers (4.3.3)
|
267
269
|
traces (0.11.1)
|
@@ -126,7 +126,35 @@ module Abide
|
|
126
126
|
|
127
127
|
def execute
|
128
128
|
AbideDevUtils::Validate.puppet_module_directory
|
129
|
-
AbideDevUtils::Sce::Generate::Reference.generate(@data)
|
129
|
+
errors, warnings = AbideDevUtils::Sce::Generate::Reference.generate(@data)
|
130
|
+
|
131
|
+
errors.each do |err|
|
132
|
+
output = ["[error]: #{err.message}"]
|
133
|
+
# Errors should all be instances of AbideDevUtils::Errors::BenchmarkLoadError
|
134
|
+
# We check that the extra methods on this error are valid before calling them, though, because
|
135
|
+
# other errors might be returned somehow.
|
136
|
+
if err.respond_to?(:osname) && err.respond_to?(:major_version)
|
137
|
+
output << "Operating System: #{err.osname} #{err.major_version}"
|
138
|
+
end
|
139
|
+
output << "Framework: #{err.framework}" if err.respond_to?(:framework)
|
140
|
+
output << "Puppet Module: #{err.module_name}" if err.respond_to?(:module_name)
|
141
|
+
output << "Original Error Type: #{err.original_error.class}" if err.respond_to?(:original_error)
|
142
|
+
output << "Backtrace:\n\t\t#{err.backtrace.join("\n\t\t")}\n"
|
143
|
+
AbideDevUtils::Output.simple(output.join("\n\t"), stream: $stderr)
|
144
|
+
end
|
145
|
+
warnings.each do |err|
|
146
|
+
output = ["[warn]: #{err.message}"]
|
147
|
+
# Errors should all be instances of AbideDevUtils::Errors::BenchmarkLoadError
|
148
|
+
# We check that the extra methods on this error are valid before calling them, though, because
|
149
|
+
# other errors might be returned somehow.
|
150
|
+
if err.respond_to?(:osname) && err.respond_to?(:major_version)
|
151
|
+
output << "Operating System: #{err.osname} #{err.major_version}"
|
152
|
+
end
|
153
|
+
output << "Framework: #{err.framework}" if err.respond_to?(:framework)
|
154
|
+
output << "Puppet Module: #{err.module_name}" if err.respond_to?(:module_name)
|
155
|
+
AbideDevUtils::Output.simple(output.join("\n\t"), stream: $stderr)
|
156
|
+
end
|
157
|
+
exit 1 unless errors.empty?
|
130
158
|
end
|
131
159
|
end
|
132
160
|
|
@@ -28,5 +28,12 @@ module AbideDevUtils
|
|
28
28
|
class ControlIdFrameworkMismatchError < GenericError
|
29
29
|
@default = 'Control ID is invalid with the given framework:'
|
30
30
|
end
|
31
|
+
|
32
|
+
# Raised when a benchmark fails to load for a non-specific reason
|
33
|
+
class BenchmarkLoadError < GenericError
|
34
|
+
attr_accessor :framework, :osname, :major_version, :module_name, :original_error
|
35
|
+
|
36
|
+
@default = 'Error loading benchmark:'
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
@@ -30,9 +30,9 @@ module AbideDevUtils
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def method_missing(name, *args, &block)
|
33
|
+
def method_missing(name, *args, **kwargs, &block)
|
34
34
|
if name.to_s.start_with?('add_')
|
35
|
-
add(name.to_s.sub('add_', '').to_sym, *args, &block)
|
35
|
+
add(name.to_s.sub('add_', '').to_sym, *args, **kwargs, &block)
|
36
36
|
else
|
37
37
|
super
|
38
38
|
end
|
@@ -148,7 +148,7 @@ module AbideDevUtils
|
|
148
148
|
# Represents a singular rule in a benchmark
|
149
149
|
class Control
|
150
150
|
include AbideDevUtils::DotNumberComparable
|
151
|
-
attr_reader :id, :params, :resource, :framework, :dependent
|
151
|
+
attr_reader :id, :params, :resource, :framework, :dependent, :profiles_levels
|
152
152
|
|
153
153
|
def initialize(id, params, resource, framework, mapper)
|
154
154
|
validate_id_with_framework(id, framework, mapper)
|
@@ -157,6 +157,7 @@ module AbideDevUtils
|
|
157
157
|
@resource = resource
|
158
158
|
@framework = framework
|
159
159
|
@mapper = mapper
|
160
|
+
@profiles_levels = find_levels_and_profiles
|
160
161
|
raise AbideDevUtils::Errors::NoMappingDataForControlError, @id unless @mapper.get(id)
|
161
162
|
end
|
162
163
|
|
@@ -202,12 +203,38 @@ module AbideDevUtils
|
|
202
203
|
send(display_title_type) unless display_title_type.nil?
|
203
204
|
end
|
204
205
|
|
206
|
+
def profiles_levels_by_level(lvl)
|
207
|
+
pls = profiles_levels.map do |plstr|
|
208
|
+
_, l = plstr.split(';;;', 2)
|
209
|
+
plstr if l == lvl || (lvl.is_a?(Array) && lvl.include?(l))
|
210
|
+
end
|
211
|
+
pls.compact.uniq
|
212
|
+
end
|
213
|
+
|
214
|
+
def profiles_levels_by_profile(prof)
|
215
|
+
pls = profiles_levels.map do |plstr|
|
216
|
+
p, = plstr.split(';;;', 2)
|
217
|
+
plstr if p == prof || (prof.is_a?(Array) && prof.include?(p))
|
218
|
+
end
|
219
|
+
pls.compact.uniq
|
220
|
+
end
|
221
|
+
|
222
|
+
def filtered_profiles_levels(prof: nil, lvl: nil)
|
223
|
+
return profiles_levels if (prof.nil? || prof.empty?) && (lvl.nil? || lvl.empty?)
|
224
|
+
if prof && lvl && !prof.empty? && !lvl.empty?
|
225
|
+
return profiles_levels_by_profile(prof).concat(profiles_levels_by_level(lvl))
|
226
|
+
end
|
227
|
+
return profiles_levels_by_profile(prof) unless prof&.empty?
|
228
|
+
|
229
|
+
profiles_levels_by_level(lvl)
|
230
|
+
end
|
231
|
+
|
205
232
|
def levels
|
206
|
-
|
233
|
+
profiles_levels.map { |plstr| plstr.split(';;;', 2).last }
|
207
234
|
end
|
208
235
|
|
209
236
|
def profiles
|
210
|
-
|
237
|
+
profiles_levels.map { |plstr| plstr.split(';;;', 2).first }
|
211
238
|
end
|
212
239
|
|
213
240
|
def valid_maps?
|
@@ -269,22 +296,16 @@ module AbideDevUtils
|
|
269
296
|
@map ||= @mapper.get(id)
|
270
297
|
end
|
271
298
|
|
272
|
-
def levels_and_profiles
|
273
|
-
@levels_and_profiles ||= find_levels_and_profiles
|
274
|
-
end
|
275
|
-
|
276
299
|
def find_levels_and_profiles
|
277
|
-
|
278
|
-
profs = []
|
300
|
+
profs_lvls = []
|
279
301
|
@mapper.levels.each do |lvl|
|
280
302
|
@mapper.profiles.each do |prof|
|
281
|
-
unless @mapper.get(id, level: lvl, profile: prof)
|
282
|
-
|
283
|
-
|
284
|
-
end
|
303
|
+
next unless @mapper.get(id, level: lvl, profile: prof)
|
304
|
+
|
305
|
+
profs_lvls << "#{prof};;;#{lvl}"
|
285
306
|
end
|
286
307
|
end
|
287
|
-
|
308
|
+
profs_lvls.uniq.sort
|
288
309
|
end
|
289
310
|
|
290
311
|
def ruby_class_to_puppet_type(class_name)
|
@@ -337,51 +358,6 @@ module AbideDevUtils
|
|
337
358
|
@controls = resources.map(&:controls).flatten.sort
|
338
359
|
end
|
339
360
|
|
340
|
-
# Creates Benchmark objects from a Puppet module
|
341
|
-
# @param pupmod [AbideDevUtils::Ppt::PuppetModule] A PuppetModule instance
|
342
|
-
# @param skip_errors [Boolean] True skips errors and loads non-erroring benchmarks, false raises the error.
|
343
|
-
# @return [Array<AbideDevUtils::Sce::Benchmark>] Array of Benchmark instances
|
344
|
-
def self.benchmarks_from_puppet_module(pupmod, ignore_all_errors: false, ignore_framework_mismatch: true)
|
345
|
-
frameworks = pupmod.hiera_conf.local_hiera_files(hierarchy_name: 'Mapping Data').each_with_object([]) do |hf, ary|
|
346
|
-
parts = hf.path.split(pupmod.hiera_conf.default_datadir)[-1].split('/')
|
347
|
-
ary << parts[2] unless ary.include?(parts[2])
|
348
|
-
end
|
349
|
-
pupmod.supported_os.each_with_object([]) do |supp_os, ary|
|
350
|
-
osname, majver = supp_os.split('::')
|
351
|
-
if majver.is_a?(Array)
|
352
|
-
majver.sort.each do |v|
|
353
|
-
frameworks.each do |fw|
|
354
|
-
benchmark = Benchmark.new(osname,
|
355
|
-
v,
|
356
|
-
pupmod.hiera_conf,
|
357
|
-
pupmod.name(strip_namespace: true),
|
358
|
-
framework: fw)
|
359
|
-
benchmark.controls
|
360
|
-
ary << benchmark
|
361
|
-
rescue AbideDevUtils::Errors::MappingDataFrameworkMismatchError => e
|
362
|
-
raise e unless ignore_all_errors || ignore_framework_mismatch
|
363
|
-
rescue StandardError => e
|
364
|
-
raise e unless ignore_all_errors
|
365
|
-
end
|
366
|
-
end
|
367
|
-
else
|
368
|
-
frameworks.each do |fw|
|
369
|
-
benchmark = Benchmark.new(osname,
|
370
|
-
majver,
|
371
|
-
pupmod.hiera_conf,
|
372
|
-
pupmod.name(strip_namespace: true),
|
373
|
-
framework: fw)
|
374
|
-
benchmark.controls
|
375
|
-
ary << benchmark
|
376
|
-
rescue AbideDevUtils::Errors::MappingDataFrameworkMismatchError => e
|
377
|
-
raise e unless ignore_all_errors || ignore_framework_mismatch
|
378
|
-
rescue StandardError => e
|
379
|
-
raise e unless ignore_all_errors
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
361
|
def map_data
|
386
362
|
mapper.map_data
|
387
363
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../ppt/puppet_module'
|
4
|
+
require_relative 'benchmark'
|
5
|
+
|
6
|
+
module AbideDevUtils
|
7
|
+
module Sce
|
8
|
+
# Namespace for classes and methods for loading benchmarks
|
9
|
+
module BenchmarkLoader
|
10
|
+
# Load benchmarks from a Puppet module
|
11
|
+
# @param module_dir [String] the directory of the Puppet module
|
12
|
+
# @param opts [Hash] options for loading the benchmarks
|
13
|
+
# @option opts [Boolean] :ignore_all_errors ignore all errors when loading benchmarks
|
14
|
+
# @option opts [Boolean] :ignore_framework_mismatch ignore errors when the framework doesn't match
|
15
|
+
# @return [Array<AbideDevUtils::Sce::Benchmark>] the loaded benchmarks
|
16
|
+
def self.benchmarks_from_puppet_module(module_dir = Dir.pwd, **opts)
|
17
|
+
PupMod.new(module_dir, **opts).load
|
18
|
+
end
|
19
|
+
|
20
|
+
# Loads benchmark data for a Puppet module
|
21
|
+
class PupMod
|
22
|
+
attr_reader :pupmod, :load_errors, :load_warnings, :ignore_all_errors, :ignore_framework_mismatch
|
23
|
+
|
24
|
+
def initialize(module_dir = Dir.pwd, **opts)
|
25
|
+
@pupmod = AbideDevUtils::Ppt::PuppetModule.new(module_dir)
|
26
|
+
@load_errors = []
|
27
|
+
@load_warnings = []
|
28
|
+
@ignore_all_errors = opts.fetch(:ignore_all_errors, false)
|
29
|
+
@ignore_framework_mismatch = opts.fetch(:ignore_framework_mismatch, false)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Load the benchmark from the Puppet module
|
33
|
+
# @return [Array<AbideDevUtils::Sce::Benchmark>] the loaded benchmarks
|
34
|
+
# @raise [AbideDevUtils::Errors::BenchmarkLoadError] if a benchmark fails to load
|
35
|
+
def load
|
36
|
+
clear_load_errors
|
37
|
+
clear_load_warnings
|
38
|
+
pupmod.supported_os.each_with_object([]) do |supp_os, ary|
|
39
|
+
osname, majver = supp_os.split('::')
|
40
|
+
if majver.is_a?(Array)
|
41
|
+
majver.sort.each do |v|
|
42
|
+
frameworks.each do |fw|
|
43
|
+
ary << new_benchmark(osname, v, fw)
|
44
|
+
rescue StandardError => e
|
45
|
+
handle_load_error(e, fw, osname, v, pupmod.name(strip_namespace: true))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
else
|
49
|
+
frameworks.each do |fw|
|
50
|
+
ary << new_benchmark(osname, majver, fw)
|
51
|
+
rescue StandardError => e
|
52
|
+
handle_load_error(e, fw, osname, majver, pupmod.name(strip_namespace: true))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def clear_load_errors
|
61
|
+
@load_errors = []
|
62
|
+
end
|
63
|
+
|
64
|
+
def clear_load_warnings
|
65
|
+
@load_warnings = []
|
66
|
+
end
|
67
|
+
|
68
|
+
def frameworks
|
69
|
+
@frameworks ||= pupmod.hiera_conf.local_hiera_files(hierarchy_name: 'Mapping Data').each_with_object([]) do |hf, ary|
|
70
|
+
parts = hf.path.split(pupmod.hiera_conf.default_datadir)[-1].split('/')
|
71
|
+
ary << parts[2] unless ary.include?(parts[2])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_benchmark(osname, majver, framework)
|
76
|
+
benchmark = AbideDevUtils::Sce::Benchmark.new(
|
77
|
+
osname,
|
78
|
+
majver,
|
79
|
+
pupmod.hiera_conf,
|
80
|
+
pupmod.name(strip_namespace: true),
|
81
|
+
framework: framework
|
82
|
+
)
|
83
|
+
benchmark.controls
|
84
|
+
benchmark
|
85
|
+
end
|
86
|
+
|
87
|
+
def handle_load_error(error, framework, osname, majver, module_name)
|
88
|
+
err = AbideDevUtils::Errors::BenchmarkLoadError.new(error.message)
|
89
|
+
err.set_backtrace(error.backtrace)
|
90
|
+
err.framework = framework
|
91
|
+
err.osname = osname
|
92
|
+
err.major_version = majver
|
93
|
+
err.module_name = module_name
|
94
|
+
err.original_error = error
|
95
|
+
if error.is_a?(AbideDevUtils::Errors::MappingDataFrameworkMismatchError) && ignore_framework_mismatch
|
96
|
+
@load_warnings << err
|
97
|
+
elsif ignore_all_errors
|
98
|
+
@load_errors << err
|
99
|
+
else
|
100
|
+
@load_errors << err
|
101
|
+
raise err
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -4,9 +4,9 @@ require 'date'
|
|
4
4
|
require 'json'
|
5
5
|
require 'pathname'
|
6
6
|
require 'yaml'
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
require_relative '../../ppt'
|
8
|
+
require_relative '../../validate'
|
9
|
+
require_relative '../benchmark_loader'
|
10
10
|
|
11
11
|
module AbideDevUtils
|
12
12
|
module Sce
|
@@ -16,9 +16,9 @@ module AbideDevUtils
|
|
16
16
|
module CoverageReport
|
17
17
|
def self.generate(format_func: :to_h, opts: {})
|
18
18
|
opts = ReportOptions.new(opts)
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
benchmarks = AbideDevUtils::Sce::BenchmarkLoader.benchmarks_from_puppet_module(
|
20
|
+
ignore_all_errors: opts.ignore_all_errors
|
21
|
+
)
|
22
22
|
benchmarks.map do |b|
|
23
23
|
BenchmarkReport.new(b, opts).run.send(format_func)
|
24
24
|
end
|
@@ -6,10 +6,10 @@ require 'puppet-strings/yard'
|
|
6
6
|
require 'shellwords'
|
7
7
|
require 'timeout'
|
8
8
|
require 'yaml'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
require_relative '../../markdown'
|
10
|
+
require_relative '../../output'
|
11
|
+
require_relative '../../ppt'
|
12
|
+
require_relative '../benchmark_loader'
|
13
13
|
|
14
14
|
module AbideDevUtils
|
15
15
|
module Sce
|
@@ -19,9 +19,14 @@ module AbideDevUtils
|
|
19
19
|
MAPPING_PATH_KEY = 'Mapping Data'
|
20
20
|
RESOURCE_DATA_PATH_KEY = 'Resource Data'
|
21
21
|
|
22
|
+
# @return [Array<Array<StandardError>>] Returns a 2d array with two items. The first item
|
23
|
+
# is an array containing StandardError-derived objects that are considered halting errors
|
24
|
+
# in reference generation. The second item is an array of StandardError-derived objects
|
25
|
+
# that are considered non-halting (warning) errors.
|
22
26
|
def self.generate(data = {})
|
23
|
-
|
24
|
-
|
27
|
+
pupmod_path = data[:module_dir] || Dir.pwd
|
28
|
+
bm_loader = BenchmarkLoader::PupMod.new(pupmod_path, ignore_framework_mismatch: true)
|
29
|
+
doc_title = case bm_loader.pupmod.name
|
25
30
|
when 'puppetlabs-sce_linux'
|
26
31
|
'SCE for Linux Reference'
|
27
32
|
when 'puppetlabs-sce_windows'
|
@@ -29,14 +34,15 @@ module AbideDevUtils
|
|
29
34
|
else
|
30
35
|
'Reference'
|
31
36
|
end
|
32
|
-
benchmarks =
|
37
|
+
benchmarks = bm_loader.load
|
33
38
|
case data.fetch(:format, 'markdown')
|
34
39
|
when 'markdown'
|
35
40
|
file = data[:out_file] || 'REFERENCE.md'
|
36
|
-
MarkdownGenerator.new(benchmarks, pupmod.name, file: file, opts: data).generate(doc_title)
|
41
|
+
MarkdownGenerator.new(benchmarks, bm_loader.pupmod.name, file: file, opts: data).generate(doc_title)
|
37
42
|
else
|
38
43
|
raise "Format #{data[:format]} is unsupported! Only `markdown` format supported"
|
39
44
|
end
|
45
|
+
[bm_loader.load_errors, bm_loader.load_warnings]
|
40
46
|
end
|
41
47
|
|
42
48
|
def self.generate_markdown
|
@@ -122,10 +128,10 @@ module AbideDevUtils
|
|
122
128
|
attr_reader :search_patterns
|
123
129
|
|
124
130
|
def initialize(search_patterns: nil, opts: {})
|
125
|
-
@search_patterns = search_patterns || PuppetStrings::DEFAULT_SEARCH_PATTERNS
|
131
|
+
@search_patterns = search_patterns || ::PuppetStrings::DEFAULT_SEARCH_PATTERNS
|
126
132
|
@debug = opts[:debug]
|
127
133
|
@quiet = opts[:quiet]
|
128
|
-
PuppetStrings::Yard.setup!
|
134
|
+
::PuppetStrings::Yard.setup!
|
129
135
|
YARD::CLI::Yardoc.run(*yard_args(@search_patterns, debug: @debug, quiet: @quiet))
|
130
136
|
end
|
131
137
|
|
@@ -219,25 +225,6 @@ module AbideDevUtils
|
|
219
225
|
end
|
220
226
|
end
|
221
227
|
|
222
|
-
# Generates markdown for Puppet classes based on Puppet Strings JSON
|
223
|
-
# class PuppetClassMarkdown
|
224
|
-
# def initialize(puppet_classes, md, opts: {})
|
225
|
-
# @puppet_classes = puppet_classes
|
226
|
-
# @md = md
|
227
|
-
# @opts = opts
|
228
|
-
# end
|
229
|
-
|
230
|
-
# def generate!
|
231
|
-
# @puppet_classes.each do |puppet_class|
|
232
|
-
# @md.add_h2(puppet_class['name'])
|
233
|
-
# @md.add_paragraph("File(Line): `#{puppet_class['file']}(#{puppet_class['line']})`")
|
234
|
-
|
235
|
-
# private
|
236
|
-
|
237
|
-
# def doc_string_builder(puppet_class)
|
238
|
-
# return if puppet_class['docstring'].nil? || puppet_class['docstring'].empty?
|
239
|
-
# end
|
240
|
-
|
241
228
|
# Generates markdown for a control
|
242
229
|
class ControlMarkdown
|
243
230
|
def initialize(control, md, strings, module_name, framework, formatter: nil, opts: {})
|
@@ -256,49 +243,23 @@ module AbideDevUtils
|
|
256
243
|
def generate!
|
257
244
|
heading_builder
|
258
245
|
control_params_builder
|
259
|
-
|
260
|
-
control_profiles_builder
|
246
|
+
control_profiles_levels_builder
|
261
247
|
config_example_builder
|
262
248
|
control_alternate_ids_builder
|
263
249
|
dependent_controls_builder
|
264
250
|
resource_reference_builder
|
265
251
|
end
|
266
252
|
|
267
|
-
# This function
|
268
|
-
#
|
269
|
-
#
|
270
|
-
# 2. If selections are made for profile, then only the selected profile and all levels of control will be selected.
|
271
|
-
# 3. If selections are made for level, then only the selected level and all profiles of control will be selected.
|
272
|
-
# This function adds in some runtime overhead because we're checking each control's level and profile which is
|
273
|
-
# what we're going to be doing later when building the level and profile markdown, but this is
|
274
|
-
# necessary to ensure that the reference.md is generated the way we want it to be.
|
253
|
+
# This function gets the array of string representations of profiles and levels
|
254
|
+
# from the control based on selection filters in opts, if any.
|
255
|
+
# @return [Boolean] if valid profiles and levels were extracted from the control.
|
275
256
|
def verify_profile_and_level_selections
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
return true unless @valid_level.empty?
|
284
|
-
elsif !@opts[:select_profile].nil? && @opts[:select_level].nil?
|
285
|
-
@control.profiles.each do |profile|
|
286
|
-
@valid_profile << profile if select_control_profile(profile)
|
287
|
-
end
|
288
|
-
|
289
|
-
return true unless @valid_profile.empty?
|
290
|
-
elsif !@opts[:select_profile].nil? && !@opts[:select_level].nil?
|
291
|
-
@control.levels.each do |level|
|
292
|
-
@valid_level << level if select_control_level(level)
|
293
|
-
end
|
294
|
-
|
295
|
-
@control.profiles.each do |profile|
|
296
|
-
@valid_profile << profile if select_control_profile(profile)
|
297
|
-
end
|
298
|
-
|
299
|
-
# As long as there are valid profiles and levels for the control at this stage, all is good
|
300
|
-
!@valid_level.empty? && !@valid_profile.empty?
|
301
|
-
end
|
257
|
+
@valid_profs_lvls = @control.filtered_profiles_levels(
|
258
|
+
prof: @opts[:select_profile],
|
259
|
+
lvl: @opts[:select_level]
|
260
|
+
)
|
261
|
+
@valid_profs_lvls.uniq!
|
262
|
+
!@valid_profs_lvls.empty?
|
302
263
|
end
|
303
264
|
|
304
265
|
private
|
@@ -365,7 +326,7 @@ module AbideDevUtils
|
|
365
326
|
def control_params_builder
|
366
327
|
return unless control_has_valid_params?
|
367
328
|
|
368
|
-
@md.
|
329
|
+
@md.add_h3('Parameters:')
|
369
330
|
[@control.param_hashes, @control.resource.sce_options, @control.resource.sce_protected].each do |collection|
|
370
331
|
collection.each do |hsh|
|
371
332
|
rparam = resource_param(hsh)
|
@@ -377,56 +338,25 @@ module AbideDevUtils
|
|
377
338
|
end
|
378
339
|
end
|
379
340
|
|
380
|
-
def
|
381
|
-
return unless @control.levels
|
382
|
-
|
383
|
-
# @valid_level is populated in verify_profile_and_level_selections from the fact that we've given
|
384
|
-
# the generator a list of levels we want to use. If we didn't give it a list of levels, then we
|
385
|
-
# want to use all of the levels that the control supports from @control.
|
386
|
-
if @framework == 'stig'
|
387
|
-
@md.add_ul('Supported MAC Levels:')
|
388
|
-
else
|
389
|
-
@md.add_ul('Supported Levels:')
|
390
|
-
end
|
391
|
-
|
392
|
-
if @valid_level.empty?
|
393
|
-
@control.levels.each do |l|
|
394
|
-
@md.add_ul(@md.code(l), indent: 1)
|
395
|
-
end
|
396
|
-
else
|
397
|
-
@valid_level.each do |l|
|
398
|
-
@md.add_ul(@md.code(l), indent: 1)
|
399
|
-
end
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
def control_profiles_builder
|
341
|
+
def control_profiles_levels_builder
|
404
342
|
return unless @control.profiles
|
405
343
|
|
406
|
-
# @valid_profile is populated in verify_profile_and_level_selections from the fact that we've given
|
407
|
-
# the generator a list of profiles we want to use. If we didn't give it a list of profiles, then we
|
408
|
-
# want to use all of the profiles that the control supports from @control.
|
409
344
|
if @framework == 'stig'
|
410
|
-
@md.
|
345
|
+
@md.add_h3('Supported Confidentiality & MAC Levels:')
|
411
346
|
else
|
412
|
-
@md.
|
347
|
+
@md.add_h3('Supported Profiles & Levels:')
|
413
348
|
end
|
414
349
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
end
|
419
|
-
else
|
420
|
-
@valid_profile.each do |l|
|
421
|
-
@md.add_ul(@md.code(l), indent: 1)
|
422
|
-
end
|
350
|
+
@valid_profs_lvls.each do |plstr|
|
351
|
+
p, l = plstr.split(';;;', 2)
|
352
|
+
@md.add_ul(@md.code("#{p}, #{l}"), indent: 1)
|
423
353
|
end
|
424
354
|
end
|
425
355
|
|
426
356
|
def control_alternate_ids_builder
|
427
357
|
# return if @framework == 'stig'
|
428
358
|
|
429
|
-
@md.
|
359
|
+
@md.add_h3('Alternate Config IDs:')
|
430
360
|
@control.alternate_ids.each do |l|
|
431
361
|
@md.add_ul(@md.code(l), indent: 1)
|
432
362
|
end
|
@@ -448,9 +378,8 @@ module AbideDevUtils
|
|
448
378
|
dep_ctrls = @control.resource.dependent_controls
|
449
379
|
return if dep_ctrls.nil? || dep_ctrls.empty?
|
450
380
|
|
451
|
-
@md.
|
381
|
+
@md.add_h3('Dependent controls:')
|
452
382
|
dep_ctrls.each do |ctrl|
|
453
|
-
puts "DEPENDENT: #{ctrl.id}"
|
454
383
|
@md.add_ul(@md.code(ctrl.display_title), indent: 1)
|
455
384
|
end
|
456
385
|
end
|
@@ -471,11 +400,9 @@ module AbideDevUtils
|
|
471
400
|
@control.title.nil? ? out_str.unshift(" #{@control.id.dump}:") : out_str.unshift(" #{@control.title.dump}:")
|
472
401
|
out_str.unshift(' control_configs:')
|
473
402
|
out_str.unshift("#{@module_name.split('-').last}::config:")
|
474
|
-
@md.
|
403
|
+
@md.add_h3('Hiera Configuration Example:')
|
475
404
|
@md.add_code_block(out_str.join("\n"), language: 'yaml')
|
476
405
|
rescue StandardError => e
|
477
|
-
require 'pry'
|
478
|
-
binding.pry
|
479
406
|
err_msg = [
|
480
407
|
"Failed to generate config example for control #{@control.id}",
|
481
408
|
"Error: #{e.message}",
|
@@ -486,7 +413,8 @@ module AbideDevUtils
|
|
486
413
|
end
|
487
414
|
|
488
415
|
def resource_reference_builder
|
489
|
-
@md.
|
416
|
+
@md.add_h3('Resource:')
|
417
|
+
@md.add_ul(@md.code(@control.resource.to_reference), indent: 1)
|
490
418
|
end
|
491
419
|
end
|
492
420
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# This should be unused, keeping around incase shit breaks and it's needed
|
4
|
+
require_relative '../../../errors'
|
5
|
+
require_relative '../../../ppt/facter_utils'
|
6
|
+
require_relative '../benchmark_loader'
|
7
7
|
|
8
8
|
module AbideDevUtils
|
9
9
|
module Sce
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abide_dev_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abide-team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -432,17 +432,18 @@ files:
|
|
432
432
|
- lib/abide_dev_utils/resources/generic_spec.erb
|
433
433
|
- lib/abide_dev_utils/sce.rb
|
434
434
|
- lib/abide_dev_utils/sce/benchmark.rb
|
435
|
+
- lib/abide_dev_utils/sce/benchmark_loader.rb
|
435
436
|
- lib/abide_dev_utils/sce/generate.rb
|
436
437
|
- lib/abide_dev_utils/sce/generate/coverage_report.rb
|
437
438
|
- lib/abide_dev_utils/sce/generate/reference.rb
|
438
439
|
- lib/abide_dev_utils/sce/hiera_data.rb
|
440
|
+
- lib/abide_dev_utils/sce/hiera_data/.resource_data.rb
|
439
441
|
- lib/abide_dev_utils/sce/hiera_data/mapping_data.rb
|
440
442
|
- lib/abide_dev_utils/sce/hiera_data/mapping_data/map_data.rb
|
441
443
|
- lib/abide_dev_utils/sce/hiera_data/mapping_data/mixins.rb
|
442
|
-
- lib/abide_dev_utils/sce/hiera_data/resource_data.rb
|
443
|
-
- lib/abide_dev_utils/sce/hiera_data/resource_data
|
444
|
-
- lib/abide_dev_utils/sce/hiera_data/resource_data
|
445
|
-
- lib/abide_dev_utils/sce/hiera_data/resource_data/resource.rb
|
444
|
+
- lib/abide_dev_utils/sce/hiera_data/resource_data/.control.rb
|
445
|
+
- lib/abide_dev_utils/sce/hiera_data/resource_data/.parameters.rb
|
446
|
+
- lib/abide_dev_utils/sce/hiera_data/resource_data/.resource.rb
|
446
447
|
- lib/abide_dev_utils/sce/mapping/mapper.rb
|
447
448
|
- lib/abide_dev_utils/sce/validate.rb
|
448
449
|
- lib/abide_dev_utils/sce/validate/resource_data.rb
|