Skip to content

Commit c3a1bdd

Browse files
1101-1aquamatthias
andauthored
[aws][feat] Add amazon Q resource collection (#2175)
Co-authored-by: Matthias Veit <aquamatthias@users.noreply.github.com>
1 parent a0efd4f commit c3a1bdd

19 files changed

+1526
-48
lines changed

plugins/aws/fix_plugin_aws/collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from fix_plugin_aws.aws_client import AwsClient
1010
from fix_plugin_aws.configuration import AwsConfig
1111
from fix_plugin_aws.resource import (
12+
amazonq,
1213
apigateway,
1314
athena,
1415
autoscaling,
@@ -105,6 +106,7 @@
105106
+ sqs.resources
106107
+ redshift.resources
107108
+ backup.resources
109+
+ amazonq.resources
108110
)
109111
all_resources: List[Type[AwsResource]] = global_resources + regional_resources
110112

plugins/aws/fix_plugin_aws/resource/amazonq.py

Lines changed: 1088 additions & 0 deletions
Large diffs are not rendered by default.

plugins/aws/fix_plugin_aws/resource/backup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class AwsBackupAdvancedBackupSetting:
222222

223223

224224
@define(eq=False, slots=False)
225-
class AwsBackupPlan(AwsResource, BackupResourceTaggable):
225+
class AwsBackupPlan(BackupResourceTaggable, AwsResource):
226226
kind: ClassVar[str] = "aws_backup_plan"
227227
kind_display: ClassVar[str] = "AWS Backup Plan"
228228
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/backupplan/details/{id}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:backup-plan:{id}"} # fmt: skip
@@ -302,7 +302,7 @@ def add_tags(backup_plan: AwsBackupPlan) -> None:
302302

303303

304304
@define(eq=False, slots=False)
305-
class AwsBackupVault(AwsResource, BackupResourceTaggable):
305+
class AwsBackupVault(BackupResourceTaggable, AwsResource):
306306
kind: ClassVar[str] = "aws_backup_vault"
307307
kind_display: ClassVar[str] = "AWS Backup Vault"
308308
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/backupplan/details/{name}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:backup-vault:{name}"} # fmt: skip
@@ -570,7 +570,7 @@ class AwsBackupReportDeliveryChannel:
570570

571571

572572
@define(eq=False, slots=False)
573-
class AwsBackupReportPlan(AwsResource, BackupResourceTaggable):
573+
class AwsBackupReportPlan(BackupResourceTaggable, AwsResource):
574574
kind: ClassVar[str] = "aws_backup_report_plan"
575575
kind_display: ClassVar[str] = "AWS Report Plan"
576576
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/compliance/reports/details/{name}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:report-plan:{name}"} # fmt: skip
@@ -658,7 +658,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
658658
builder.add_edge(self, reverse=True, clazz=AwsBackupFramework, id=framework_arn)
659659

660660

661-
class AwsBackupRestoreTestingPlan(AwsResource, BackupResourceTaggable):
661+
class AwsBackupRestoreTestingPlan(BackupResourceTaggable, AwsResource):
662662
kind: ClassVar[str] = "aws_backup_restore_testing_plan"
663663
kind_display: ClassVar[str] = "AWS Restore Testing Plan"
664664
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/restoretesting/details/{name}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:restore-testing-plan:{name}"} # fmt: skip
@@ -736,7 +736,7 @@ def add_tags(restore_plan: AwsBackupRestoreTestingPlan) -> None:
736736

737737

738738
@define(eq=False, slots=False)
739-
class AwsBackupLegalHold(AwsResource, BackupResourceTaggable):
739+
class AwsBackupLegalHold(BackupResourceTaggable, AwsResource):
740740
kind: ClassVar[str] = "aws_backup_legal_hold"
741741
kind_display: ClassVar[str] = "AWS Legal Hold"
742742
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/legalholds/details/{id}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:legal-hold:{id}"} # fmt: skip
@@ -938,7 +938,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
938938

939939

940940
@define(eq=False, slots=False)
941-
class AwsBackupFramework(AwsResource, BackupResourceTaggable):
941+
class AwsBackupFramework(BackupResourceTaggable, AwsResource):
942942
kind: ClassVar[str] = "aws_backup_framework"
943943
kind_display: ClassVar[str] = "AWS Backup Framework"
944944
aws_metadata: ClassVar[Dict[str, Any]] = {"provider_link_tpl": "https://{region_id}.console.aws.amazon.com/backup/home?region={region_id}#/compliance/frameworks/details/{name}", "arn_tpl": "arn:{partition}:backup:{region}:{account}:framework:{name}"} # fmt: skip

plugins/aws/fix_plugin_aws/resource/base.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,21 @@ def add_node(
508508
# if there is no arn: try to create one from template
509509
if node.arn is None and (arn_tpl := meta.get("arn_tpl")):
510510
try:
511-
node.arn = arn_tpl.format(
512-
partition=self.account.partition,
513-
id=node.id,
514-
name=node.name,
515-
account=self.account.id,
516-
region=self.region.name,
517-
)
511+
args = {
512+
"partition": self.account.partition,
513+
"id": node.id,
514+
"name": node.name,
515+
"account": self.account.id,
516+
"region": self.region.name,
517+
}
518+
519+
# Add any additional dynamic arguments from the metadata (if they exist)
520+
if extra_args := meta.get("extra_args"):
521+
for extra_arg in extra_args:
522+
args[extra_arg] = getattr(node, extra_arg)
523+
524+
# Format the ARN with the provided arguments
525+
node.arn = arn_tpl.format(**args)
518526
except Exception as e:
519527
log.warning(f"Can not compute ARN for {node} with template: {arn_tpl}: {e}")
520528

plugins/aws/test/collector_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def count_kind(clazz: Type[AwsResource]) -> int:
3333
# make sure all threads have been joined
3434
assert len(threading.enumerate()) == 1
3535
# ensure the correct number of nodes and edges
36-
assert count_kind(AwsResource) == 236
37-
assert len(account_collector.graph.edges) == 540
36+
assert count_kind(AwsResource) == 248
37+
assert len(account_collector.graph.edges) == 564
3838
assert len(account_collector.graph.deferred_edges) == 2
3939
for node in account_collector.graph.nodes:
4040
if isinstance(node, AwsRegion):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fix_plugin_aws.resource.amazonq import AwsQBusinessApplication
2+
from test.resources import round_trip_for
3+
4+
5+
def test_applications() -> None:
6+
round_trip_for(AwsQBusinessApplication)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"libraryItems": [
3+
{
4+
"libraryItemId": "foo",
5+
"appId": "foo",
6+
"appVersion": 123,
7+
"categories": [
8+
{
9+
"id": "foo",
10+
"title": "foo"
11+
},
12+
{
13+
"id": "foo",
14+
"title": "foo"
15+
},
16+
{
17+
"id": "foo",
18+
"title": "foo"
19+
}
20+
],
21+
"status": "foo",
22+
"createdAt": "2024-08-30T12:42:21Z",
23+
"createdBy": "foo",
24+
"updatedAt": "2024-08-30T12:42:21Z",
25+
"updatedBy": "foo",
26+
"ratingCount": 123,
27+
"isRatedByUser": true,
28+
"userCount": 123
29+
}
30+
],
31+
"nextToken": "foo"
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"apps": [
3+
{
4+
"appId": "foo",
5+
"appArn": "foo",
6+
"title": "foo",
7+
"description": "foo",
8+
"createdAt": "2024-08-30T12:42:21Z",
9+
"canEdit": true,
10+
"status": "foo"
11+
}
12+
],
13+
"nextToken": "foo"
14+
}
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"nextToken": "foo",
3+
"applications": [
4+
{
5+
"displayName": "foo",
6+
"applicationId": "foo",
7+
"createdAt": "2024-08-30T12:21:29Z",
8+
"updatedAt": "2024-08-30T12:21:29Z",
9+
"status": "ACTIVE"
10+
}
11+
]
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"nextToken": "foo",
3+
"conversations": [
4+
{
5+
"conversationId": "foo",
6+
"title": "foo",
7+
"startTime": "2024-08-30T12:42:21Z"
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)