Skip to content

Commit

Permalink
[aws][fix]: Fix non acyclic graph connection (#2118)
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Jun 18, 2024
1 parent b884916 commit d41709e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions plugins/aws/fix_plugin_aws/resource/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from attrs import define, field

from fix_plugin_aws.resource.base import AwsResource, AwsApiSpec, GraphBuilder
from fix_plugin_aws.resource.cloudformation import AwsCloudFormationStack
from fix_plugin_aws.resource.dynamodb import AwsDynamoDbTable, AwsDynamoDbGlobalTable
from fix_plugin_aws.resource.ec2 import AwsEc2Instance, AwsEc2Volume
from fix_plugin_aws.resource.efs import AwsEfsFileSystem
from fix_plugin_aws.resource.rds import AwsRdsCluster, AwsRdsInstance
from fix_plugin_aws.resource.redshift import AwsRedshiftCluster
from fix_plugin_aws.resource.s3 import AwsS3Bucket
from fix_plugin_aws.utils import TagsValue
from fixlib.baseresources import ModelReference
from fixlib.json_bender import Bender, S, ForallBend, Bend
Expand Down Expand Up @@ -172,7 +179,6 @@ class AwsBackupProtectedResource(AwsResource):
"resource_name": S("ResourceName"),
"last_backup_vault_arn": S("LastBackupVaultArn"),
"last_recovery_point_arn": S("LastRecoveryPointArn"),
"arn": S("ResourceArn"),
}
resource_arn: Optional[str] = field(default=None, metadata={"description": "An Amazon Resource Name (ARN) that uniquely identifies a resource. The format of the ARN depends on the resource type."}) # fmt: skip
resource_type: Optional[str] = field(default=None, metadata={"description": "The type of Amazon Web Services resource; for example, an Amazon Elastic Block Store (Amazon EBS) volume or an Amazon Relational Database Service (Amazon RDS) database. For Windows Volume Shadow Copy Service (VSS) backups, the only supported resource type is Amazon EC2."}) # fmt: skip
Expand All @@ -183,7 +189,22 @@ class AwsBackupProtectedResource(AwsResource):

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if resource_arn := self.resource_arn:
builder.add_edge(self, clazz=AwsResource, arn=resource_arn)
builder.add_edge(
self,
clazz=(
AwsS3Bucket,
AwsEc2Instance,
AwsEc2Volume,
AwsRdsCluster,
AwsRdsInstance,
AwsDynamoDbTable,
AwsDynamoDbGlobalTable,
AwsEfsFileSystem,
AwsRedshiftCluster,
AwsCloudFormationStack,
),
arn=resource_arn,
)
if vault_arn := self.last_backup_vault_arn:
builder.add_edge(self, reverse=True, clazz=AwsBackupVault, id=vault_arn)
if recovery_point_arn := self.last_recovery_point_arn:
Expand Down
2 changes: 1 addition & 1 deletion plugins/aws/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def count_kind(clazz: Type[AwsResource]) -> int:
assert len(threading.enumerate()) == 1
# ensure the correct number of nodes and edges
assert count_kind(AwsResource) == 236
assert len(account_collector.graph.edges) == 540
assert len(account_collector.graph.edges) == 539
assert len(account_collector.graph.deferred_edges) == 2
for node in account_collector.graph.nodes:
if isinstance(node, AwsRegion):
Expand Down

0 comments on commit d41709e

Please sign in to comment.