-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor AWS DynamoDB to use new data model (#1153)
Refactors DynamoDB sync to use the cartography data model.
- Loading branch information
Showing
6 changed files
with
354 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
cartography/data/jobs/cleanup/aws_import_dynamodb_tables_cleanup.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from dataclasses import dataclass | ||
|
||
from cartography.models.core.common import PropertyRef | ||
from cartography.models.core.nodes import CartographyNodeProperties | ||
from cartography.models.core.nodes import CartographyNodeSchema | ||
from cartography.models.core.relationships import CartographyRelProperties | ||
from cartography.models.core.relationships import CartographyRelSchema | ||
from cartography.models.core.relationships import LinkDirection | ||
from cartography.models.core.relationships import make_target_node_matcher | ||
from cartography.models.core.relationships import OtherRelationships | ||
from cartography.models.core.relationships import TargetNodeMatcher | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBGSINodeProperties(CartographyNodeProperties): | ||
id: PropertyRef = PropertyRef('Arn') | ||
arn: PropertyRef = PropertyRef('Arn') | ||
name: PropertyRef = PropertyRef('GSIName') | ||
region: PropertyRef = PropertyRef('Region', set_in_kwargs=True) | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
provisioned_throughput_read_capacity_units: PropertyRef = PropertyRef('ProvisionedThroughputReadCapacityUnits') | ||
provisioned_throughput_write_capacity_units: PropertyRef = PropertyRef('ProvisionedThroughputWriteCapacityUnits') | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBGSIToAwsAccountRelProperties(CartographyRelProperties): | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
|
||
|
||
@dataclass(frozen=True) | ||
# (:DynamoDBGlobalSecondaryIndex)<-[:RESOURCE]-(:AWSAccount) | ||
class DynamoDBGSIToAWSAccount(CartographyRelSchema): | ||
target_node_label: str = 'AWSAccount' | ||
target_node_matcher: TargetNodeMatcher = make_target_node_matcher( | ||
{'id': PropertyRef('AWS_ID', set_in_kwargs=True)}, | ||
) | ||
direction: LinkDirection = LinkDirection.INWARD | ||
rel_label: str = "RESOURCE" | ||
properties: DynamoDBGSIToAwsAccountRelProperties = DynamoDBGSIToAwsAccountRelProperties() | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBGSIToDynamoDBTableRelProperties(CartographyRelProperties): | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
|
||
|
||
@dataclass(frozen=True) | ||
# (:DynamoDBGlobalSecondaryIndex)<-[:GLOBAL_SECONDARY_INDEX]-(:DynamoDBTable) | ||
class DynamoDBGSIToDynamoDBTable(CartographyRelSchema): | ||
target_node_label: str = 'DynamoDBTable' | ||
target_node_matcher: TargetNodeMatcher = make_target_node_matcher( | ||
{'arn': PropertyRef('TableArn')}, | ||
) | ||
direction: LinkDirection = LinkDirection.INWARD | ||
rel_label: str = "GLOBAL_SECONDARY_INDEX" | ||
properties: DynamoDBGSIToDynamoDBTableRelProperties = DynamoDBGSIToDynamoDBTableRelProperties() | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBGSISchema(CartographyNodeSchema): | ||
label: str = 'DynamoDBGlobalSecondaryIndex' | ||
properties: DynamoDBGSINodeProperties = DynamoDBGSINodeProperties() | ||
sub_resource_relationship: DynamoDBGSIToAWSAccount = DynamoDBGSIToAWSAccount() | ||
other_relationships: OtherRelationships = OtherRelationships( | ||
[ | ||
DynamoDBGSIToDynamoDBTable(), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from dataclasses import dataclass | ||
|
||
from cartography.models.core.common import PropertyRef | ||
from cartography.models.core.nodes import CartographyNodeProperties | ||
from cartography.models.core.nodes import CartographyNodeSchema | ||
from cartography.models.core.relationships import CartographyRelProperties | ||
from cartography.models.core.relationships import CartographyRelSchema | ||
from cartography.models.core.relationships import LinkDirection | ||
from cartography.models.core.relationships import make_target_node_matcher | ||
from cartography.models.core.relationships import TargetNodeMatcher | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBTableNodeProperties(CartographyNodeProperties): | ||
id: PropertyRef = PropertyRef('Arn') | ||
arn: PropertyRef = PropertyRef('Arn') | ||
name: PropertyRef = PropertyRef('TableName') | ||
region: PropertyRef = PropertyRef('Region', set_in_kwargs=True) | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
rows: PropertyRef = PropertyRef('Rows') | ||
size: PropertyRef = PropertyRef('Size') | ||
provisioned_throughput_read_capacity_units: PropertyRef = PropertyRef('ProvisionedThroughputReadCapacityUnits') | ||
provisioned_throughput_write_capacity_units: PropertyRef = PropertyRef('ProvisionedThroughputWriteCapacityUnits') | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBTableToAwsAccountRelProperties(CartographyRelProperties): | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
|
||
|
||
@dataclass(frozen=True) | ||
# (:DynamoDBTable)<-[:RESOURCE]-(:AWSAccount) | ||
class DynamoDBTableToAWSAccount(CartographyRelSchema): | ||
target_node_label: str = 'AWSAccount' | ||
target_node_matcher: TargetNodeMatcher = make_target_node_matcher( | ||
{'id': PropertyRef('AWS_ID', set_in_kwargs=True)}, | ||
) | ||
direction: LinkDirection = LinkDirection.INWARD | ||
rel_label: str = "RESOURCE" | ||
properties: DynamoDBTableToAwsAccountRelProperties = DynamoDBTableToAwsAccountRelProperties() | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DynamoDBTableSchema(CartographyNodeSchema): | ||
label: str = 'DynamoDBTable' | ||
properties: DynamoDBTableNodeProperties = DynamoDBTableNodeProperties() | ||
sub_resource_relationship: DynamoDBTableToAWSAccount = DynamoDBTableToAWSAccount() |
Oops, something went wrong.