Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design/handler-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ field_name:

- `MappingEngine.generate_metadata_from_config()`
- `MappingEngine._build_config_element()`
- `MappingEngine._refuse_unwritable_metadata_mappings()` (when the style loads)
- `StyleConfig` in `style_config.py` checks the mapping when the style loads, with the XCCDF models as validation context

---

Expand Down
23 changes: 15 additions & 8 deletions docs/design/xccdf-mapping-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,38 @@ The type that holds the content is the one the XCCDF model gives the Rule's targ

### Checked when the style loads

The style schema (`MetadataFromConfigMapping` in `style_config.py`) refuses a metadata
mapping, with the path of the key, when it:
The style schema (`MetadataFromConfigMapping` and `StyleConfig` in `style_config.py`)
refuses a metadata mapping when the style loads, with the path of the key, when it:

- sets a key the builder does not read, at any level (`metadata_spec`, `group_element`,
`item_element` and each of its `children`, to any depth)
- leaves out `source_field`, `metadata_spec`, `root_element`, `namespace_prefix`, `group_by`,
`group_element`, or the `element` of the group, the item or a child; or gives an empty
`namespace_prefix`
`source_field` or `namespace_prefix`
- names an element or attribute that is not an XML name without a prefix (`xsi:type`,
`{uri}name`, `two words` and `xmlns` are refused)
- sets a removed key: `requires_post_processing`, `metadata_spec.namespace` (the URI comes
from `benchmark.namespaces`)

XCCDF allows only elements from another namespace inside `metadata`
(`xsd:any namespace="##other"`), and XCCDF 1.1.4 Rules have no `metadata` element. These
checks need the XCCDF and Benchmark models, so the engine makes them when it loads the style,
before any export; it refuses a metadata mapping that:
checks need the models, which `ConfigLoader` gives the schema as validation context
(`StyleModels`: the XCCDF models of the style's version, the Recommendation and Benchmark
models); the same load refuses a metadata mapping that:

- targets an element the XCCDF version's Rule does not have (any metadata mapping on 1.1.4),
or one that cannot hold repeated elements of the mapping's namespace (`title`, `ident`,
`dc_status`, `signature`)
- has an empty `source_field`, or a `group_by` that is empty or no field of the listed items
or one whose type does not repeat and take elements of every namespace but XCCDF's
(`title`, `ident`, `signature`, and `dc_status`, whose type takes Dublin Core elements
only, even when the mapping's prefix is the Dublin Core one)
- has a `source_field` that is no list field of the Recommendation, or a `group_by` that is
empty or no field of the listed items
- has a `namespace_prefix` `benchmark.namespaces` does not declare, or one that resolves to
the XCCDF namespace

The wildcard of the holder's type is read with the XCCDF namespace as its parent namespace,
so `##other` means "not the XCCDF namespace" (xsdata resolves it that way only when told the
parent namespace).

An attribute value comes from the benchmark, so it is checked at export: a value the serializer
would write as an XML Schema type name (it starts with `{` and names a type, such as
`{http://www.w3.org/2001/XMLSchema}string`) stops the export with an error naming the
Expand Down
4 changes: 2 additions & 2 deletions docs/developer-guide/mapping-engine-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ xsdata writes it with the rest of the Rule, so its place among the Rule's childr
the schema the models were generated from, and its prefix is the one the root declares.
Nothing is inserted after serialization.

The engine checks every metadata mapping when the style loads (see
Every metadata mapping is checked when the style loads (see
[XCCDF mapping design](../design/xccdf-mapping-design.md#checked-when-the-style-loads)).
XCCDF 1.1.4 allows `<metadata>` only on the Benchmark, not inside a Rule, so a metadata
mapping on a 1.1.4 style (such as DISA) is refused with an error naming the version.
Expand Down Expand Up @@ -1225,7 +1225,7 @@ EOF
**Symptom:** the style is refused when it loads, naming the place and the transform:

```text
ValueError: field_mappings.title: Unknown transformation: strip_html
ValueError: my_style.yaml: field_mappings.title.simple.transform: Unknown transformation: strip_html
```

**Cause:** the mapping (or a `{value|filter}` in a template) names a transform no function is
Expand Down
4 changes: 2 additions & 2 deletions docs/technical-reference/mapping-engine-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ field_name:
- `MappingEngine.generate_metadata_from_config()` builds xsdata `AnyElement` content, held
by a `MetadataType` on `Rule.metadata`; the serializer writes it in schema order
- `MappingEngine._build_config_element()`
- `MappingEngine._refuse_unwritable_metadata_mappings()` checks the mapping when the style
loads ([XCCDF mapping design](../design/xccdf-mapping-design.md#checked-when-the-style-loads))
- `StyleConfig` (`style_config.py`) checks the mapping when the style loads, with the XCCDF
models as validation context ([XCCDF mapping design](../design/xccdf-mapping-design.md#checked-when-the-style-loads))

### 3. generate_profiles_from_rules - Profile Generation

Expand Down
Loading
Loading