2022-12-18 21:16:46 +00:00
|
|
|
from typing import Any, Dict, List, Iterable
|
|
|
|
|
|
|
|
|
|
|
|
def match_task_arn(task: Dict[str, Any], arns: List[str]) -> bool:
|
2021-05-06 17:33:48 +00:00
|
|
|
return task["ReplicationTaskArn"] in arns
|
|
|
|
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
def match_task_id(task: Dict[str, Any], ids: List[str]) -> bool:
|
2021-05-06 17:33:48 +00:00
|
|
|
return task["ReplicationTaskIdentifier"] in ids
|
|
|
|
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
def match_task_migration_type(task: Dict[str, Any], migration_types: List[str]) -> bool:
|
2021-05-06 17:33:48 +00:00
|
|
|
return task["MigrationType"] in migration_types
|
|
|
|
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
def match_task_endpoint_arn(task: Dict[str, Any], endpoint_arns: List[str]) -> bool:
|
2021-05-06 17:33:48 +00:00
|
|
|
return (
|
|
|
|
task["SourceEndpointArn"] in endpoint_arns
|
|
|
|
or task["TargetEndpointArn"] in endpoint_arns
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
def match_task_replication_instance_arn(
|
|
|
|
task: Dict[str, Any], replication_instance_arns: List[str]
|
|
|
|
) -> bool:
|
2021-05-06 17:33:48 +00:00
|
|
|
return task["ReplicationInstanceArn"] in replication_instance_arns
|
|
|
|
|
|
|
|
|
|
|
|
task_filter_functions = {
|
|
|
|
"replication-task-arn": match_task_arn,
|
|
|
|
"replication-task-id": match_task_id,
|
|
|
|
"migration-type": match_task_migration_type,
|
|
|
|
"endpoint-arn": match_task_endpoint_arn,
|
|
|
|
"replication-instance-arn": match_task_replication_instance_arn,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
def filter_tasks(tasks: Iterable[Any], filters: List[Dict[str, Any]]) -> Any:
|
2021-05-06 17:33:48 +00:00
|
|
|
matching_tasks = tasks
|
|
|
|
|
|
|
|
for f in filters:
|
2022-12-18 21:16:46 +00:00
|
|
|
filter_function = task_filter_functions.get(f["Name"])
|
2021-05-06 17:33:48 +00:00
|
|
|
|
|
|
|
if not filter_function:
|
|
|
|
continue
|
|
|
|
|
2022-12-18 21:16:46 +00:00
|
|
|
# https://github.com/python/mypy/issues/12682
|
2021-05-06 17:33:48 +00:00
|
|
|
matching_tasks = filter(
|
2022-12-18 21:16:46 +00:00
|
|
|
lambda task: filter_function(task, f["Values"]), matching_tasks # type: ignore[arg-type]
|
2021-05-06 17:33:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return matching_tasks
|