Skip to content

Commit 48acc1c

Browse files
authored
[aws][feat] Integrate Backup Service collection (#2106)
1 parent 4df872b commit 48acc1c

16 files changed

+1341
-6
lines changed

plugins/aws/fix_plugin_aws/collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
opensearch,
4747
acm,
4848
waf,
49+
backup,
4950
)
5051
from fix_plugin_aws.resource.base import AwsAccount, AwsApiSpec, AwsRegion, AwsResource, GraphBuilder
5152
from fixlib.baseresources import Cloud, EdgeType, BaseOrganizationalRoot, BaseOrganizationalUnit
@@ -103,6 +104,7 @@
103104
+ ssm.resources
104105
+ sqs.resources
105106
+ redshift.resources
107+
+ backup.resources
106108
)
107109
all_resources: List[Type[AwsResource]] = global_resources + regional_resources
108110

plugins/aws/fix_plugin_aws/resource/backup.py

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

plugins/aws/test/collector_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def count_kind(clazz: Type[AwsResource]) -> int:
2828
return count
2929

3030
for resource in all_resources:
31-
assert count_kind(resource) > 0, "No instances of {} found".format(resource.__name__)
31+
assert count_kind(resource) > 0, f"No instances of {resource.__name__} found"
3232

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) == 225
37-
assert len(account_collector.graph.edges) == 519
36+
assert count_kind(AwsResource) == 236
37+
assert len(account_collector.graph.edges) == 540
3838
assert len(account_collector.graph.deferred_edges) == 2
3939
for node in account_collector.graph.nodes:
4040
if isinstance(node, AwsRegion):
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from fix_plugin_aws.resource.backup import (
2+
AwsBackupJob,
3+
AwsBackupPlan,
4+
AwsBackupVault,
5+
AwsBackupRecoveryPoint,
6+
AwsBackupProtectedResource,
7+
AwsBackupReportPlan,
8+
AwsBackupRestoreTestingPlan,
9+
AwsBackupLegalHold,
10+
AwsBackupRestoreJob,
11+
AwsBackupCopyJob,
12+
AwsBackupFramework,
13+
)
14+
from test.resources import round_trip_for, build_graph
15+
16+
17+
def test_backup_jobs() -> None:
18+
round_trip_for(AwsBackupJob)
19+
20+
21+
def test_backup_plans() -> None:
22+
round_trip_for(AwsBackupPlan)
23+
24+
25+
def test_backup_vaults() -> None:
26+
round_trip_for(AwsBackupVault)
27+
28+
29+
def test_backup_recovery_points() -> None:
30+
builder = build_graph(AwsBackupVault)
31+
assert len(list(builder.nodes(AwsBackupRecoveryPoint))) > 0
32+
33+
34+
def test_backup_protected_resources() -> None:
35+
round_trip_for(AwsBackupProtectedResource)
36+
37+
38+
def test_backup_report_plans() -> None:
39+
round_trip_for(AwsBackupReportPlan)
40+
41+
42+
def test_backup_restore_testing_plans() -> None:
43+
round_trip_for(AwsBackupRestoreTestingPlan)
44+
45+
46+
def test_backup_legal_holds() -> None:
47+
round_trip_for(AwsBackupLegalHold)
48+
49+
50+
def test_backup_restore_jobs() -> None:
51+
round_trip_for(AwsBackupRestoreJob)
52+
53+
54+
def test_backup_copy_jobs() -> None:
55+
round_trip_for(AwsBackupCopyJob)
56+
57+
58+
def test_backup_frameworks() -> None:
59+
round_trip_for(AwsBackupFramework)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"BackupJobs": [
3+
{
4+
"BackupJobId": "1234567890abcdef",
5+
"CreationDate": "2023-03-15T12:34:56.789Z",
6+
"AccountId": "123456789012",
7+
"BackupVaultName": "MyBackupVault",
8+
"BackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
9+
"RecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
10+
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
11+
"CompletionDate": "2023-03-15T13:34:56.789Z",
12+
"State": "COMPLETED",
13+
"StatusMessage": "Backup completed successfully",
14+
"PercentDone": 100,
15+
"BackupSizeInBytes": 1024,
16+
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
17+
"CreatedBy": {
18+
"BackupPlanId": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
19+
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
20+
"BackupPlanVersion": "1234567890abcdef",
21+
"BackupRuleId": "MyBackupRule"
22+
},
23+
"ExpectedCompletionDate": "2023-03-15T13:34:56.789Z",
24+
"StartBy": "2023-03-15T12:34:56.789Z",
25+
"ResourceType": "EC2",
26+
"BytesTransferred": 1024,
27+
"BackupOptions": {
28+
"WindowsVSS": "enabled"
29+
},
30+
"BackupType": "FULL",
31+
"ParentJobId": "1234567890abcdef",
32+
"IsParent": true,
33+
"ResourceName": "MyEC2Instance",
34+
"InitiationDate": "2023-03-15T12:34:56.789Z",
35+
"MessageCategory": "SUCCESS"
36+
}
37+
],
38+
"NextToken": "foo"
39+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"NextToken": "foo",
3+
"BackupPlansList": [
4+
{
5+
"BackupPlanId": "8F81F553-3A74-4A3F-B93D-B3360DC80C50",
6+
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
7+
"BackupPlanName": "MyBackupPlan",
8+
"CreationDate": "2023-03-15T12:34:56.789Z",
9+
"DeletionDate": "2023-03-16T12:34:56.789Z",
10+
"VersionId": "1234567890abcdef",
11+
"CreatorRequestId": "my-unique-request-id",
12+
"LastExecutionDate": "2023-03-14T12:34:56.789Z",
13+
"AdvancedBackupSettings": [
14+
{
15+
"ResourceType": "EC2",
16+
"BackupOptions": {
17+
"WindowsVSS": "enabled"
18+
}
19+
}
20+
]
21+
}
22+
]
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"BackupVaultList": [
3+
{
4+
"BackupVaultName": "MyBackupVault",
5+
"BackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyBackupVault",
6+
"CreationDate": "2023-03-15T12:34:56.789Z",
7+
"EncryptionKeyArn": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab",
8+
"CreatorRequestId": "my-unique-request-id",
9+
"NumberOfRecoveryPoints": 10,
10+
"Locked": false,
11+
"MinRetentionDays": 30,
12+
"MaxRetentionDays": 365,
13+
"LockDate": "2023-03-16T12:34:56.789Z"
14+
}
15+
],
16+
"NextToken": "foo"
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"CopyJobs": [
3+
{
4+
"CopyJobId": "1234567890abcdef",
5+
"CreationDate": "2023-03-15T12:34:56.789Z",
6+
"AccountId": "123456789012",
7+
"SourceBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MySourceVault",
8+
"SourceRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:1EB3B5E7-9EB0-435A-A80B-108B488B0D45",
9+
"DestinationBackupVaultArn": "arn:aws:backup:us-east-1:123456789012:vault:MyDestinationVault",
10+
"DestinationRecoveryPointArn": "arn:aws:backup:us-east-1:123456789012:recovery-point:2EB3B5E7-9EB0-435A-A80B-108B488B0D45",
11+
"ResourceArn": "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0",
12+
"CompletionDate": "2023-03-15T13:34:56.789Z",
13+
"State": "COMPLETED",
14+
"StatusMessage": "Copy completed successfully",
15+
"BackupSizeInBytes": 1024,
16+
"IamRoleArn": "arn:aws:iam::123456789012:role/BackupRole",
17+
"CreatedBy": {
18+
"BackupPlanId": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
19+
"BackupPlanArn": "arn:aws:backup:us-east-1:123456789012:plan:8F81F553-3A74-4A3F-B93D-B3360DC80C50",
20+
"BackupPlanVersion": "1234567890abcdef",
21+
"BackupRuleId": "MyBackupRule"
22+
},
23+
"ResourceType": "EC2",
24+
"ParentJobId": "1234567890abcdef",
25+
"IsParent": true,
26+
"CompositeMemberIdentifier": "MyEC2Instance",
27+
"NumberOfChildJobs": 1,
28+
"ChildJobsInState": {
29+
"COMPLETED": 1
30+
},
31+
"ResourceName": "MyEC2Instance",
32+
"MessageCategory": "SUCCESS"
33+
}
34+
],
35+
"NextToken": "foo"
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Frameworks": [
3+
{
4+
"FrameworkArn": "arn:aws:backup:us-east-1:123456789012:framework:MyFramework",
5+
"FrameworkName": "MyFramework",
6+
"FrameworkDescription": "My framework description",
7+
"NumberOfControls": 10,
8+
"CreationTime": "2023-03-15T12:34:56.789Z",
9+
"DeploymentStatus": "COMPLETED"
10+
}
11+
],
12+
"NextToken": "foo"
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"NextToken": "foo",
3+
"LegalHolds": [
4+
{
5+
"LegalHoldId": "1234567890abcdef",
6+
"CreationDate": "2023-03-15T12:34:56.789Z",
7+
"Title": "My Legal Hold",
8+
"Status": "ACTIVE",
9+
"Description": "My legal hold description",
10+
"LegalHoldArn": "arn:aws:backup:us-east-1:123456789012:legal-hold:1234567890abcdef",
11+
"CancellationDate": "2023-03-16T12:34:56.789Z"
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)