Skip to content

Commit

Permalink
convert volume syntax (cartography-cncf#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonpetgrave64 authored Sep 14, 2022
1 parent 2c1f29b commit a400a20
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cartography/data/jobs/cleanup/aws_import_volumes_cleanup.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"statements": [
{
"query": "MATCH (n:EBSVolume)<-[:RESOURCE]-(:AWSAccount{id: {AWS_ID}}) WHERE n.lastupdated <> {UPDATE_TAG} WITH n LIMIT {LIMIT_SIZE} DETACH DELETE (n)",
"query": "MATCH (n:EBSVolume)<-[:RESOURCE]-(:AWSAccount{id: $AWS_ID}) WHERE n.lastupdated <> $UPDATE_TAG WITH n LIMIT $LIMIT_SIZE DETACH DELETE (n)",
"iterative": true,
"iterationsize": 100
},
{
"query": "MATCH (:EBSVolume)<-[r:RESOURCE]-(:AWSAccount{id: {AWS_ID}}) WHERE r.lastupdated <> {UPDATE_TAG} WITH r LIMIT {LIMIT_SIZE} DELETE (r)",
"query": "MATCH (:EBSVolume)<-[r:RESOURCE]-(:AWSAccount{id: $AWS_ID}) WHERE r.lastupdated <> $UPDATE_TAG WITH r LIMIT $LIMIT_SIZE DELETE (r)",
"iterative": true,
"iterationsize": 100
},
{
"query": "MATCH (:EBSVolume)-[r:ATTACHED_TO_EC2_INSTANCE]->(:EC2Instance)<-[:RESOURCE]-(:AWSAccount{id: {AWS_ID}}) WHERE r.lastupdated <> {UPDATE_TAG} WITH r LIMIT {LIMIT_SIZE} DELETE (r)",
"query": "MATCH (:EBSVolume)-[r:ATTACHED_TO_EC2_INSTANCE]->(:EC2Instance)<-[:RESOURCE]-(:AWSAccount{id: $AWS_ID}) WHERE r.lastupdated <> $UPDATE_TAG WITH r LIMIT $LIMIT_SIZE DELETE (r)",
"iterative": true,
"iterationsize": 100
}
Expand Down
16 changes: 8 additions & 8 deletions cartography/intel/aws/ec2/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def load_volumes(
neo4j_session: neo4j.Session, data: List[Dict], region: str, current_aws_account_id: str, update_tag: int,
) -> None:
ingest_volumes = """
UNWIND {volumes_list} as volume
UNWIND $volumes_list as volume
MERGE (vol:EBSVolume{id: volume.VolumeId})
ON CREATE SET vol.firstseen = timestamp()
SET vol.arn = volume.VolumeArn,
vol.lastupdated = {update_tag},
vol.lastupdated = $update_tag,
vol.availabilityzone = volume.AvailabilityZone,
vol.createtime = volume.CreateTime,
vol.encrypted = volume.Encrypted,
Expand All @@ -53,12 +53,12 @@ def load_volumes(
vol.multiattachenabled = volume.MultiAttachEnabled,
vol.type = volume.VolumeType,
vol.kmskeyid = volume.KmsKeyId,
vol.region={Region}
vol.region=$Region
WITH vol
MATCH (aa:AWSAccount{id: {AWS_ACCOUNT_ID}})
MATCH (aa:AWSAccount{id: $AWS_ACCOUNT_ID})
MERGE (aa)-[r:RESOURCE]->(vol)
ON CREATE SET r.firstseen = timestamp()
SET r.lastupdated = {update_tag}
SET r.lastupdated = $update_tag
"""

neo4j_session.run(
Expand All @@ -76,12 +76,12 @@ def load_volume_relationships(
aws_update_tag: int,
) -> None:
add_relationship_query = """
MATCH (volume:EBSVolume{arn: {VolumeArn}})
MATCH (volume:EBSVolume{arn: $VolumeArn})
WITH volume
MATCH (instance:EC2Instance{instanceid: {InstanceId}})
MATCH (instance:EC2Instance{instanceid: $InstanceId})
MERGE (volume)-[r:ATTACHED_TO_EC2_INSTANCE]->(instance)
ON CREATE SET r.firstseen = timestamp()
SET r.lastupdated = {aws_update_tag}
SET r.lastupdated = $aws_update_tag
"""
for volume in volumes:
for attachment in volume.get('Attachments', []):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_load_volume_to_account_rels(neo4j_session):
# Arrange: Create Test AWSAccount
neo4j_session.run(
"""
MERGE (aws:AWSAccount{id: {aws_account_id}})
MERGE (aws:AWSAccount{id: $aws_account_id})
ON CREATE SET aws.firstseen = timestamp()
SET aws.lastupdated = {aws_update_tag}
SET aws.lastupdated = $aws_update_tag
""",
aws_account_id=TEST_ACCOUNT_ID,
aws_update_tag=TEST_UPDATE_TAG,
Expand Down

0 comments on commit a400a20

Please sign in to comment.