Bases: Validator
Validator to confirm all param ids in catalog are unique.
Source code in trestle/core/catalog_validator.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | class CatalogValidator(Validator):
"""Validator to confirm all param ids in catalog are unique."""
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 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
|
Functions
model_is_valid(model, quiet, trestle_root=None)
Test if the model is valid.
Parameters:
Name | Type | Description | Default |
model | TopLevelOscalModel | | required |
quiet | bool | Don't report msgs unless invalid. | required |
Returns:
Type | Description |
bool | 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | 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 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
|