Skip to content

Commit

Permalink
aws - timestream register aws_backup count filter (cloud-custodian#9504)
Browse files Browse the repository at this point in the history
  • Loading branch information
shineyb authored May 23, 2024
1 parent 2713b42 commit 5ee77dc
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions c7n/resources/timestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Tag as TagAction,
RemoveTag as RemoveTagAction
)
from c7n.filters.backup import ConsecutiveAwsBackupsFilter


class DescribeTimestream(DescribeSource):
Expand Down Expand Up @@ -138,6 +139,9 @@ def process(self, resources):
)


TimestreamTable.filter_registry.register('consecutive-aws-backups', ConsecutiveAwsBackupsFilter)


@TimestreamDatabase.filter_registry.register('kms-key')
class KmsFilter(KmsRelatedFilter):
RelatedIdsExpression = 'KmsKeyId'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"status_code": 200,
"data": {
"ResponseMetadata": {},
"RecoveryPoints": [
{
"RecoveryPointArn": "arn:aws:backup:us-east-1:644160558196:recovery-point:757807c0-ef88-4055-aa6f-b7f2ac04e8b5",
"CreationDate": {
"__class__": "datetime",
"year": 2024,
"month": 5,
"day": 13,
"hour": 22,
"minute": 10,
"second": 12,
"microsecond": 899000
},
"Status": "COMPLETED",
"EncryptionKeyArn": "arn:aws:kms:us-east-1:644160558196:key/5d97ffc0-5842-49ce-9daf-6d0a129bf6c8",
"BackupSizeBytes": 0,
"BackupVaultName": "Default",
"IsParent": false,
"ResourceName": "database/test-timestream/table/test-2",
"VaultType": "BACKUP_VAULT"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"status_code": 200,
"data": {
"Endpoints": [
{
"Address": "ingest-cell2.timestream.us-east-1.amazonaws.com",
"CachePeriodInMinutes": 1440
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"status_code": 200,
"data": {
"Endpoints": [
{
"Address": "ingest-cell2.timestream.us-east-1.amazonaws.com",
"CachePeriodInMinutes": 1440
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"status_code": 200,
"data": {
"Tables": [
{
"Arn": "arn:aws:timestream:us-east-1:644160558196:database/test-timestream/table/test-2",
"TableName": "test-2",
"DatabaseName": "test-timestream",
"TableStatus": "ACTIVE",
"RetentionProperties": {
"MemoryStoreRetentionPeriodInHours": 12,
"MagneticStoreRetentionPeriodInDays": 1
},
"CreationTime": {
"__class__": "datetime",
"year": 2024,
"month": 5,
"day": 13,
"hour": 22,
"minute": 2,
"second": 21,
"microsecond": 252000
},
"LastUpdatedTime": {
"__class__": "datetime",
"year": 2024,
"month": 5,
"day": 13,
"hour": 22,
"minute": 2,
"second": 21,
"microsecond": 244000
},
"MagneticStoreWriteProperties": {
"EnableMagneticStoreWrites": false
},
"Schema": {
"CompositePartitionKey": [
{
"Type": "MEASURE"
}
]
}
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status_code": 200,
"data": {
"Tags": [],
"ResponseMetadata": {}
}
}
25 changes: 25 additions & 0 deletions tests/test_timestream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from .common import BaseTest
from c7n.testing import mock_datetime_now
import c7n.filters.backup
from dateutil import parser


class TestTimestreamDatabase(BaseTest):
Expand Down Expand Up @@ -171,6 +174,28 @@ def test_timestream_table_delete(self):
tables = client.list_tables()['Tables']
self.assertEqual(len(tables), 0)

def test_timestream_consecutive_aws_backup_count_filter(self):
session_factory = self.replay_flight_data("test_timestream_consecutive_backup_count_filter")
p = self.load_policy(
{
"name": "timestream_consecutive_aws_backup_count_filter",
"resource": "aws.timestream-table",
"filters": [
{
"type": "consecutive-aws-backups",
"count": 1,
"period": "days",
"status": "COMPLETED"
}
]
},
session_factory=session_factory,
)
with mock_datetime_now(parser.parse("2024-05-14T22:00:00+00:00"), c7n.filters.backup):
resources = p.run()
self.assertEqual(resources[0]['c7n:AwsBackups'][0]['Status'], "COMPLETED")
self.assertEqual(len(resources), 1)

def test_timestream_kms_key_filter(self):
session_factory = self.replay_flight_data('test_timestream_kms_key_filter')
p = self.load_policy(
Expand Down

0 comments on commit 5ee77dc

Please sign in to comment.