Repository navigation
refactor(exporters): check styles against the models in the schema - #59
Merged
Merged
Conversation
The checks that need the XCCDF and Benchmark models move from nine hand-written MappingEngine._refuse_* methods into StyleConfig's validation. ConfigLoader gives the schema StyleModels as pydantic validation context: the XCCDF models of the style's version, the Recommendation and Benchmark models, and the engine's own transform lookup and template parser. Each refusal now carries the path of the key. - Field names: RecommendationField, RecommendationPath and BenchmarkField types check source_field, sources, children and element sources. - Transforms: TransformName checks the registry; Template checks its filters in the strings the engine fills (owner decision). - Elements: a field mapping's target, a Group element and a Benchmark element are checked against the XCCDF version. - Rule metadata: the prefix is declared and not XCCDF's, group_by names a field of the items, and the target repeats and takes elements of every namespace but XCCDF's, read with the XCCDF namespace as parent namespace (a Dublin Core prefix on dc_status is refused). The engine reads the models through the same StyleModels. Exports are unchanged: the 28-file comparison is byte-identical. Refs: cis-bench-fh9l.3 Signed-off-by: Aaron Lippold <lippold@gmail.com>
An empty cci_lookup.source_field names no field; the engine skipped it before the checks moved into the schema, and the schema does again. Refs: cis-bench-fh9l.3 Signed-off-by: Aaron Lippold <lippold@gmail.com>
The compatibility case for an empty cci_lookup.source_field now goes through MappingEngine and checks the written title, not only the load. Refs: cis-bench-fh9l.3 Signed-off-by: Aaron Lippold <lippold@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the style checks that need the XCCDF or Benchmark models from nine hand-written
MappingEngine._refuse_*methods into the style schema (StyleConfig), so a style rule has one home and every refusal names the path of the key.ConfigLoadergives the schemaStyleModelsas pydantic validation context, for each file of anextendschain: the XCCDF models of the style's version, the Recommendation and Benchmark models, and the engine's own transform lookup and template parser (one of each).RecommendationField,RecommendationPathandBenchmarkFieldchecksource_field, sources, children and element sources;cci_lookup.source_fieldmust hold CIS controls.TransformNamechecks the registry.Templatechecks its filters in the strings the engine fills; a filter-like text in a string nothing fills (severity,style_name) is plain text.group_bynames a field of the items, and the target must repeat and take elements of every namespace but XCCDF's. The holder's wildcard is read with the XCCDF namespace as parent namespace, and a Dublin Core prefix ondc_statusis refused.StyleModels; the nine methods, their constants and the engine's ownXmlContextare deleted.Every refusal of the nine methods was listed with the test that covers it before any deletion; the four with no test got one first, passing on the old code. Empty names keep their old behaviour.
Verification: 2821 tests passed,
tests/scripts53, mypy, ruff, format,mkdocs build --strict; 28 XCCDF exports (9 cached benchmarks and 5 synthetic fixtures, DISA and CIS) byte-identical to the exports before this change and valid.Card: cis-bench-fh9l.3 (template variables and the nested child type follow in cis-bench-fh9l.12 and cis-bench-fh9l.13)