Skip to content

trestle.transforms.implementations.aws_config

trestle.transforms.implementations.aws_config ¤

Facilitate OSCAL-AWS Config transformation.

Transforms AWS Config compliance evaluation results (the JSON shape returned by the AWS Config get-compliance-details-by-config-rule / get-compliance-details-by-resource APIs: a top-level EvaluationResults list of EvaluationResult objects, see https://docs.aws.amazon.com/config/latest/APIReference/API_EvaluationResult.html) into OSCAL Assessment Results, following the same Task + ResultsTransformer + private results-factory shape used by osco.py / tanium.py in this package.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

AwsConfigResultToOscalARTransformer ¤

Bases: ResultsTransformer


              flowchart TD
              trestle.transforms.implementations.aws_config.AwsConfigResultToOscalARTransformer[AwsConfigResultToOscalARTransformer]
              trestle.transforms.transformer_factory.ResultsTransformer[ResultsTransformer]
              trestle.transforms.transformer_factory.TransformerBase[TransformerBase]

                              trestle.transforms.transformer_factory.ResultsTransformer --> trestle.transforms.implementations.aws_config.AwsConfigResultToOscalARTransformer
                                trestle.transforms.transformer_factory.TransformerBase --> trestle.transforms.transformer_factory.ResultsTransformer
                



              click trestle.transforms.implementations.aws_config.AwsConfigResultToOscalARTransformer href "" "trestle.transforms.implementations.aws_config.AwsConfigResultToOscalARTransformer"
              click trestle.transforms.transformer_factory.ResultsTransformer href "" "trestle.transforms.transformer_factory.ResultsTransformer"
              click trestle.transforms.transformer_factory.TransformerBase href "" "trestle.transforms.transformer_factory.TransformerBase"
            

Interface for AWS Config transformer.

Source code in trestle/transforms/implementations/aws_config.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class AwsConfigResultToOscalARTransformer(ResultsTransformer):
    """Interface for AWS Config transformer."""

    def __init__(self) -> None:
        """Initialize."""
        self._modes: Dict[str, Any] = {}

    def set_modes(self, modes: Dict[str, Any]) -> None:
        """Set the transformation modes."""
        if modes is not None:
            self._modes = modes

    @property
    def analysis(self) -> List[str]:
        """Return statistics."""
        return self._results_factory.analysis if hasattr(self, '_results_factory') else []

    def transform(self, blob: str) -> Results:
        """
        Transform AWS Config evaluation results into OSCAL results.

        Args:
            blob: text (json) blob containing AWS Config evaluation results,
                shaped as ``{"EvaluationResults": [EvaluationResult, ...]}``.

        Returns:
            Results containing a single OSCAL Result with one Observation
            per input EvaluationResult.
        """
        self._results_factory = _OscalResultsFactory(self.get_timestamp())
        data = json.loads(blob)
        for evaluation_result in data.get('EvaluationResults', []):
            self._results_factory.ingest(evaluation_result)
        results = Results.model_construct(root=[])
        results.root.append(self._results_factory.result)
        return results
Attributes¤
analysis property ¤

Return statistics.

Methods:¤
__init__() ¤

Initialize.

Source code in trestle/transforms/implementations/aws_config.py
54
55
56
def __init__(self) -> None:
    """Initialize."""
    self._modes: Dict[str, Any] = {}
set_modes(modes) ¤

Set the transformation modes.

Source code in trestle/transforms/implementations/aws_config.py
58
59
60
61
def set_modes(self, modes: Dict[str, Any]) -> None:
    """Set the transformation modes."""
    if modes is not None:
        self._modes = modes
transform(blob) ¤

Transform AWS Config evaluation results into OSCAL results.

Parameters:

Name Type Description Default
blob str

text (json) blob containing AWS Config evaluation results, shaped as {"EvaluationResults": [EvaluationResult, ...]}.

required

Returns:

Type Description
Results

Results containing a single OSCAL Result with one Observation

Results

per input EvaluationResult.

Source code in trestle/transforms/implementations/aws_config.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def transform(self, blob: str) -> Results:
    """
    Transform AWS Config evaluation results into OSCAL results.

    Args:
        blob: text (json) blob containing AWS Config evaluation results,
            shaped as ``{"EvaluationResults": [EvaluationResult, ...]}``.

    Returns:
        Results containing a single OSCAL Result with one Observation
        per input EvaluationResult.
    """
    self._results_factory = _OscalResultsFactory(self.get_timestamp())
    data = json.loads(blob)
    for evaluation_result in data.get('EvaluationResults', []):
        self._results_factory.ingest(evaluation_result)
    results = Results.model_construct(root=[])
    results.root.append(self._results_factory.result)
    return results

handler: python