Skip to content

refs_validator

trestle.core.refs_validator ¤

Validate by confirming all refs have corresponding id.

Attributes¤

Classes¤

RefsValidator ¤

Bases: Validator

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

Source code in trestle/core/refs_validator.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class RefsValidator(Validator):
    """Validator to confirm all references in responsible parties are found in roles."""

    def model_is_valid(
        self, model: TopLevelOscalModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None
    ) -> 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)
Functions¤
model_is_valid(model, quiet, trestle_root=None) ¤

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def model_is_valid(
    self, model: TopLevelOscalModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None
) -> 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)

Functions¤

handler: python