Skip to content

refs_validator

trestle.core.refs_validator ¤

Validate by confirming all refs have corresponding id.

Classes¤

RefsValidator (Validator) ¤

Validator to confirm all references in responsible parties are found in roles.

Source code in trestle/core/refs_validator.py
class RefsValidator(Validator):
    """Validator to confirm all references in responsible parties are found in roles."""

    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 the model's responsible parties match those found in roles.
        """
        roles = as_list(model.metadata.roles)
        role_ids = [role.id for role in roles]
        responsible_parties = as_list(model.metadata.responsible_parties)
        if not responsible_parties:
            return True
        party_roles = [party.role_id for party in responsible_parties]
        # return true if all party roles are in the roles list
        return all(item in role_ids for item in party_roles)
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
bool

True (valid) if the model's responsible parties match those found in roles.

Source code in trestle/core/refs_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 the model's responsible parties match those found in roles.
    """
    roles = as_list(model.metadata.roles)
    role_ids = [role.id for role in roles]
    responsible_parties = as_list(model.metadata.responsible_parties)
    if not responsible_parties:
        return True
    party_roles = [party.role_id for party in responsible_parties]
    # return true if all party roles are in the roles list
    return all(item in role_ids for item in party_roles)

handler: python