From 51079ede57cf3af9fc6f724df64a9acd29585595 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 13 Jun 2024 11:15:49 +0000 Subject: [PATCH] feat: finished connect_in_graph_for resources --- plugins/aws/fix_plugin_aws/resource/backup.py | 8 +++++--- plugins/aws/tools/aws_model_gen.py | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/aws/fix_plugin_aws/resource/backup.py b/plugins/aws/fix_plugin_aws/resource/backup.py index 2e3d45f041..ba1fbdba71 100644 --- a/plugins/aws/fix_plugin_aws/resource/backup.py +++ b/plugins/aws/fix_plugin_aws/resource/backup.py @@ -7,7 +7,7 @@ from fix_plugin_aws.resource.base import AwsResource, AwsApiSpec, GraphBuilder from fix_plugin_aws.utils import TagsValue, ToDict from fixlib.baseresources import ModelReference -from fixlib.json_bender import Bender, S, ForallBend, Bend, bend +from fixlib.json_bender import Bender, S, ForallBend, Bend from fixlib.types import Json log = logging.getLogger("fix.plugins.aws") @@ -122,7 +122,7 @@ class AwsBackupProtectedResource(AwsResource): ) reference_kinds: ClassVar[ModelReference] = { "predecessors": {"default": ["aws_backup_vault", "aws_backup_recovery_point"]}, - "successors": {"default": ["aws_resource"]}, + "successors": {"default": ["aws_s3_bucket", "aws_ec2_instance", "aws_ec2_volume","aws_rds_cluster","aws_rds_instance","aws_dynamodb_table","aws_dynamodb_global_table","aws_efs_file_system", "aws_redshift_cluster", "aws_cloudformation_stack"]}, } api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("backup", "list-protected-resources", "Results") mapping: ClassVar[Dict[str, Bender]] = { @@ -293,7 +293,7 @@ class AwsBackupRecoveryPoint(AwsResource): "These recovery points are crucial for restoring data during disaster recovery or operational recovery scenarios." ) reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": ["aws_backup_vault"]}, + "predecessors": {"default": ["aws_backup_vault", "aws_backup_plan"]}, } # Resource will be collect by AwsBackupVault mapping: ClassVar[Dict[str, Bender]] = { @@ -352,6 +352,8 @@ class AwsBackupRecoveryPoint(AwsResource): def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: if backup_vault_name := self.backup_vault_name: builder.add_edge(self, reverse=True, clazz=AwsBackupVault, name=backup_vault_name) + if (created_by := self.recovery_point_created_by) and (backup_plan_id := created_by.backup_plan_id): + builder.add_edge(self, reverse=True, clazz=AwsBackupPlan, id=backup_plan_id) @define(eq=False, slots=False) diff --git a/plugins/aws/tools/aws_model_gen.py b/plugins/aws/tools/aws_model_gen.py index de946b58bc..b97cddedd5 100644 --- a/plugins/aws/tools/aws_model_gen.py +++ b/plugins/aws/tools/aws_model_gen.py @@ -169,7 +169,6 @@ def complex_simple_shape(s: Shape) -> Optional[Tuple[str, str]]: props = [] prefix = prefix or "" prop_prefix = prop_prefix or "" - result = [] def process_shape_items(shape_items: List[Tuple[Any, Any]], prop_prefix: str, clazz_name: Optional[str]) -> None: for name, prop_shape in shape_items: @@ -242,7 +241,7 @@ def process_shape_items(shape_items: List[Tuple[Any, Any]], prop_prefix: str, cl elif isinstance(shape, ListShape): process_shape_items(shape.member.members.items(), prop_prefix, clazz_name) else: - if (getattr(shape, "members", None) is None) or (getattr(shape, "member", None) is None): + if getattr(shape, "members", None) is None: return [] process_shape_items(shape.members.items(), prop_prefix, clazz_name) return result