Main top-level functionality
Public functions
validate_filters
validate_filters(
filters: dict, session_client: BaseClient | None = None
) -> None
Validate AWS SecurityHub filters to get findings.
Parameters:
-
(filtersdict) –The filters to validate
-
(session_clientBaseClient, default:None) –A boto session BaseClient for AWS SecurityHub Tries to create one if not provided
Raises:
-
ParamValidationError–If the filters contain invalid values
validate_updates
validate_updates(
updates: dict, session_client: BaseClient | None = None
) -> None
Validate AWS SecurityHub updates to findings.
Parameters:
-
(updatesdict) –The updates to make to (a set of) findings
-
(session_clientBaseClient, default:None) –A boto session BaseClient for AWS SecurityHub Tries to create one if not provided
Raises:
-
ParamValidationError–If the updates contain invalid values
Public classes
Rule
dataclass
Rule(
Filters: dict[str, list[dict[str, Any]]],
UpdatesToFilteredFindings: dict[str, Any],
client: BaseClient,
ExtraFeatures: dict[str, Any] = dict(),
)
Dataclass representing a SecurityHub management rule.
Methods:
-
__post_init__–Validate the rule upon initialization.
-
batch_update_findings–Batch update findings in AWS SecurityHub.
-
get_and_update–Get all the findings matching the rule's filters from AWS SecurityHub and update them according to the rule's updates.
-
match–Check if a finding matches the rule's filters.
__post_init__
__post_init__() -> None
Validate the rule upon initialization.
Manager
dataclass
Manager(
client: BaseClient,
DefaultRuleInput: dict[str, Any] = dict(),
_rules: list[Rule] = list(),
)
Dataclass managing rule creation.
Methods:
-
from_rules_document–Build a Manager with its rules registered from a parsed rules document.
-
get_and_update_all–Get all the findings matching the rules' filters from AWS SecurityHub and update them according to the rules' updates.
-
match_and_update–Match one finding against all configured rules and apply updates for each match.
-
process_finding–Match one finding against all configured rules and apply updates for each match.
-
set_rules–Create rules based on the provided input and the default rule input.
from_rules_document
classmethod
from_rules_document(
rules: dict[str, Any], client: BaseClient
) -> Manager
Build a Manager with its rules registered from a parsed rules document.
Parameters:
-
(rulesdict[str, Any]) –The parsed rules document. Must contain a top-level
Ruleskey, and may contain aManagerConfigkey with aDefaultRuleInputsub-key. -
(clientBaseClient) –The boto3 Security Hub client to use for the manager and its rules.
Returns:
-
Manager–A Manager with its rules already registered via
Manager.set_rules.
Raises:
-
ValueError–If the rules document has no top-level
Ruleskey, or ifManagerConfigcontains keys other thanDefaultRuleInput(most commonly caused by puttingExtraFeaturesnext to, rather than inside,DefaultRuleInput).
get_and_update_all
get_and_update_all() -> bool
Get all the findings matching the rules' filters from AWS SecurityHub and update them according to the rules' updates.
Returns:
-
bool–True if all findings were processed successfully, False otherwise
process_finding
process_finding(
finding: dict[str, Any],
) -> MatchAndUpdateResult
Match one finding against all configured rules and apply updates for each match.
Unlike match_and_update, this also reports how many rules matched, so callers can
distinguish "nothing matched" from "everything matched and was processed successfully".
Parameters:
Returns:
-
MatchAndUpdateResult–The number of rules that matched and whether all matching updates were processed.
set_rules
set_rules(rules_input: list[dict[str, Any]]) -> list[Rule]
MatchAndUpdateResult
dataclass
MatchAndUpdateResult(
matched_rules: int, all_processed: bool
)
The outcome of matching and updating a single finding against all configured rules.
Attributes:
-
matched_rules(int) –The number of rules that matched the finding.
-
all_processed(bool) –True if there were no unprocessed findings for any of the matched rules' updates, False otherwise. Vacuously True when no rule matched.
NoteTextConfig
dataclass
NoteTextConfig(Mode: str, Key: str = '')
Configuration for note text handling.
Raises:
-
ValueError–If the Mode is not one of the allowed values.
-
ValueError–If the Key is not a string when Mode is 'jsonUpdate'.
Methods:
-
__post_init__–Validate the NoteTextConfig upon initialization.
__post_init__
__post_init__() -> None
Validate the NoteTextConfig upon initialization.