Repository navigation
refactor(exporters): type field mappings by their structure - #57
Merged
Merged
Conversation
field_mappings is a discriminated union on structure (left out = simple), built with pydantic's Discriminator and Tag. simple, composite, nested and dublin_core each declare the keys the engine reads for that structure and refuse any other; embedded_xml_tags, ident_from_list and metadata_from_config are accepted as JSON-like data until typed. An unknown structure is refused with the known ones; null still switches off an inherited mapping. Template and TransformName are the shared types of every template and transform value; a dublin_core mapping's dc_elements prefixes must be bound, as the benchmark reference's are. Keys nothing read are gone from the styles: field-mapping descriptions are YAML comments; optional, content (the empty fix comes from its attributes; the fix text is fixtext's), multiple on dublin_core, and cci_lookup.enabled and deduplicate_nist are refused with what happens instead. A nested mapping takes exactly one child, which the engine builds; source_logic takes only the value its structure acts on. Exports are unchanged. Signed-off-by: Aaron Lippold <lippold@gmail.com>
A Dublin Core element's content is filled with {variables} when it is
written, so it is a Template like every other template value of the
typed field mappings (and of the benchmark reference, which shares the
model); content written with no value is refused with the shared "has
no value" message. The style_config module docstring describes the typed
field-mapping structures.
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.
A field mapping's keys depend on its
structure, and until now a key that didn't belong to the structure was ignored. This PR makesfield_mappingsa pydantic discriminated union onstructure(left out meanssimple), built with pydantic'sDiscriminatorandTag.What each structure takes
The keys are the ones the engine reads for that structure, measured from
mapping_engine.py; any other key is refused.simple:source_field,transform,source_logic(onlycci_lookup_with_deduplication),cci_lookup(source_field,cis_controls_version,extract,fallback_cci,mapping_file),multiple, and anyattributes.composite:sources(required; each withfield,label,transform),separator, and anyattributes.nested: exactly one child inchildren(source_field,element,transform). The engine builds only the first child, so a second is refused rather than dropped.attributes.systemonly.dublin_core:source_field(required),source_logic(onlynist_after_cci_deduplication),dc_elements, andattributes.href. Itsdc_elementsprefixes must be bound inbenchmark.namespaces, as the benchmark reference's are.target_element.embedded_xml_tags,ident_from_listandmetadata_from_configare accepted as JSON-like data until they get their own types.structureis refused with the list of known ones.nullstill switches off a mapping a style inherits.TemplateandTransformNameare the shared types for every template and transform value of the four typed structures. Dublin Core element text is aTemplatetoo.Keys removed from the styles
None of these keys was ever read, so exports are unchanged:
descriptiontext is now YAML comments.optional(cis.yamlwarning): a mapping with no value is already left out.content: ""(disa.yamlfix):fixis written empty because it has attributes and no source. The fix text itself comes from thefixtextmapping, unchanged.multipleondublin_core: one reference is written per NIST control regardless.cci_lookup.enabledanddeduplicate_nist: the lookup runs because ofsource_logic, and deduplication is switched bycci_deduplication.enabled.Each is refused with a hint saying what happens instead. The CCIs and fix text in the exports are unchanged.
Docs
yaml-config-reference.mdandmapping-engine-guide.mddescribe the structures. The "Static Content Field" section, which described acontentkey nothing read, is corrected. The CCI andoptionalexamples, and examples of keys that never existed (condition,default), are fixed.Verification
pytest tests/: 2740 passed.pytest tests/scripts: 53 passed. mypy,ruff check,ruff format --checkandmkdocs build --strictare clean.cis-bench validatepasses on all 28.