def validate_action_str()

in smdebug_rulesconfig/actions/utils.py [0:0]


def validate_action_str(action_str, action_parameters):
    """
    Parse the action string as JSON within an exec call and verify that it matches the original action parameters.
    Note that we need the exec call to mimic the same behavior in the rules container.

    If this triggers a syntax error, the exec call is set up incorrectly and needs to be fixed.
    If this triggers a JSON decode error, the action string is badly formatted. This is probably due to invalid action
        parameters being specified (are you using any escape characters?)
    If this triggers an assertion error, the deserialized action JSON does not match the original action parameters,
        so the exec call is set up incorrectly and needs to be fixed.
    """
    try:
        exec(f'import json; assert json.loads("{action_str}") == {action_parameters}')
    except (SyntaxError, json.JSONDecodeError, AssertionError) as e:
        raise Exception(
            f"Error {type(e)} occurred during action string validation. See the docstring for more info."
        )