|
2 | 2 | from typing import ClassVar, Dict, List, Optional, Type, Any |
3 | 3 | from attrs import define, field |
4 | 4 | from fix_plugin_aws.aws_client import AwsClient |
5 | | -from fix_plugin_aws.resource.base import AwsApiSpec, AwsResource, GraphBuilder |
| 5 | +from fix_plugin_aws.resource.base import AwsApiSpec, AwsResource, GraphBuilder, parse_json |
6 | 6 | from fix_plugin_aws.resource.kinesis import AwsKinesisStream |
7 | 7 | from fix_plugin_aws.resource.kms import AwsKmsKey |
8 | 8 | from fix_plugin_aws.utils import ToDict |
@@ -328,6 +328,30 @@ class AwsDynamoDbArchivalSummary: |
328 | 328 | archival_backup_arn: Optional[str] = field(default=None) |
329 | 329 |
|
330 | 330 |
|
| 331 | +@define(eq=False, slots=False) |
| 332 | +class AwsDynamoDbPointInTimeRecovery: |
| 333 | + kind: ClassVar[str] = "aws_dynamo_db_point_in_time_recovery" |
| 334 | + mapping: ClassVar[Dict[str, Bender]] = { |
| 335 | + "status": S("PointInTimeRecoveryStatus"), |
| 336 | + "earliest_restorable_date_time": S("EarliestRestorableDateTime"), |
| 337 | + "latest_restorable_date_time": S("LatestRestorableDateTime"), |
| 338 | + } |
| 339 | + status: Optional[str] = field(default=None, metadata={"description": "The current state of point in time recovery: ENABLED - Point in time recovery is enabled. DISABLED - Point in time recovery is disabled."}) # fmt: skip |
| 340 | + earliest_restorable_date_time: Optional[datetime] = field(default=None, metadata={"description": "Specifies the earliest point in time you can restore your table to. You can restore your table to any point in time during the last 35 days."}) # fmt: skip |
| 341 | + latest_restorable_date_time: Optional[datetime] = field(default=None, metadata={"description": "LatestRestorableDateTime is typically 5 minutes before the current time."}) # fmt: skip |
| 342 | + |
| 343 | + |
| 344 | +@define(eq=False, slots=False) |
| 345 | +class AwsDynamoDbContinuousBackup: |
| 346 | + kind: ClassVar[str] = "aws_dynamo_db_continuous_backup" |
| 347 | + mapping: ClassVar[Dict[str, Bender]] = { |
| 348 | + "status": S("ContinuousBackupsStatus"), |
| 349 | + "point_in_time_recovery": S("PointInTimeRecoveryDescription") >> Bend(AwsDynamoDbPointInTimeRecovery.mapping), |
| 350 | + } |
| 351 | + status: Optional[str] = field(default=None, metadata={"description": "ContinuousBackupsStatus can be one of the following states: ENABLED, DISABLED"}) # fmt: skip |
| 352 | + point_in_time_recovery: Optional[AwsDynamoDbPointInTimeRecovery] = field(default=None, metadata={"description": "The description of the point in time recovery settings applied to the table."}) # fmt: skip |
| 353 | + |
| 354 | + |
331 | 355 | @define(eq=False, slots=False) |
332 | 356 | class AwsDynamoDbTable(DynamoDbTaggable, AwsResource): |
333 | 357 | kind: ClassVar[str] = "aws_dynamodb_table" |
@@ -390,26 +414,37 @@ class AwsDynamoDbTable(DynamoDbTaggable, AwsResource): |
390 | 414 | dynamodb_sse_description: Optional[AwsDynamoDbSSEDescription] = field(default=None) |
391 | 415 | dynamodb_archival_summary: Optional[AwsDynamoDbArchivalSummary] = field(default=None) |
392 | 416 | dynamodb_table_class_summary: Optional[AwsDynamoDbTableClassSummary] = field(default=None) |
| 417 | + dynamodb_continuous_backup: Optional[AwsDynamoDbContinuousBackup] = field(default=None) |
393 | 418 |
|
394 | 419 | @classmethod |
395 | 420 | def called_collect_apis(cls) -> List[AwsApiSpec]: |
396 | 421 | return [ |
397 | 422 | cls.api_spec, |
398 | 423 | AwsApiSpec(service_name, "describe-table"), |
399 | 424 | AwsApiSpec(service_name, "list-tags-of-resource"), |
| 425 | + AwsApiSpec(service_name, "describe-continuous-backups"), |
400 | 426 | ] |
401 | 427 |
|
402 | 428 | @classmethod |
403 | 429 | def collect(cls: Type[AwsResource], json: List[Json], builder: GraphBuilder) -> List[AwsResource]: |
404 | 430 | instances = [] |
405 | 431 |
|
| 432 | + def add_backup_description(table: AwsDynamoDbTable) -> None: |
| 433 | + if continuous_backup := builder.client.get( |
| 434 | + service_name, "describe-continuous-backups", "ContinuousBackupsDescription", TableName=table.name |
| 435 | + ): |
| 436 | + table.dynamodb_continuous_backup = parse_json( |
| 437 | + continuous_backup, AwsDynamoDbContinuousBackup, builder, AwsDynamoDbContinuousBackup.mapping |
| 438 | + ) |
| 439 | + |
406 | 440 | def add_instance(table: str) -> None: |
407 | 441 | table_description = builder.client.get(service_name, "describe-table", "Table", TableName=table) |
408 | 442 | if table_description is not None: |
409 | 443 | if instance := cls.from_api(table_description, builder): |
410 | 444 | instances.append(instance) |
411 | 445 | builder.add_node(instance, table_description) |
412 | 446 | builder.submit_work(service_name, add_tags, instance) |
| 447 | + builder.submit_work(service_name, add_backup_description, instance) |
413 | 448 |
|
414 | 449 | def add_tags(table: AwsDynamoDbTable) -> None: |
415 | 450 | tags = builder.client.list(service_name, "list-tags-of-resource", "Tags", ResourceArn=table.arn) |
|
0 commit comments