Repository navigation
refactor(exporters): dispatch map_rule on the typed field mapping - #63
Merged
Merged
Conversation
map_rule loops over the style model's field mappings and matches on each mapping's model; an unhandled structure is a mypy error (assert_never). The simple, composite, embedded_xml_tags, nested and dublin_core builders take their typed variants (_build_field_value, _composite_text, create_embedded_xml_tags, dublin_core_elements, and the new _nested_element, _references and _element_from_value). The loader's per-file pass for cci_lookup.mapping_file matches the raw YAML's shape. No .get() on field-mapping data is left in mapping_engine.py. The defaults those reads carried are stated once in the models: a composite's separator is a blank line, a tag source's separator and an embedded tag's content are "", a nested mapping's system and a dublin_core href are "", and multiple is false. Rule attribute maps take RuleTemplateText (always text). Checks the schema already makes at load are gone from the engine (missing components or sources, an unknown dublin_core source_logic), and apply_field_mapping, which nothing called, is deleted. Tests that changed engine.config dicts now load a style file that extends the DISA style. The 28 exports are byte-identical. Refs: cis-bench-fh9l.14 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.
map_rulenow dispatches on the field mapping's model, and the remaining field-mapping builders read typed models instead of dicts.map_ruleloops over the style model's field mappings and usesmatchon each one's type. The last case isassert_never, so a structure with no case is a mypy error (checked by dropping one)._build_field_value,_composite_text,create_embedded_xml_tagsanddublin_core_elementstake typed models. The old in-loop branches are now_nested_element,_referencesand_element_from_value, with the same logic.cci_lookup.mapping_filematches the shape of the raw YAML. No.get()on field-mapping data is left inmapping_engine.py.""; a nested mapping'ssystemand a Dublin Corehrefare"";multipleis false. Rule attribute maps takeRuleTemplateText.componentsorsources, an unknown Dublin Coresource_logic).apply_field_mapping, which nothing called, is deleted, and the developer guide's code reference shows the real loop.engine.configdicts now load a style file that extends the DISA style. A source-text assertion on the loop is replaced by a test that builds a Rule from one mapping of each of the seven structures.Checks:
tests/scripts, mypy, ruff andmkdocs build --strictpass.nextand passcis-bench validate.Card: cis-bench-fh9l.14.