Skip to content

duplicates_validator

trestle.core.duplicates_validator ¤

Validate by confirming no duplicate uuids.

Classes¤

DuplicatesValidator ¤

Bases: Validator

Validator to check for duplicate uuids and param_ids in the model.

Source code in trestle/core/duplicates_validator.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class DuplicatesValidator(Validator):
    """Validator to check for duplicate uuids and param_ids in the model."""

    def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
        """
        Test if the model is valid and contains no duplicate uuids or param_ids.

        args:
            model: An Oscal model that can be passed to the validator.
            quiet: Don't report msgs unless invalid.

        returns:
            True (valid) if the model does not contain duplicate uuid's.
        """
        if not ModelUtils.has_no_duplicate_values_by_name(model, 'uuid'):
            return False
        # only profile, comp-def and ssp have set-params and only set-params have param_id
        # param_id is required to be unique in profiles but not in other models
        if isinstance(model, Profile):
            return ModelUtils.has_no_duplicate_values_by_name(model, 'param_id')
        return True
Functions¤
model_is_valid(model, quiet, trestle_root=None) ¤

Test if the model is valid and contains no duplicate uuids or param_ids.

Parameters:

Name Type Description Default
model OscalBaseModel

An Oscal model that can be passed to the validator.

required
quiet bool

Don't report msgs unless invalid.

required

Returns:

Type Description
bool

True (valid) if the model does not contain duplicate uuid's.

Source code in trestle/core/duplicates_validator.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
    """
    Test if the model is valid and contains no duplicate uuids or param_ids.

    args:
        model: An Oscal model that can be passed to the validator.
        quiet: Don't report msgs unless invalid.

    returns:
        True (valid) if the model does not contain duplicate uuid's.
    """
    if not ModelUtils.has_no_duplicate_values_by_name(model, 'uuid'):
        return False
    # only profile, comp-def and ssp have set-params and only set-params have param_id
    # param_id is required to be unique in profiles but not in other models
    if isinstance(model, Profile):
        return ModelUtils.has_no_duplicate_values_by_name(model, 'param_id')
    return True

handler: python