Skip to content

Commit

Permalink
Remove duplicate EC2 cleanup jobs (#1151)
Browse files Browse the repository at this point in the history
Fast follow of #1146 - removes
duplicate calls to cleanup jobs. All these manual jobs will soon be
deprecated as we refactor modules to the new data model.
  • Loading branch information
achantavy authored Apr 3, 2023
1 parent 915c254 commit 672b5fe
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 73 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"statements": [
{
"query": "MATCH (n:EC2SecurityGroup)<-[:RESOURCE]-(:AWSAccount{id: $AWS_ID}) WHERE n.lastupdated <> $UPDATE_TAG WITH n LIMIT $LIMIT_SIZE DETACH DELETE (n)",
"iterative": true,
"iterationsize": 100
},
{
"query": "MATCH (n:IpRule)-[:MEMBER_OF_EC2_SECURITY_GROUP]->(:EC2SecurityGroup)<-[:RESOURCE]-(:AWSAccount{id: $AWS_ID}) WHERE n.lastupdated <> $UPDATE_TAG WITH n LIMIT $LIMIT_SIZE DETACH DELETE (n)",
"iterative": true,
Expand Down
20 changes: 0 additions & 20 deletions cartography/data/jobs/cleanup/aws_import_volumes_cleanup.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,10 @@
"iterationsize": 100,
"iterative": true
},
{
"query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(:EC2Instance)-[r:PART_OF_SUBNET]->(:EC2Subnet) WHERE r.lastupdated <> $UPDATE_TAG WITH r LIMIT $LIMIT_SIZE DELETE (r)",
"iterationsize": 100,
"iterative": true
},
{
"query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(:LoadBalancer)-[r:PART_OF_SUBNET]->(:EC2Subnet) WHERE r.lastupdated <> $UPDATE_TAG WITH r LIMIT $LIMIT_SIZE DELETE (r)",
"iterationsize": 100,
"iterative": true
},
{
"query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(n:NetworkInterface) WHERE n.lastupdated <> $UPDATE_TAG WITH n LIMIT $LIMIT_SIZE DETACH DELETE (n)",
"iterative": true,
"iterationsize": 100
},
{
"query": "MATCH (:AWSAccount{id: $AWS_ID})-[r:RESOURCE]->(:NetworkInterface) WHERE r.lastupdated <> $UPDATE_TAG WITH r LIMIT $LIMIT_SIZE DELETE (r)",
"iterative": true,
"iterationsize": 100
}
],
"name": "cleanup NetworkInterface"
Expand Down
5 changes: 0 additions & 5 deletions cartography/intel/aws/ec2/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ def cleanup(neo4j_session: neo4j.Session, common_job_parameters: Dict[str, Any])
logger.debug("Running EC2 instance cleanup")
GraphJob.from_node_schema(EC2ReservationSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EC2InstanceSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EC2SubnetSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EC2SecurityGroupSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EC2KeyPairSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EC2NetworkInterfaceSchema(), common_job_parameters).run(neo4j_session)
GraphJob.from_node_schema(EBSVolumeSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down
5 changes: 3 additions & 2 deletions cartography/intel/aws/ec2/key_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import neo4j

from .util import get_botocore_config
from cartography.graph.job import GraphJob
from cartography.models.aws.ec2.keypairs import EC2KeyPairSchema
from cartography.util import aws_handle_regions
from cartography.util import run_cleanup_job
from cartography.util import timeit

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,7 +56,7 @@ def load_ec2_key_pairs(

@timeit
def cleanup_ec2_key_pairs(neo4j_session: neo4j.Session, common_job_parameters: Dict) -> None:
run_cleanup_job('aws_import_ec2_key_pairs_cleanup.json', neo4j_session, common_job_parameters)
GraphJob.from_node_schema(EC2KeyPairSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down
3 changes: 3 additions & 0 deletions cartography/intel/aws/ec2/network_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import neo4j

from .util import get_botocore_config
from cartography.graph.job import GraphJob
from cartography.models.aws.ec2.networkinterfaces import EC2NetworkInterfaceSchema
from cartography.util import aws_handle_regions
from cartography.util import run_cleanup_job
from cartography.util import timeit
Expand Down Expand Up @@ -265,6 +267,7 @@ def load(neo4j_session: neo4j.Session, data: List[Dict], region: str, aws_accoun
@timeit
def cleanup_network_interfaces(neo4j_session: neo4j.Session, common_job_parameters: Dict) -> None:
run_cleanup_job('aws_ingest_network_interfaces_cleanup.json', neo4j_session, common_job_parameters)
GraphJob.from_node_schema(EC2NetworkInterfaceSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down
3 changes: 3 additions & 0 deletions cartography/intel/aws/ec2/security_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import neo4j

from .util import get_botocore_config
from cartography.graph.job import GraphJob
from cartography.models.aws.ec2.securitygroups import EC2SecurityGroupSchema
from cartography.util import aws_handle_regions
from cartography.util import run_cleanup_job
from cartography.util import timeit
Expand Down Expand Up @@ -146,6 +148,7 @@ def cleanup_ec2_security_groupinfo(neo4j_session: neo4j.Session, common_job_para
neo4j_session,
common_job_parameters,
)
GraphJob.from_node_schema(EC2SecurityGroupSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down
3 changes: 3 additions & 0 deletions cartography/intel/aws/ec2/subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import neo4j

from .util import get_botocore_config
from cartography.graph.job import GraphJob
from cartography.models.aws.ec2.subnets import EC2SubnetSchema
from cartography.util import aws_handle_regions
from cartography.util import run_cleanup_job
from cartography.util import timeit
Expand Down Expand Up @@ -76,6 +78,7 @@ def load_subnets(
@timeit
def cleanup_subnets(neo4j_session: neo4j.Session, common_job_parameters: Dict) -> None:
run_cleanup_job('aws_ingest_subnets_cleanup.json', neo4j_session, common_job_parameters)
GraphJob.from_node_schema(EC2SubnetSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down
9 changes: 3 additions & 6 deletions cartography/intel/aws/ec2/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import boto3
import neo4j

from cartography.graph.job import GraphJob
from cartography.models.aws.ec2.volumes import EBSVolumeSchema
from cartography.util import aws_handle_regions
from cartography.util import run_cleanup_job
from cartography.util import timeit

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,11 +98,7 @@ def load_volume_relationships(

@timeit
def cleanup_volumes(neo4j_session: neo4j.Session, common_job_parameters: Dict) -> None:
run_cleanup_job(
'aws_import_volumes_cleanup.json',
neo4j_session,
common_job_parameters,
)
GraphJob.from_node_schema(EBSVolumeSchema(), common_job_parameters).run(neo4j_session)


@timeit
Expand Down

0 comments on commit 672b5fe

Please sign in to comment.