compliance_engine 1.1.0 → 1.2.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/CHANGELOG.md +9 -0
- data/lib/compliance_engine/cli.rb +1 -2
- data/lib/compliance_engine/component.rb +45 -1
- data/lib/compliance_engine/data.rb +13 -14
- data/lib/compliance_engine/data_loader.rb +25 -7
- data/lib/compliance_engine/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 67a58c88267190eae57f6703f5397740aacac7e69884b69c323a846d3587f003
|
|
4
|
+
data.tar.gz: abb32a50c4a5477cbaecf7d5b4a6734cdd0c30fdc4cc3394e8d66a886b04cfea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1bc6a094c622894c124457f293099cc8b8f10a22184b56e48981bda714765b8fd8a0c151afab6744c32984b6176b322e1e69f942b152f638d158e6ac40afbd9
|
|
7
|
+
data.tar.gz: 7bfd5ef4df5f39711dd9816945ac52700dd0ac95a0b12ac0b8b56aada923c4f0e6012f3a6931535f687ec90020a81cb6e616b1f717c7842c4b5d4a2fad52351f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
### 1.2.1 / 2026-12-01
|
|
2
|
+
* Reduce memory use in `ComplianceEngine::Data#check_mapping` by dropping a redundant internal cache that held one entry per check for every profile or CE mapped
|
|
3
|
+
* Reduce memory use by keeping a single copy of each distinct string value in loaded compliance data
|
|
4
|
+
* Reduce memory use in `ComplianceEngine::Data#check_mapping` and `Collection#select`/`#reject` by no longer deep-copying loaded compliance data each time a collection is copied. The deeply frozen fragments returned by `#to_a` on a copied component (everything loaded from compliance data files) are now shared with the original and remain frozen
|
|
5
|
+
|
|
6
|
+
### 1.2.0 / 2026-10-17
|
|
7
|
+
* Allow OpenVox 9 (and Puppet 9) in the Puppet module's `metadata.json`
|
|
8
|
+
* Test with OpenVox 9: spec tests on Ruby 4.0 and JRuby 10.0, and acceptance tests against the `openvox9` collection alongside `openvox8`
|
|
9
|
+
|
|
1
10
|
### 1.1.0 / 2026-06-11
|
|
2
11
|
* Include `Enumerable` in `ComplianceEngine::Collection` so all collections (`Ces`, `Checks`, `Controls`, `Profiles`) gain the full Enumerable interface (`#each_with_object`, `#map`, `#reduce`, `#find`, ...); they defined `#each` but raised `NoMethodError` on these. The explicit `#select`/`#reject` still return Collections. (#127)
|
|
3
12
|
|
|
@@ -50,9 +50,8 @@ class ComplianceEngine::CLI < Thor
|
|
|
50
50
|
def inspect
|
|
51
51
|
# Run the CLI with `data` as the object containing the compliance data.
|
|
52
52
|
require 'irb'
|
|
53
|
-
# rubocop:disable Lint/Debugger
|
|
53
|
+
# rubocop:disable-next Lint/Debugger
|
|
54
54
|
binding.irb
|
|
55
|
-
# rubocop:enable Lint/Debugger
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
private
|
|
@@ -40,11 +40,18 @@ class ComplianceEngine::Component
|
|
|
40
40
|
# an independent fragment store. Cache variables are cleared so each
|
|
41
41
|
# copy rebuilds them lazily from its own fragments on first access.
|
|
42
42
|
#
|
|
43
|
+
# A fragment that is deeply frozen (as everything loaded through a
|
|
44
|
+
# ComplianceEngine::DataLoader is) cannot be mutated through either
|
|
45
|
+
# object, so the copy references it instead of deep-copying it. Any
|
|
46
|
+
# other fragment is deep-copied so nested values stay independent.
|
|
47
|
+
#
|
|
43
48
|
# @return [NilClass]
|
|
44
49
|
def initialize_copy(_source)
|
|
45
50
|
super
|
|
46
51
|
@component = @component.dup
|
|
47
|
-
@component[:fragments] = @component[:fragments].transform_values
|
|
52
|
+
@component[:fragments] = @component[:fragments].transform_values do |fragment|
|
|
53
|
+
deep_frozen?(fragment) ? fragment : Marshal.load(Marshal.dump(fragment))
|
|
54
|
+
end
|
|
48
55
|
cache_variables.each { |var| instance_variable_set(var, nil) }
|
|
49
56
|
nil
|
|
50
57
|
end
|
|
@@ -145,6 +152,43 @@ class ComplianceEngine::Component
|
|
|
145
152
|
instance_variables - (context_variables + [:@component])
|
|
146
153
|
end
|
|
147
154
|
|
|
155
|
+
# Check whether an object and everything nested within it is frozen
|
|
156
|
+
#
|
|
157
|
+
# Only plain Hashes, Arrays, and Strings and immutable scalars are
|
|
158
|
+
# recognized. Any other object (a Set, a Struct, or a subclass of Hash,
|
|
159
|
+
# Array, or String, for example) may hold mutable state even when it is
|
|
160
|
+
# frozen itself, so it is never considered deeply frozen. Neither is a
|
|
161
|
+
# Hash with a default value or default proc, which a copy would share.
|
|
162
|
+
#
|
|
163
|
+
# @param obj [Object] The object to check
|
|
164
|
+
# @param seen [Hash] The containers already visited, compared by identity,
|
|
165
|
+
# so that data referring back to itself does not recurse forever
|
|
166
|
+
# @return [TrueClass, FalseClass] true if no part of the object can be mutated
|
|
167
|
+
def deep_frozen?(obj, seen = {}.compare_by_identity)
|
|
168
|
+
return false unless obj.frozen?
|
|
169
|
+
|
|
170
|
+
case obj
|
|
171
|
+
when Symbol, Numeric, NilClass, TrueClass, FalseClass
|
|
172
|
+
true
|
|
173
|
+
when String
|
|
174
|
+
obj.instance_of?(String)
|
|
175
|
+
when Hash
|
|
176
|
+
return false unless obj.instance_of?(Hash) && obj.default.nil? && obj.default_proc.nil?
|
|
177
|
+
return true if seen.key?(obj)
|
|
178
|
+
|
|
179
|
+
seen[obj] = true
|
|
180
|
+
obj.all? { |k, v| deep_frozen?(k, seen) && deep_frozen?(v, seen) }
|
|
181
|
+
when Array
|
|
182
|
+
return false unless obj.instance_of?(Array)
|
|
183
|
+
return true if seen.key?(obj)
|
|
184
|
+
|
|
185
|
+
seen[obj] = true
|
|
186
|
+
obj.all? { |v| deep_frozen?(v, seen) }
|
|
187
|
+
else
|
|
188
|
+
false
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
148
192
|
# Compare a fact value against a confine value
|
|
149
193
|
#
|
|
150
194
|
# @param fact [Object] The fact value
|
|
@@ -211,7 +211,7 @@ class ComplianceEngine::Data
|
|
|
211
211
|
end
|
|
212
212
|
|
|
213
213
|
self.environment_data ||= {}
|
|
214
|
-
self.environment_data =
|
|
214
|
+
self.environment_data = environment_data.merge(modules)
|
|
215
215
|
|
|
216
216
|
nil
|
|
217
217
|
end
|
|
@@ -445,43 +445,42 @@ class ComplianceEngine::Data
|
|
|
445
445
|
|
|
446
446
|
# Return true if the check is mapped to the profile or CE
|
|
447
447
|
#
|
|
448
|
+
# The result is not memoized here: the only caller is #check_mapping, which
|
|
449
|
+
# asks about each check once per profile or CE and caches its own result.
|
|
450
|
+
#
|
|
448
451
|
# @param check [ComplianceEngine::Check] The check
|
|
449
452
|
# @param profile_or_ce [ComplianceEngine::Profile, ComplianceEngine::Ce] The profile or CE
|
|
450
453
|
# @return [TrueClass, FalseClass]
|
|
451
454
|
def mapping?(check, profile_or_ce)
|
|
452
455
|
raise ArgumentError, 'Argument must be a ComplianceEngine::Profile object' unless profile_or_ce.is_a?(ComplianceEngine::Profile) || profile_or_ce.is_a?(ComplianceEngine::Ce)
|
|
453
456
|
|
|
454
|
-
@mapping ||= {}
|
|
455
|
-
cache_key = [check.key, "#{profile_or_ce.class}:#{profile_or_ce.key}"].to_s
|
|
456
|
-
return @mapping[cache_key] if @mapping.key?(cache_key)
|
|
457
|
-
|
|
458
457
|
# An explicit `false` on the profile side hard-excludes the check, regardless of any other route.
|
|
459
|
-
return
|
|
458
|
+
return false if profile_or_ce.is_a?(ComplianceEngine::Profile) && profile_or_ce.checks&.dig(check.key) == false
|
|
460
459
|
|
|
461
460
|
# Correlate based on controls
|
|
462
461
|
controls = check.controls&.select { |_, v| v }&.map { |k, _| k }
|
|
463
462
|
|
|
464
|
-
return
|
|
463
|
+
return true if correlate(controls, profile_or_ce.controls)
|
|
465
464
|
|
|
466
465
|
if profile_or_ce.is_a?(ComplianceEngine::Ce)
|
|
467
466
|
# Correlate based on CEs
|
|
468
|
-
return
|
|
467
|
+
return true if check.ces&.include?(profile_or_ce.key)
|
|
469
468
|
|
|
470
|
-
return
|
|
469
|
+
return false
|
|
471
470
|
end
|
|
472
471
|
|
|
473
472
|
# Correlate based on direct reference to checks
|
|
474
|
-
return
|
|
473
|
+
return true if profile_or_ce.checks&.dig(check.key)
|
|
475
474
|
|
|
476
475
|
# Correlate based on CEs
|
|
477
|
-
return
|
|
476
|
+
return true if correlate(check.ces, profile_or_ce.ces)
|
|
478
477
|
|
|
479
478
|
# Correlate based on CEs and controls. A CE explicitly set to `false` in the profile
|
|
480
479
|
# cannot be used as a bridge; absence (nil) still allows the bridge.
|
|
481
|
-
return
|
|
482
|
-
return
|
|
480
|
+
return true if profile_or_ce.ces&.any? { |k, v| v && correlate(controls, ces[k]&.controls) }
|
|
481
|
+
return true if check.ces&.any? { |ce| profile_or_ce.ces&.dig(ce) != false && ces[ce]&.controls&.any? { |k, v| v && profile_or_ce.controls&.dig(k) } }
|
|
483
482
|
|
|
484
|
-
|
|
483
|
+
false
|
|
485
484
|
end
|
|
486
485
|
|
|
487
486
|
# Correlate between arrays and hashes
|
|
@@ -20,10 +20,13 @@ class ComplianceEngine::DataLoader
|
|
|
20
20
|
|
|
21
21
|
# Set the data for the data loader
|
|
22
22
|
#
|
|
23
|
-
# The hash and all nested hashes
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
23
|
+
# The hash and all nested hashes and arrays within it are deep-frozen so
|
|
24
|
+
# that parsed compliance data is treated as read-only once loaded. String
|
|
25
|
+
# values are replaced with frozen, deduplicated copies, so a String object
|
|
26
|
+
# the caller still holds is not itself frozen and is no longer part of the
|
|
27
|
+
# data. A hash or array that is already frozen is replaced with a frozen
|
|
28
|
+
# copy. Callers must not retain a mutable reference to the hash after
|
|
29
|
+
# calling this method.
|
|
27
30
|
#
|
|
28
31
|
# @param value [Hash] The new value for the data loader
|
|
29
32
|
# @raise [ComplianceEngine::Error] If the value is not a Hash
|
|
@@ -56,14 +59,29 @@ class ComplianceEngine::DataLoader
|
|
|
56
59
|
# that invariant explicit and surfaces any accidental in-place mutation
|
|
57
60
|
# immediately as a FrozenError rather than silent data corruption.
|
|
58
61
|
#
|
|
62
|
+
# String values are also interned (deduplicated). Compliance data repeats
|
|
63
|
+
# the same control, CE, and parameter names many times across files, and
|
|
64
|
+
# the parsers allocate a new String for every occurrence that is not a
|
|
65
|
+
# Hash key. Interning them keeps a single copy of each distinct string.
|
|
66
|
+
#
|
|
59
67
|
# @param obj [Object] the object to freeze
|
|
60
|
-
# @return [Object] the frozen object
|
|
68
|
+
# @return [Object] the frozen object; a String or an already-frozen Hash or
|
|
69
|
+
# Array is returned as a different object, everything else is frozen
|
|
70
|
+
# in-place
|
|
61
71
|
def deep_freeze(obj)
|
|
62
72
|
case obj
|
|
63
73
|
when Hash
|
|
64
|
-
|
|
74
|
+
# A frozen container cannot have its values replaced with interned
|
|
75
|
+
# strings, so it is replaced with a frozen copy instead.
|
|
76
|
+
return obj.transform_values { |v| deep_freeze(v) }.freeze if obj.frozen?
|
|
77
|
+
|
|
78
|
+
obj.transform_values! { |v| deep_freeze(v) }
|
|
65
79
|
when Array
|
|
66
|
-
obj.
|
|
80
|
+
return obj.map { |v| deep_freeze(v) }.freeze if obj.frozen?
|
|
81
|
+
|
|
82
|
+
obj.map! { |v| deep_freeze(v) }
|
|
83
|
+
when String
|
|
84
|
+
return -obj
|
|
67
85
|
end
|
|
68
86
|
obj.freeze
|
|
69
87
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: compliance_engine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steven Pritchard
|
|
@@ -159,7 +159,7 @@ licenses:
|
|
|
159
159
|
metadata:
|
|
160
160
|
homepage_uri: https://simp-project.com/docs/sce/
|
|
161
161
|
source_code_uri: https://github.com/simp/rubygem-simp-compliance_engine
|
|
162
|
-
changelog_uri: https://github.com/simp/rubygem-simp-compliance_engine/releases/tag/1.1
|
|
162
|
+
changelog_uri: https://github.com/simp/rubygem-simp-compliance_engine/releases/tag/1.2.1
|
|
163
163
|
bug_tracker_uri: https://github.com/simp/rubygem-simp-compliance_engine/issues
|
|
164
164
|
rdoc_options: []
|
|
165
165
|
require_paths:
|
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
175
175
|
- !ruby/object:Gem::Version
|
|
176
176
|
version: '0'
|
|
177
177
|
requirements: []
|
|
178
|
-
rubygems_version: 4.0.
|
|
178
|
+
rubygems_version: 4.0.20
|
|
179
179
|
specification_version: 4
|
|
180
180
|
summary: Parser for Sicura Compliance Engine data
|
|
181
181
|
test_files: []
|