Skip to content

Commit

Permalink
[aws][feat] Add amazon Q resource collection (#2175)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Veit <[email protected]>
  • Loading branch information
1101-1 and aquamatthias authored Sep 5, 2024
1 parent a0efd4f commit c3a1bdd
Show file tree
Hide file tree
Showing 19 changed files with 1,526 additions and 48 deletions.
2 changes: 2 additions & 0 deletions plugins/aws/fix_plugin_aws/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from fix_plugin_aws.aws_client import AwsClient
from fix_plugin_aws.configuration import AwsConfig
from fix_plugin_aws.resource import (
amazonq,
apigateway,
athena,
autoscaling,
Expand Down Expand Up @@ -105,6 +106,7 @@
+ sqs.resources
+ redshift.resources
+ backup.resources
+ amazonq.resources
)
all_resources: List[Type[AwsResource]] = global_resources + regional_resources

Expand Down
1,088 changes: 1,088 additions & 0 deletions plugins/aws/fix_plugin_aws/resource/amazonq.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions plugins/aws/fix_plugin_aws/resource/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class AwsBackupAdvancedBackupSetting:


@define(eq=False, slots=False)
class AwsBackupPlan(AwsResource, BackupResourceTaggable):
class AwsBackupPlan(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_plan"
kind_display: ClassVar[str] = "AWS Backup Plan"
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
Expand Down Expand Up @@ -302,7 +302,7 @@ def add_tags(backup_plan: AwsBackupPlan) -> None:


@define(eq=False, slots=False)
class AwsBackupVault(AwsResource, BackupResourceTaggable):
class AwsBackupVault(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_vault"
kind_display: ClassVar[str] = "AWS Backup Vault"
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
Expand Down Expand Up @@ -570,7 +570,7 @@ class AwsBackupReportDeliveryChannel:


@define(eq=False, slots=False)
class AwsBackupReportPlan(AwsResource, BackupResourceTaggable):
class AwsBackupReportPlan(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_report_plan"
kind_display: ClassVar[str] = "AWS Report Plan"
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
Expand Down Expand Up @@ -658,7 +658,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
builder.add_edge(self, reverse=True, clazz=AwsBackupFramework, id=framework_arn)


class AwsBackupRestoreTestingPlan(AwsResource, BackupResourceTaggable):
class AwsBackupRestoreTestingPlan(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_restore_testing_plan"
kind_display: ClassVar[str] = "AWS Restore Testing Plan"
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
Expand Down Expand Up @@ -736,7 +736,7 @@ def add_tags(restore_plan: AwsBackupRestoreTestingPlan) -> None:


@define(eq=False, slots=False)
class AwsBackupLegalHold(AwsResource, BackupResourceTaggable):
class AwsBackupLegalHold(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_legal_hold"
kind_display: ClassVar[str] = "AWS Legal Hold"
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
Expand Down Expand Up @@ -938,7 +938,7 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:


@define(eq=False, slots=False)
class AwsBackupFramework(AwsResource, BackupResourceTaggable):
class AwsBackupFramework(BackupResourceTaggable, AwsResource):
kind: ClassVar[str] = "aws_backup_framework"
kind_display: ClassVar[str] = "AWS Backup Framework"
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
Expand Down
22 changes: 15 additions & 7 deletions plugins/aws/fix_plugin_aws/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,21 @@ def add_node(
# if there is no arn: try to create one from template
if node.arn is None and (arn_tpl := meta.get("arn_tpl")):
try:
node.arn = arn_tpl.format(
partition=self.account.partition,
id=node.id,
name=node.name,
account=self.account.id,
region=self.region.name,
)
args = {
"partition": self.account.partition,
"id": node.id,
"name": node.name,
"account": self.account.id,
"region": self.region.name,
}

# Add any additional dynamic arguments from the metadata (if they exist)
if extra_args := meta.get("extra_args"):
for extra_arg in extra_args:
args[extra_arg] = getattr(node, extra_arg)

# Format the ARN with the provided arguments
node.arn = arn_tpl.format(**args)
except Exception as e:
log.warning(f"Can not compute ARN for {node} with template: {arn_tpl}: {e}")

Expand Down
4 changes: 2 additions & 2 deletions plugins/aws/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def count_kind(clazz: Type[AwsResource]) -> int:
# make sure all threads have been joined
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 count_kind(AwsResource) == 248
assert len(account_collector.graph.edges) == 564
assert len(account_collector.graph.deferred_edges) == 2
for node in account_collector.graph.nodes:
if isinstance(node, AwsRegion):
Expand Down
6 changes: 6 additions & 0 deletions plugins/aws/test/resources/amazonq_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from fix_plugin_aws.resource.amazonq import AwsQBusinessApplication
from test.resources import round_trip_for


def test_applications() -> None:
round_trip_for(AwsQBusinessApplication)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"libraryItems": [
{
"libraryItemId": "foo",
"appId": "foo",
"appVersion": 123,
"categories": [
{
"id": "foo",
"title": "foo"
},
{
"id": "foo",
"title": "foo"
},
{
"id": "foo",
"title": "foo"
}
],
"status": "foo",
"createdAt": "2024-08-30T12:42:21Z",
"createdBy": "foo",
"updatedAt": "2024-08-30T12:42:21Z",
"updatedBy": "foo",
"ratingCount": 123,
"isRatedByUser": true,
"userCount": 123
}
],
"nextToken": "foo"
}
15 changes: 15 additions & 0 deletions plugins/aws/test/resources/files/qapps/list-q-apps__foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"apps": [
{
"appId": "foo",
"appArn": "foo",
"title": "foo",
"description": "foo",
"createdAt": "2024-08-30T12:42:21Z",
"canEdit": true,
"status": "foo"
}
],
"nextToken": "foo"
}

12 changes: 12 additions & 0 deletions plugins/aws/test/resources/files/qbusiness/list-applications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"nextToken": "foo",
"applications": [
{
"displayName": "foo",
"applicationId": "foo",
"createdAt": "2024-08-30T12:21:29Z",
"updatedAt": "2024-08-30T12:21:29Z",
"status": "ACTIVE"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"nextToken": "foo",
"conversations": [
{
"conversationId": "foo",
"title": "foo",
"startTime": "2024-08-30T12:42:21Z"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"history": [
{
"executionId": "foo",
"startTime": "2024-08-30T12:48:51Z",
"endTime": "2024-08-30T12:48:51Z",
"status": "SUCCEEDED",
"error": {
"errorMessage": "foo",
"errorCode": "InvalidRequest"
},
"dataSourceErrorCode": "foo",
"metrics": {
"documentsAdded": "foo",
"documentsModified": "foo",
"documentsDeleted": "foo",
"documentsFailed": "foo",
"documentsScanned": "foo"
}
}
],
"nextToken": "foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dataSources": [
{
"displayName": "foo",
"dataSourceId": "foo",
"type": "foo",
"createdAt": "2024-08-30T12:46:23Z",
"updatedAt": "2024-08-30T12:46:23Z",
"status": "CREATING"
}
],
"nextToken": "foo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"documentDetailList": [
{
"documentId": "foo",
"status": "PROCESSING",
"error": {
"errorMessage": "foo",
"errorCode": "InvalidRequest"
},
"createdAt": "2024-08-30T12:46:23Z",
"updatedAt": "2024-08-30T12:46:23Z"
}
],
"nextToken": "foo"
}
12 changes: 12 additions & 0 deletions plugins/aws/test/resources/files/qbusiness/list-indices__foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"nextToken": "foo",
"indices": [
{
"displayName": "foo",
"indexId": "foo",
"createdAt": "2024-08-30T12:42:21Z",
"updatedAt": "2024-08-30T12:42:21Z",
"status": "ACTIVE"
}
]
}
Loading

0 comments on commit c3a1bdd

Please sign in to comment.