Skip to content

control_context

trestle.core.control_context ¤

Provide a context for control operations.

Classes¤

ContextPurpose (Enum) ¤

Specify the modality of the control markdown.

Source code in trestle/core/control_context.py
class ContextPurpose(Enum):
    """Specify the modality of the control markdown."""

    CATALOG = 0
    COMPONENT = 1
    PROFILE = 2
    SSP = 3
CATALOG ¤
COMPONENT ¤
PROFILE ¤
SSP ¤

ControlContext dataclass ¤

Class encapsulating control markdown usage.

Source code in trestle/core/control_context.py
@dataclass
class ControlContext:
    """Class encapsulating control markdown usage."""

    purpose: ContextPurpose
    to_markdown: bool
    trestle_root: pathlib.Path
    md_root: pathlib.Path
    prompt_responses: bool
    additional_content: bool
    overwrite_header_values: bool
    set_parameters_flag: bool
    yaml_header: Optional[Dict[Any, Any]] = None
    sections_dict: Optional[Dict[str, str]] = None
    profile: Optional[prof.Profile] = None
    required_sections: Optional[str] = None
    allowed_sections: Optional[str] = None
    comp_def: Optional[comp.ComponentDefinition] = None
    comp_name: Optional[str] = None
    inherited_props: Optional[Dict[str, Any]] = None
    rules_dict: Optional[Dict[str, Dict[str, str]]] = None
    rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None
    rules_param_vals: Optional[List[Dict[str, str]]] = None
    control_implementation: Optional[comp.ControlImplementation] = None
    uri_name_map: Optional[Dict[str, str]] = None

    @classmethod
    def generate(
        cls,
        purpose: ContextPurpose,
        to_markdown: bool,
        trestle_root: pathlib.Path,
        md_root: pathlib.Path,
        prompt_responses=False,
        additional_content=False,
        overwrite_header_values=False,
        set_parameters_flag=False,
        yaml_header: Optional[Dict[Any, Any]] = None,
        sections_dict: Optional[Dict[str, str]] = None,
        profile: Optional[prof.Profile] = None,
        required_sections: Optional[str] = None,
        allowed_sections: Optional[str] = None,
        comp_def: Optional[comp.ComponentDefinition] = None,
        comp_name: Optional[str] = None,
        inherited_props: Optional[Dict[str, Any]] = None,
        rules_dict: Optional[Dict[str, Dict[str, str]]] = None,
        rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None,
        rules_param_vals: Optional[List[Dict[str, str]]] = None,
        control_implementation: Optional[comp.ControlImplementation] = None,
        uri_name_map: Optional[Dict[str, str]] = None
    ) -> ControlContext:
        """Generate control context of the needed type."""
        context = cls(
            purpose,
            to_markdown,
            trestle_root,
            md_root,
            prompt_responses,
            additional_content,
            overwrite_header_values,
            set_parameters_flag,
            yaml_header=yaml_header,
            sections_dict=sections_dict,
            profile=profile,
            required_sections=required_sections,
            allowed_sections=allowed_sections,
            comp_def=comp_def,
            comp_name=comp_name,
            inherited_props=inherited_props,
            rules_dict=rules_dict,
            rules_params_dict=rules_params_dict,
            rules_param_vals=rules_param_vals,
            control_implementation=control_implementation,
            uri_name_map=uri_name_map
        )
        context.yaml_header = as_dict(yaml_header)
        context.sections_dict = as_dict(sections_dict)
        # catalog generate always sets params
        if to_markdown:
            context.set_parameters = True
        return context

    @classmethod
    def clone(cls, context: ControlContext) -> ControlContext:
        """Create a deep clone of the context without duplicating large objects."""
        new_context = cls(
            context.purpose,
            context.to_markdown,
            context.trestle_root,
            context.md_root,
            context.prompt_responses,
            context.additional_content,
            context.overwrite_header_values,
            context.set_parameters_flag,
            yaml_header=copy.deepcopy(context.yaml_header),
            sections_dict=copy.deepcopy(context.sections_dict),
            profile=context.profile,
            required_sections=context.required_sections,
            allowed_sections=context.allowed_sections,
            comp_def=context.comp_def,
            comp_name=context.comp_name,
            inherited_props=copy.deepcopy(context.inherited_props),
            rules_dict=copy.deepcopy(context.rules_dict),
            rules_params_dict=copy.deepcopy(context.rules_params_dict),
            rules_param_vals=context.rules_param_vals,
            control_implementation=copy.deepcopy(context.control_implementation),
            uri_name_map=context.uri_name_map
        )
        return new_context
additional_content: bool dataclass-field ¤
allowed_sections: Optional[str] dataclass-field ¤
comp_def: Optional[trestle.oscal.component.ComponentDefinition] dataclass-field ¤
comp_name: Optional[str] dataclass-field ¤
control_implementation: Optional[trestle.oscal.component.ControlImplementation] dataclass-field ¤
inherited_props: Optional[Dict[str, Any]] dataclass-field ¤
md_root: Path dataclass-field ¤
overwrite_header_values: bool dataclass-field ¤
profile: Optional[trestle.oscal.profile.Profile] dataclass-field ¤
prompt_responses: bool dataclass-field ¤
purpose: ContextPurpose dataclass-field ¤
required_sections: Optional[str] dataclass-field ¤
rules_dict: Optional[Dict[str, Dict[str, str]]] dataclass-field ¤
rules_param_vals: Optional[List[Dict[str, str]]] dataclass-field ¤
rules_params_dict: Optional[Dict[str, Dict[str, Any]]] dataclass-field ¤
sections_dict: Optional[Dict[str, str]] dataclass-field ¤
set_parameters_flag: bool dataclass-field ¤
to_markdown: bool dataclass-field ¤
trestle_root: Path dataclass-field ¤
uri_name_map: Optional[Dict[str, str]] dataclass-field ¤
yaml_header: Optional[Dict[Any, Any]] dataclass-field ¤
Methods¤
__eq__(self, other) special ¤
__init__(self, purpose, to_markdown, trestle_root, md_root, prompt_responses, additional_content, overwrite_header_values, set_parameters_flag, yaml_header=None, sections_dict=None, profile=None, required_sections=None, allowed_sections=None, comp_def=None, comp_name=None, inherited_props=None, rules_dict=None, rules_params_dict=None, rules_param_vals=None, control_implementation=None, uri_name_map=None) special ¤
__repr__(self) special ¤
clone(context) classmethod ¤

Create a deep clone of the context without duplicating large objects.

Source code in trestle/core/control_context.py
@classmethod
def clone(cls, context: ControlContext) -> ControlContext:
    """Create a deep clone of the context without duplicating large objects."""
    new_context = cls(
        context.purpose,
        context.to_markdown,
        context.trestle_root,
        context.md_root,
        context.prompt_responses,
        context.additional_content,
        context.overwrite_header_values,
        context.set_parameters_flag,
        yaml_header=copy.deepcopy(context.yaml_header),
        sections_dict=copy.deepcopy(context.sections_dict),
        profile=context.profile,
        required_sections=context.required_sections,
        allowed_sections=context.allowed_sections,
        comp_def=context.comp_def,
        comp_name=context.comp_name,
        inherited_props=copy.deepcopy(context.inherited_props),
        rules_dict=copy.deepcopy(context.rules_dict),
        rules_params_dict=copy.deepcopy(context.rules_params_dict),
        rules_param_vals=context.rules_param_vals,
        control_implementation=copy.deepcopy(context.control_implementation),
        uri_name_map=context.uri_name_map
    )
    return new_context
generate(purpose, to_markdown, trestle_root, md_root, prompt_responses=False, additional_content=False, overwrite_header_values=False, set_parameters_flag=False, yaml_header=None, sections_dict=None, profile=None, required_sections=None, allowed_sections=None, comp_def=None, comp_name=None, inherited_props=None, rules_dict=None, rules_params_dict=None, rules_param_vals=None, control_implementation=None, uri_name_map=None) classmethod ¤

Generate control context of the needed type.

Source code in trestle/core/control_context.py
@classmethod
def generate(
    cls,
    purpose: ContextPurpose,
    to_markdown: bool,
    trestle_root: pathlib.Path,
    md_root: pathlib.Path,
    prompt_responses=False,
    additional_content=False,
    overwrite_header_values=False,
    set_parameters_flag=False,
    yaml_header: Optional[Dict[Any, Any]] = None,
    sections_dict: Optional[Dict[str, str]] = None,
    profile: Optional[prof.Profile] = None,
    required_sections: Optional[str] = None,
    allowed_sections: Optional[str] = None,
    comp_def: Optional[comp.ComponentDefinition] = None,
    comp_name: Optional[str] = None,
    inherited_props: Optional[Dict[str, Any]] = None,
    rules_dict: Optional[Dict[str, Dict[str, str]]] = None,
    rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None,
    rules_param_vals: Optional[List[Dict[str, str]]] = None,
    control_implementation: Optional[comp.ControlImplementation] = None,
    uri_name_map: Optional[Dict[str, str]] = None
) -> ControlContext:
    """Generate control context of the needed type."""
    context = cls(
        purpose,
        to_markdown,
        trestle_root,
        md_root,
        prompt_responses,
        additional_content,
        overwrite_header_values,
        set_parameters_flag,
        yaml_header=yaml_header,
        sections_dict=sections_dict,
        profile=profile,
        required_sections=required_sections,
        allowed_sections=allowed_sections,
        comp_def=comp_def,
        comp_name=comp_name,
        inherited_props=inherited_props,
        rules_dict=rules_dict,
        rules_params_dict=rules_params_dict,
        rules_param_vals=rules_param_vals,
        control_implementation=control_implementation,
        uri_name_map=uri_name_map
    )
    context.yaml_header = as_dict(yaml_header)
    context.sections_dict = as_dict(sections_dict)
    # catalog generate always sets params
    if to_markdown:
        context.set_parameters = True
    return context

handler: python