cartography 0.102.0rc2__py3-none-any.whl → 0.103.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cartography might be problematic. Click here for more details.
- cartography/__main__.py +1 -2
- cartography/_version.py +2 -2
- cartography/cli.py +376 -249
- cartography/client/core/tx.py +39 -18
- cartography/config.py +28 -0
- cartography/driftdetect/__main__.py +1 -2
- cartography/driftdetect/add_shortcut.py +10 -2
- cartography/driftdetect/cli.py +71 -75
- cartography/driftdetect/detect_deviations.py +7 -3
- cartography/driftdetect/get_states.py +20 -8
- cartography/driftdetect/model.py +5 -5
- cartography/driftdetect/serializers.py +8 -6
- cartography/driftdetect/storage.py +2 -2
- cartography/graph/cleanupbuilder.py +35 -15
- cartography/graph/job.py +46 -17
- cartography/graph/querybuilder.py +165 -80
- cartography/graph/statement.py +35 -26
- cartography/intel/analysis.py +4 -1
- cartography/intel/aws/__init__.py +114 -55
- cartography/intel/aws/apigateway.py +134 -63
- cartography/intel/aws/cloudtrail.py +127 -0
- cartography/intel/aws/cloudwatch.py +93 -0
- cartography/intel/aws/config.py +56 -20
- cartography/intel/aws/dynamodb.py +108 -40
- cartography/intel/aws/ec2/__init__.py +2 -2
- cartography/intel/aws/ec2/auto_scaling_groups.py +181 -78
- cartography/intel/aws/ec2/elastic_ip_addresses.py +41 -13
- cartography/intel/aws/ec2/images.py +49 -20
- cartography/intel/aws/ec2/instances.py +234 -136
- cartography/intel/aws/ec2/internet_gateways.py +40 -11
- cartography/intel/aws/ec2/key_pairs.py +44 -20
- cartography/intel/aws/ec2/launch_templates.py +101 -59
- cartography/intel/aws/ec2/load_balancer_v2s.py +104 -39
- cartography/intel/aws/ec2/load_balancers.py +82 -42
- cartography/intel/aws/ec2/network_acls.py +89 -65
- cartography/intel/aws/ec2/network_interfaces.py +146 -87
- cartography/intel/aws/ec2/reserved_instances.py +45 -16
- cartography/intel/aws/ec2/route_tables.py +138 -98
- cartography/intel/aws/ec2/security_groups.py +71 -21
- cartography/intel/aws/ec2/snapshots.py +61 -22
- cartography/intel/aws/ec2/subnets.py +54 -18
- cartography/intel/aws/ec2/tgw.py +100 -34
- cartography/intel/aws/ec2/util.py +1 -1
- cartography/intel/aws/ec2/volumes.py +69 -41
- cartography/intel/aws/ec2/vpc.py +37 -12
- cartography/intel/aws/ec2/vpc_peerings.py +83 -24
- cartography/intel/aws/ecr.py +88 -32
- cartography/intel/aws/ecs.py +83 -47
- cartography/intel/aws/efs.py +93 -0
- cartography/intel/aws/eks.py +55 -29
- cartography/intel/aws/elasticache.py +42 -18
- cartography/intel/aws/elasticsearch.py +57 -20
- cartography/intel/aws/emr.py +61 -23
- cartography/intel/aws/iam.py +401 -145
- cartography/intel/aws/iam_instance_profiles.py +22 -22
- cartography/intel/aws/identitycenter.py +71 -37
- cartography/intel/aws/inspector.py +159 -89
- cartography/intel/aws/kms.py +92 -38
- cartography/intel/aws/lambda_function.py +103 -34
- cartography/intel/aws/organizations.py +30 -10
- cartography/intel/aws/permission_relationships.py +133 -51
- cartography/intel/aws/rds.py +249 -85
- cartography/intel/aws/redshift.py +107 -46
- cartography/intel/aws/resourcegroupstaggingapi.py +120 -66
- cartography/intel/aws/resources.py +57 -46
- cartography/intel/aws/route53.py +108 -61
- cartography/intel/aws/s3.py +168 -83
- cartography/intel/aws/s3accountpublicaccessblock.py +157 -0
- cartography/intel/aws/secretsmanager.py +24 -12
- cartography/intel/aws/securityhub.py +20 -9
- cartography/intel/aws/sns.py +166 -0
- cartography/intel/aws/sqs.py +60 -28
- cartography/intel/aws/ssm.py +70 -30
- cartography/intel/aws/util/arns.py +7 -7
- cartography/intel/aws/util/common.py +31 -4
- cartography/intel/azure/__init__.py +78 -19
- cartography/intel/azure/compute.py +101 -27
- cartography/intel/azure/cosmosdb.py +496 -170
- cartography/intel/azure/sql.py +296 -105
- cartography/intel/azure/storage.py +322 -113
- cartography/intel/azure/subscription.py +39 -23
- cartography/intel/azure/tenant.py +13 -4
- cartography/intel/azure/util/credentials.py +95 -55
- cartography/intel/bigfix/__init__.py +2 -2
- cartography/intel/bigfix/computers.py +93 -65
- cartography/intel/cloudflare/__init__.py +74 -0
- cartography/intel/cloudflare/accounts.py +57 -0
- cartography/intel/cloudflare/dnsrecords.py +64 -0
- cartography/intel/cloudflare/members.py +75 -0
- cartography/intel/cloudflare/roles.py +65 -0
- cartography/intel/cloudflare/zones.py +64 -0
- cartography/intel/create_indexes.py +3 -2
- cartography/intel/crowdstrike/__init__.py +11 -9
- cartography/intel/crowdstrike/endpoints.py +5 -1
- cartography/intel/crowdstrike/spotlight.py +8 -3
- cartography/intel/cve/__init__.py +46 -13
- cartography/intel/cve/feed.py +48 -12
- cartography/intel/digitalocean/__init__.py +22 -13
- cartography/intel/digitalocean/compute.py +75 -108
- cartography/intel/digitalocean/management.py +44 -80
- cartography/intel/digitalocean/platform.py +48 -43
- cartography/intel/dns.py +36 -10
- cartography/intel/duo/__init__.py +21 -16
- cartography/intel/duo/api_host.py +14 -9
- cartography/intel/duo/endpoints.py +50 -45
- cartography/intel/duo/groups.py +18 -14
- cartography/intel/duo/phones.py +37 -34
- cartography/intel/duo/tokens.py +26 -23
- cartography/intel/duo/users.py +54 -50
- cartography/intel/duo/web_authn_credentials.py +30 -25
- cartography/intel/entra/__init__.py +25 -7
- cartography/intel/entra/ou.py +112 -0
- cartography/intel/entra/users.py +69 -63
- cartography/intel/gcp/__init__.py +185 -49
- cartography/intel/gcp/compute.py +418 -231
- cartography/intel/gcp/crm.py +96 -43
- cartography/intel/gcp/dns.py +60 -19
- cartography/intel/gcp/gke.py +72 -38
- cartography/intel/gcp/iam.py +61 -41
- cartography/intel/gcp/storage.py +84 -55
- cartography/intel/github/__init__.py +13 -11
- cartography/intel/github/repos.py +270 -137
- cartography/intel/github/teams.py +170 -88
- cartography/intel/github/users.py +70 -39
- cartography/intel/github/util.py +36 -34
- cartography/intel/gsuite/__init__.py +47 -26
- cartography/intel/gsuite/api.py +73 -30
- cartography/intel/jamf/__init__.py +19 -1
- cartography/intel/jamf/computers.py +30 -7
- cartography/intel/jamf/util.py +7 -2
- cartography/intel/kandji/__init__.py +6 -3
- cartography/intel/kandji/devices.py +14 -8
- cartography/intel/kubernetes/namespaces.py +7 -4
- cartography/intel/kubernetes/pods.py +7 -4
- cartography/intel/kubernetes/services.py +8 -4
- cartography/intel/lastpass/__init__.py +2 -2
- cartography/intel/lastpass/users.py +23 -12
- cartography/intel/oci/__init__.py +44 -11
- cartography/intel/oci/iam.py +134 -38
- cartography/intel/oci/organizations.py +13 -6
- cartography/intel/oci/utils.py +43 -20
- cartography/intel/okta/__init__.py +66 -15
- cartography/intel/okta/applications.py +42 -20
- cartography/intel/okta/awssaml.py +93 -33
- cartography/intel/okta/factors.py +16 -4
- cartography/intel/okta/groups.py +56 -29
- cartography/intel/okta/organization.py +5 -1
- cartography/intel/okta/origins.py +6 -2
- cartography/intel/okta/roles.py +15 -5
- cartography/intel/okta/users.py +20 -8
- cartography/intel/okta/utils.py +6 -4
- cartography/intel/openai/__init__.py +86 -0
- cartography/intel/openai/adminapikeys.py +90 -0
- cartography/intel/openai/apikeys.py +96 -0
- cartography/intel/openai/projects.py +94 -0
- cartography/intel/openai/serviceaccounts.py +82 -0
- cartography/intel/openai/users.py +78 -0
- cartography/intel/openai/util.py +29 -0
- cartography/intel/pagerduty/__init__.py +8 -7
- cartography/intel/pagerduty/escalation_policies.py +18 -6
- cartography/intel/pagerduty/schedules.py +12 -4
- cartography/intel/pagerduty/services.py +11 -4
- cartography/intel/pagerduty/teams.py +8 -3
- cartography/intel/pagerduty/users.py +3 -1
- cartography/intel/pagerduty/vendors.py +3 -1
- cartography/intel/semgrep/__init__.py +24 -6
- cartography/intel/semgrep/dependencies.py +50 -28
- cartography/intel/semgrep/deployment.py +3 -1
- cartography/intel/semgrep/findings.py +42 -18
- cartography/intel/snipeit/__init__.py +17 -3
- cartography/intel/snipeit/asset.py +12 -6
- cartography/intel/snipeit/user.py +8 -5
- cartography/intel/snipeit/util.py +9 -4
- cartography/intel/tailscale/__init__.py +77 -0
- cartography/intel/tailscale/acls.py +146 -0
- cartography/intel/tailscale/devices.py +127 -0
- cartography/intel/tailscale/postureintegrations.py +81 -0
- cartography/intel/tailscale/tailnets.py +76 -0
- cartography/intel/tailscale/users.py +80 -0
- cartography/intel/tailscale/utils.py +132 -0
- cartography/models/aws/apigateway.py +21 -17
- cartography/models/aws/apigatewaycertificate.py +28 -22
- cartography/models/aws/apigatewayresource.py +28 -20
- cartography/models/aws/apigatewaystage.py +33 -25
- cartography/models/aws/cloudtrail/__init__.py +0 -0
- cartography/models/aws/cloudtrail/trail.py +61 -0
- cartography/models/aws/cloudwatch/__init__.py +0 -0
- cartography/models/aws/cloudwatch/loggroup.py +52 -0
- cartography/models/aws/dynamodb/gsi.py +30 -22
- cartography/models/aws/dynamodb/tables.py +25 -17
- cartography/models/aws/ec2/auto_scaling_groups.py +102 -82
- cartography/models/aws/ec2/images.py +36 -34
- cartography/models/aws/ec2/instances.py +51 -45
- cartography/models/aws/ec2/keypair.py +21 -16
- cartography/models/aws/ec2/keypair_instance.py +28 -21
- cartography/models/aws/ec2/launch_configurations.py +30 -26
- cartography/models/aws/ec2/launch_template_versions.py +48 -38
- cartography/models/aws/ec2/launch_templates.py +21 -17
- cartography/models/aws/ec2/load_balancer_listeners.py +27 -23
- cartography/models/aws/ec2/load_balancers.py +47 -37
- cartography/models/aws/ec2/network_acl_rules.py +38 -30
- cartography/models/aws/ec2/network_acls.py +38 -29
- cartography/models/aws/ec2/networkinterface_instance.py +52 -39
- cartography/models/aws/ec2/networkinterfaces.py +53 -37
- cartography/models/aws/ec2/privateip_networkinterface.py +32 -22
- cartography/models/aws/ec2/reservations.py +18 -14
- cartography/models/aws/ec2/route_table_associations.py +44 -34
- cartography/models/aws/ec2/route_tables.py +50 -43
- cartography/models/aws/ec2/routes.py +45 -37
- cartography/models/aws/ec2/securitygroup_instance.py +29 -20
- cartography/models/aws/ec2/securitygroup_networkinterface.py +24 -15
- cartography/models/aws/ec2/subnet_instance.py +24 -19
- cartography/models/aws/ec2/subnet_networkinterface.py +40 -31
- cartography/models/aws/ec2/volumes.py +47 -40
- cartography/models/aws/efs/__init__.py +0 -0
- cartography/models/aws/efs/mount_target.py +52 -0
- cartography/models/aws/eks/clusters.py +23 -21
- cartography/models/aws/emr.py +32 -30
- cartography/models/aws/iam/instanceprofile.py +33 -24
- cartography/models/aws/identitycenter/awsidentitycenter.py +18 -14
- cartography/models/aws/identitycenter/awspermissionset.py +37 -29
- cartography/models/aws/identitycenter/awsssouser.py +23 -21
- cartography/models/aws/inspector/findings.py +77 -65
- cartography/models/aws/inspector/packages.py +35 -29
- cartography/models/aws/s3/__init__.py +0 -0
- cartography/models/aws/s3/account_public_access_block.py +51 -0
- cartography/models/aws/sns/__init__.py +0 -0
- cartography/models/aws/sns/topic.py +50 -0
- cartography/models/aws/ssm/instance_information.py +51 -39
- cartography/models/aws/ssm/instance_patch.py +32 -26
- cartography/models/bigfix/bigfix_computer.py +42 -38
- cartography/models/bigfix/bigfix_root.py +3 -3
- cartography/models/cloudflare/__init__.py +0 -0
- cartography/models/cloudflare/account.py +25 -0
- cartography/models/cloudflare/dnsrecord.py +55 -0
- cartography/models/cloudflare/member.py +82 -0
- cartography/models/cloudflare/role.py +44 -0
- cartography/models/cloudflare/zone.py +59 -0
- cartography/models/core/common.py +12 -10
- cartography/models/core/nodes.py +5 -2
- cartography/models/core/relationships.py +14 -6
- cartography/models/crowdstrike/hosts.py +37 -35
- cartography/models/cve/cve.py +34 -32
- cartography/models/cve/cve_feed.py +6 -6
- cartography/models/digitalocean/__init__.py +0 -0
- cartography/models/digitalocean/account.py +21 -0
- cartography/models/digitalocean/droplet.py +56 -0
- cartography/models/digitalocean/project.py +48 -0
- cartography/models/duo/api_host.py +3 -3
- cartography/models/duo/endpoint.py +43 -41
- cartography/models/duo/group.py +14 -14
- cartography/models/duo/phone.py +27 -27
- cartography/models/duo/token.py +16 -16
- cartography/models/duo/user.py +46 -44
- cartography/models/duo/web_authn_credential.py +27 -19
- cartography/models/entra/ou.py +48 -0
- cartography/models/entra/tenant.py +24 -18
- cartography/models/entra/user.py +64 -48
- cartography/models/gcp/iam.py +23 -23
- cartography/models/github/orgs.py +5 -4
- cartography/models/github/teams.py +37 -31
- cartography/models/github/users.py +34 -23
- cartography/models/kandji/device.py +22 -16
- cartography/models/kandji/tenant.py +6 -4
- cartography/models/lastpass/tenant.py +3 -3
- cartography/models/lastpass/user.py +32 -28
- cartography/models/openai/__init__.py +0 -0
- cartography/models/openai/adminapikey.py +90 -0
- cartography/models/openai/apikey.py +84 -0
- cartography/models/openai/organization.py +17 -0
- cartography/models/openai/project.py +70 -0
- cartography/models/openai/serviceaccount.py +50 -0
- cartography/models/openai/user.py +49 -0
- cartography/models/semgrep/dependencies.py +36 -24
- cartography/models/semgrep/deployment.py +5 -5
- cartography/models/semgrep/findings.py +58 -42
- cartography/models/semgrep/locations.py +27 -21
- cartography/models/snipeit/asset.py +30 -21
- cartography/models/snipeit/tenant.py +6 -4
- cartography/models/snipeit/user.py +19 -12
- cartography/models/tailscale/__init__.py +0 -0
- cartography/models/tailscale/device.py +95 -0
- cartography/models/tailscale/group.py +86 -0
- cartography/models/tailscale/postureintegration.py +58 -0
- cartography/models/tailscale/tag.py +102 -0
- cartography/models/tailscale/tailnet.py +29 -0
- cartography/models/tailscale/user.py +52 -0
- cartography/stats.py +3 -3
- cartography/sync.py +113 -31
- cartography/util.py +84 -62
- {cartography-0.102.0rc2.dist-info → cartography-0.103.0.dist-info}/METADATA +8 -15
- cartography-0.103.0.dist-info/RECORD +442 -0
- {cartography-0.102.0rc2.dist-info → cartography-0.103.0.dist-info}/WHEEL +1 -1
- cartography-0.102.0rc2.dist-info/RECORD +0 -381
- {cartography-0.102.0rc2.dist-info → cartography-0.103.0.dist-info}/entry_points.txt +0 -0
- {cartography-0.102.0rc2.dist-info → cartography-0.103.0.dist-info}/licenses/LICENSE +0 -0
- {cartography-0.102.0rc2.dist-info → cartography-0.103.0.dist-info}/top_level.txt +0 -0
cartography/intel/aws/config.py
CHANGED
|
@@ -14,22 +14,28 @@ logger = logging.getLogger(__name__)
|
|
|
14
14
|
|
|
15
15
|
@timeit
|
|
16
16
|
@aws_handle_regions
|
|
17
|
-
def get_configuration_recorders(
|
|
18
|
-
|
|
17
|
+
def get_configuration_recorders(
|
|
18
|
+
boto3_session: boto3.session.Session,
|
|
19
|
+
region: str,
|
|
20
|
+
) -> List[Dict]:
|
|
21
|
+
client = boto3_session.client("config", region_name=region)
|
|
19
22
|
recorders: List[Dict] = []
|
|
20
23
|
response = client.describe_configuration_recorders()
|
|
21
|
-
for recorder in response.get(
|
|
24
|
+
for recorder in response.get("ConfigurationRecorders"):
|
|
22
25
|
recorders.append(recorder)
|
|
23
26
|
return recorders
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
@timeit
|
|
27
30
|
@aws_handle_regions
|
|
28
|
-
def get_delivery_channels(
|
|
29
|
-
|
|
31
|
+
def get_delivery_channels(
|
|
32
|
+
boto3_session: boto3.session.Session,
|
|
33
|
+
region: str,
|
|
34
|
+
) -> List[Dict]:
|
|
35
|
+
client = boto3_session.client("config", region_name=region)
|
|
30
36
|
channels: List[Dict] = []
|
|
31
37
|
response = client.describe_delivery_channels()
|
|
32
|
-
for channel in response.get(
|
|
38
|
+
for channel in response.get("DeliveryChannels"):
|
|
33
39
|
channels.append(channel)
|
|
34
40
|
return channels
|
|
35
41
|
|
|
@@ -37,11 +43,11 @@ def get_delivery_channels(boto3_session: boto3.session.Session, region: str) ->
|
|
|
37
43
|
@timeit
|
|
38
44
|
@aws_handle_regions
|
|
39
45
|
def get_config_rules(boto3_session: boto3.session.Session, region: str) -> List[Dict]:
|
|
40
|
-
client = boto3_session.client(
|
|
41
|
-
paginator = client.get_paginator(
|
|
46
|
+
client = boto3_session.client("config", region_name=region)
|
|
47
|
+
paginator = client.get_paginator("describe_config_rules")
|
|
42
48
|
rules: List[Dict] = []
|
|
43
49
|
for page in paginator.paginate():
|
|
44
|
-
rules.extend(page[
|
|
50
|
+
rules.extend(page["ConfigRules"])
|
|
45
51
|
return rules
|
|
46
52
|
|
|
47
53
|
|
|
@@ -72,7 +78,7 @@ def load_configuration_recorders(
|
|
|
72
78
|
# generate a unique id using a combo of the name, account id and region, since the name
|
|
73
79
|
# itself is unique per region.
|
|
74
80
|
for recorder in data:
|
|
75
|
-
recorder[
|
|
81
|
+
recorder["_id"] = f'{recorder["name"]}:{current_aws_account_id}:{region}'
|
|
76
82
|
|
|
77
83
|
neo4j_session.run(
|
|
78
84
|
ingest_configuration_recorders,
|
|
@@ -112,7 +118,7 @@ def load_delivery_channels(
|
|
|
112
118
|
# generate a unique id using a combo of the name, account id and region, since the name
|
|
113
119
|
# itself is unique per region.
|
|
114
120
|
for channel in data:
|
|
115
|
-
channel[
|
|
121
|
+
channel["_id"] = f'{channel["name"]}:{current_aws_account_id}:{region}'
|
|
116
122
|
|
|
117
123
|
neo4j_session.run(
|
|
118
124
|
ingest_delivery_channels,
|
|
@@ -157,9 +163,9 @@ def load_config_rules(
|
|
|
157
163
|
"""
|
|
158
164
|
for rule in data:
|
|
159
165
|
details = []
|
|
160
|
-
if rule.get(
|
|
166
|
+
if rule.get("Source", {}).get("SourceDetails"):
|
|
161
167
|
for detail in rule["Source"]["SourceDetails"]:
|
|
162
|
-
details.append(f
|
|
168
|
+
details.append(f"{detail}")
|
|
163
169
|
rule["_source_details"] = details
|
|
164
170
|
neo4j_session.run(
|
|
165
171
|
ingest_config_rules,
|
|
@@ -172,20 +178,50 @@ def load_config_rules(
|
|
|
172
178
|
|
|
173
179
|
@timeit
|
|
174
180
|
def cleanup_config(neo4j_session: neo4j.Session, common_job_parameters: Dict) -> None:
|
|
175
|
-
run_cleanup_job(
|
|
181
|
+
run_cleanup_job(
|
|
182
|
+
"aws_import_config_cleanup.json",
|
|
183
|
+
neo4j_session,
|
|
184
|
+
common_job_parameters,
|
|
185
|
+
)
|
|
176
186
|
|
|
177
187
|
|
|
178
188
|
@timeit
|
|
179
189
|
def sync(
|
|
180
|
-
neo4j_session: neo4j.Session,
|
|
181
|
-
|
|
190
|
+
neo4j_session: neo4j.Session,
|
|
191
|
+
boto3_session: boto3.session.Session,
|
|
192
|
+
regions: List[str],
|
|
193
|
+
current_aws_account_id: str,
|
|
194
|
+
update_tag: int,
|
|
195
|
+
common_job_parameters: Dict,
|
|
182
196
|
) -> None:
|
|
183
197
|
for region in regions:
|
|
184
|
-
logger.info(
|
|
198
|
+
logger.info(
|
|
199
|
+
"Syncing AWS Config for region '%s' in account '%s'.",
|
|
200
|
+
region,
|
|
201
|
+
current_aws_account_id,
|
|
202
|
+
)
|
|
185
203
|
recorders = get_configuration_recorders(boto3_session, region)
|
|
186
|
-
load_configuration_recorders(
|
|
204
|
+
load_configuration_recorders(
|
|
205
|
+
neo4j_session,
|
|
206
|
+
recorders,
|
|
207
|
+
region,
|
|
208
|
+
current_aws_account_id,
|
|
209
|
+
update_tag,
|
|
210
|
+
)
|
|
187
211
|
channels = get_delivery_channels(boto3_session, region)
|
|
188
|
-
load_delivery_channels(
|
|
212
|
+
load_delivery_channels(
|
|
213
|
+
neo4j_session,
|
|
214
|
+
channels,
|
|
215
|
+
region,
|
|
216
|
+
current_aws_account_id,
|
|
217
|
+
update_tag,
|
|
218
|
+
)
|
|
189
219
|
rules = get_config_rules(boto3_session, region)
|
|
190
|
-
load_config_rules(
|
|
220
|
+
load_config_rules(
|
|
221
|
+
neo4j_session,
|
|
222
|
+
rules,
|
|
223
|
+
region,
|
|
224
|
+
current_aws_account_id,
|
|
225
|
+
update_tag,
|
|
226
|
+
)
|
|
191
227
|
cleanup_config(neo4j_session, common_job_parameters)
|
|
@@ -22,12 +22,19 @@ stat_handler = get_stats_client(__name__)
|
|
|
22
22
|
|
|
23
23
|
@timeit
|
|
24
24
|
@aws_handle_regions
|
|
25
|
-
def get_dynamodb_tables(
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
def get_dynamodb_tables(
|
|
26
|
+
boto3_session: boto3.session.Session,
|
|
27
|
+
region: str,
|
|
28
|
+
) -> List[Dict]:
|
|
29
|
+
client = boto3_session.client(
|
|
30
|
+
"dynamodb",
|
|
31
|
+
region_name=region,
|
|
32
|
+
config=get_botocore_config(),
|
|
33
|
+
)
|
|
34
|
+
paginator = client.get_paginator("list_tables")
|
|
28
35
|
dynamodb_tables = []
|
|
29
36
|
for page in paginator.paginate():
|
|
30
|
-
for table_name in page[
|
|
37
|
+
for table_name in page["TableNames"]:
|
|
31
38
|
dynamodb_tables.append(client.describe_table(TableName=table_name))
|
|
32
39
|
return dynamodb_tables
|
|
33
40
|
|
|
@@ -38,33 +45,50 @@ def transform_dynamodb_tables(dynamodb_tables: List, region: str) -> Any:
|
|
|
38
45
|
ddb_gsi_data: List[Dict[str, Any]] = []
|
|
39
46
|
|
|
40
47
|
for table in dynamodb_tables:
|
|
41
|
-
ddb_table_data.append(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
ddb_table_data.append(
|
|
49
|
+
{
|
|
50
|
+
"Arn": table["Table"]["TableArn"],
|
|
51
|
+
"TableName": table["Table"]["TableName"],
|
|
52
|
+
"Region": region,
|
|
53
|
+
"Rows": table["Table"]["ItemCount"],
|
|
54
|
+
"Size": table["Table"]["TableSizeBytes"],
|
|
55
|
+
"ProvisionedThroughputReadCapacityUnits": table["Table"][
|
|
56
|
+
"ProvisionedThroughput"
|
|
57
|
+
]["ReadCapacityUnits"],
|
|
58
|
+
"ProvisionedThroughputWriteCapacityUnits": table["Table"][
|
|
59
|
+
"ProvisionedThroughput"
|
|
60
|
+
]["WriteCapacityUnits"],
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
for gsi in table["Table"].get("GlobalSecondaryIndexes", []):
|
|
64
|
+
ddb_gsi_data.append(
|
|
65
|
+
{
|
|
66
|
+
"Arn": gsi["IndexArn"],
|
|
67
|
+
"TableArn": table["Table"]["TableArn"],
|
|
68
|
+
"Region": region,
|
|
69
|
+
"ProvisionedThroughputReadCapacityUnits": gsi[
|
|
70
|
+
"ProvisionedThroughput"
|
|
71
|
+
]["ReadCapacityUnits"],
|
|
72
|
+
"ProvisionedThroughputWriteCapacityUnits": gsi[
|
|
73
|
+
"ProvisionedThroughput"
|
|
74
|
+
]["WriteCapacityUnits"],
|
|
75
|
+
"GSIName": gsi["IndexName"],
|
|
76
|
+
},
|
|
77
|
+
)
|
|
59
78
|
return ddb_table_data, ddb_gsi_data
|
|
60
79
|
|
|
61
80
|
|
|
62
81
|
@timeit
|
|
63
82
|
def load_dynamodb_tables(
|
|
64
|
-
neo4j_session: neo4j.Session,
|
|
83
|
+
neo4j_session: neo4j.Session,
|
|
84
|
+
tables_data: List[Dict[str, Any]],
|
|
85
|
+
region: str,
|
|
86
|
+
current_aws_account_id: str,
|
|
65
87
|
aws_update_tag: int,
|
|
66
88
|
) -> None:
|
|
67
|
-
logger.info(
|
|
89
|
+
logger.info(
|
|
90
|
+
f"Loading Dynamo DB tables {len(tables_data)} for region '{region}' into graph.",
|
|
91
|
+
)
|
|
68
92
|
load(
|
|
69
93
|
neo4j_session,
|
|
70
94
|
DynamoDBTableSchema(),
|
|
@@ -77,10 +101,15 @@ def load_dynamodb_tables(
|
|
|
77
101
|
|
|
78
102
|
@timeit
|
|
79
103
|
def load_dynamodb_gsi(
|
|
80
|
-
neo4j_session: neo4j.Session,
|
|
104
|
+
neo4j_session: neo4j.Session,
|
|
105
|
+
gsi_data: List[Dict[str, Any]],
|
|
106
|
+
region: str,
|
|
107
|
+
current_aws_account_id: str,
|
|
81
108
|
aws_update_tag: int,
|
|
82
109
|
) -> None:
|
|
83
|
-
logger.info(
|
|
110
|
+
logger.info(
|
|
111
|
+
f"Loading Dynamo DB GSI {len(gsi_data)} for region '{region}' into graph.",
|
|
112
|
+
)
|
|
84
113
|
load(
|
|
85
114
|
neo4j_session,
|
|
86
115
|
DynamoDBGSISchema(),
|
|
@@ -92,38 +121,77 @@ def load_dynamodb_gsi(
|
|
|
92
121
|
|
|
93
122
|
|
|
94
123
|
@timeit
|
|
95
|
-
def cleanup_dynamodb_tables(
|
|
96
|
-
|
|
97
|
-
|
|
124
|
+
def cleanup_dynamodb_tables(
|
|
125
|
+
neo4j_session: neo4j.Session,
|
|
126
|
+
common_job_parameters: Dict,
|
|
127
|
+
) -> None:
|
|
128
|
+
GraphJob.from_node_schema(DynamoDBTableSchema(), common_job_parameters).run(
|
|
129
|
+
neo4j_session,
|
|
130
|
+
)
|
|
131
|
+
GraphJob.from_node_schema(DynamoDBGSISchema(), common_job_parameters).run(
|
|
132
|
+
neo4j_session,
|
|
133
|
+
)
|
|
98
134
|
|
|
99
135
|
|
|
100
136
|
@timeit
|
|
101
137
|
def sync_dynamodb_tables(
|
|
102
|
-
neo4j_session: neo4j.Session,
|
|
103
|
-
|
|
138
|
+
neo4j_session: neo4j.Session,
|
|
139
|
+
boto3_session: boto3.session.Session,
|
|
140
|
+
regions: List[str],
|
|
141
|
+
current_aws_account_id: str,
|
|
142
|
+
aws_update_tag: int,
|
|
143
|
+
common_job_parameters: Dict,
|
|
104
144
|
) -> None:
|
|
105
145
|
for region in regions:
|
|
106
|
-
logger.info(
|
|
146
|
+
logger.info(
|
|
147
|
+
"Syncing DynamoDB for region in '%s' in account '%s'.",
|
|
148
|
+
region,
|
|
149
|
+
current_aws_account_id,
|
|
150
|
+
)
|
|
107
151
|
dynamodb_tables = get_dynamodb_tables(boto3_session, region)
|
|
108
|
-
ddb_table_data, ddb_gsi_data = transform_dynamodb_tables(
|
|
109
|
-
|
|
110
|
-
|
|
152
|
+
ddb_table_data, ddb_gsi_data = transform_dynamodb_tables(
|
|
153
|
+
dynamodb_tables,
|
|
154
|
+
region,
|
|
155
|
+
)
|
|
156
|
+
load_dynamodb_tables(
|
|
157
|
+
neo4j_session,
|
|
158
|
+
ddb_table_data,
|
|
159
|
+
region,
|
|
160
|
+
current_aws_account_id,
|
|
161
|
+
aws_update_tag,
|
|
162
|
+
)
|
|
163
|
+
load_dynamodb_gsi(
|
|
164
|
+
neo4j_session,
|
|
165
|
+
ddb_gsi_data,
|
|
166
|
+
region,
|
|
167
|
+
current_aws_account_id,
|
|
168
|
+
aws_update_tag,
|
|
169
|
+
)
|
|
111
170
|
cleanup_dynamodb_tables(neo4j_session, common_job_parameters)
|
|
112
171
|
|
|
113
172
|
|
|
114
173
|
@timeit
|
|
115
174
|
def sync(
|
|
116
|
-
neo4j_session: neo4j.Session,
|
|
117
|
-
|
|
175
|
+
neo4j_session: neo4j.Session,
|
|
176
|
+
boto3_session: boto3.session.Session,
|
|
177
|
+
regions: List[str],
|
|
178
|
+
current_aws_account_id: str,
|
|
179
|
+
update_tag: int,
|
|
180
|
+
common_job_parameters: Dict,
|
|
118
181
|
) -> None:
|
|
119
182
|
sync_dynamodb_tables(
|
|
120
|
-
neo4j_session,
|
|
183
|
+
neo4j_session,
|
|
184
|
+
boto3_session,
|
|
185
|
+
regions,
|
|
186
|
+
current_aws_account_id,
|
|
187
|
+
update_tag,
|
|
188
|
+
common_job_parameters,
|
|
121
189
|
)
|
|
122
190
|
merge_module_sync_metadata(
|
|
123
191
|
neo4j_session,
|
|
124
|
-
group_type=
|
|
192
|
+
group_type="AWSAccount",
|
|
125
193
|
group_id=current_aws_account_id,
|
|
126
|
-
synced_type=
|
|
194
|
+
synced_type="DynamoDBTable",
|
|
127
195
|
update_tag=update_tag,
|
|
128
196
|
stat_handler=stat_handler,
|
|
129
197
|
)
|
|
@@ -10,6 +10,6 @@ logger = logging.getLogger(__name__)
|
|
|
10
10
|
|
|
11
11
|
@timeit
|
|
12
12
|
def get_ec2_regions(boto3_session: boto3.session.Session) -> List[str]:
|
|
13
|
-
client = boto3_session.client(
|
|
13
|
+
client = boto3_session.client("ec2")
|
|
14
14
|
result = client.describe_regions()
|
|
15
|
-
return [r[
|
|
15
|
+
return [r["RegionName"] for r in result["Regions"]]
|