Skip to content

catalog_validator

trestle.core.catalog_validator ¤

Validate catalog by confirming no duplicate param ids.

logger ¤

Classes¤

CatalogValidator (Validator) ¤

Validator to confirm all param ids in catalog are unique.

Source code in trestle/core/catalog_validator.py
class CatalogValidator(Validator):
    """Validator to confirm all param ids in catalog are unique."""

    def model_is_valid(self, model: TopLevelOscalModel, quiet: bool) -> bool:
        """
        Test if the model is valid.

        args:
            model: A top level OSCAL model.
            quiet: Don't report msgs unless invalid.

        returns:
            True (valid) if it is not a catalog, or it is a catalog and its links are 1:1 with resources.
        """
        if not isinstance(model, Catalog):
            return True
        catalog: Catalog = model
        cat_interface = CatalogInterface(catalog)
        param_ids = set()
        for control in cat_interface.get_all_controls_from_dict():
            for param in as_list(control.params):
                if param.id in param_ids:
                    logger.warning(f'Catalog has duplicated parameter id: {param.id} in control {control.id}')
                    return False
                param_ids.add(param.id)
        for param_id in cat_interface.loose_param_dict.keys():
            if param_id in param_ids:
                logger.warning(f'Catalog has duplicated parameter id: {param.id} in control {control.id}')
                return False
        return True
Methods¤
model_is_valid(self, model, quiet) ¤

Test if the model is valid.

Parameters:

Name Type Description Default
model ~TopLevelOscalModel

A top level OSCAL model.

required
quiet bool

Don't report msgs unless invalid.

required

Returns:

Type Description
True (valid) if it is not a catalog, or it is a catalog and its links are 1

1 with resources.

Source code in trestle/core/catalog_validator.py
def model_is_valid(self, model: TopLevelOscalModel, quiet: bool) -> bool:
    """
    Test if the model is valid.

    args:
        model: A top level OSCAL model.
        quiet: Don't report msgs unless invalid.

    returns:
        True (valid) if it is not a catalog, or it is a catalog and its links are 1:1 with resources.
    """
    if not isinstance(model, Catalog):
        return True
    catalog: Catalog = model
    cat_interface = CatalogInterface(catalog)
    param_ids = set()
    for control in cat_interface.get_all_controls_from_dict():
        for param in as_list(control.params):
            if param.id in param_ids:
                logger.warning(f'Catalog has duplicated parameter id: {param.id} in control {control.id}')
                return False
            param_ids.add(param.id)
    for param_id in cat_interface.loose_param_dict.keys():
        if param_id in param_ids:
            logger.warning(f'Catalog has duplicated parameter id: {param.id} in control {control.id}')
            return False
    return True

handler: python