Boto-related utilities
Public functions
get_values_by_boto_argument
get_values_by_boto_argument(
finding: dict, name: str
) -> list[Any]
Get the values in a finding for a given boto argument name.
Some arguments in: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/securityhub/client/get_findings.html do not directly map to finding fields as per: https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-findings-format.html Therefore, this method handles those special cases. The method returns a list to handle both single-value and multi-value fields.
Parameters:
Returns:
stub_boto_client
stub_boto_client(
boto_session_client: BaseClient,
calls: list[BotoStubCall],
) -> Generator[Stubber, None, None]
Generate a context in which a boto client is stubbed with the specified calls.
This function saves you from writing the boilerplate code to create a Stubber like: https://botocore.amazonaws.com/v1/documentation/api/latest/reference/stubber.html.
Use like this:
boto_client = botocore.session.get_session().create_client("servicename")
call = BotoStubCall(
method="get_resources",
service_response={"Resources": {"arn": "abc"}},
expected_params={"Filters": "filters"},
)
with stub_boto_client(boto_client, [call]) as _:
boto_client.get_resources(Filters="filters")
Or the last part slightly more dynamically like this:
with stub_boto_client(boto_client, [call]) as _:
getattr(boto_client, call.method)(**call.expected_params)
Parameters:
-
(boto_session_clientBaseClient) –The boto session BaseClient that will be stubbed
-
(callslist[BotoStubCall]) –The list of BotoStubCall instances representing the calls to add to the stubber
Yields:
-
Generator[Stubber, None, None]–A generator yielding a Stubber instance with the specified calls added. Usually not needed to be used directly, because the stubbing is active on the original session client within the context as a side effect.
validate_call_params
validate_call_params(
boto_stub_calls: list[BotoStubCall],
boto_session_client: BaseClient,
) -> None
Validate boto call parameters by attempting to call the methods with the expected parameters in a stubbed context.
Parameters:
-
(boto_stub_callslist[BotoStubCall]) –The list of BotoStubCall instances representing the calls to validate
-
(boto_session_clientBaseClient) –The boto session BaseClient that will be used for validation
Raises:
-
ParamValidationError–If any of the boto parameters contain invalid values