def load_gcp_subnets()

in cartography/intel/gcp/compute.py [0:0]


def load_gcp_subnets(neo4j_session, subnets, gcp_update_tag):
    """
    Ingest GCP subnet data to Neo4j
    :param neo4j_session: The Neo4j session
    :param subnets: List of the subnets
    :param gcp_update_tag: The timestamp to set these Neo4j nodes with
    :return: Nothing
    """
    query = """
    MERGE(vpc:GCPVpc{id:{VpcPartialUri}})
    ON CREATE SET vpc.firstseen = timestamp(),
    vpc.partial_uri = {VpcPartialUri}

    MERGE(subnet:GCPSubnet{id:{PartialUri}})
    ON CREATE SET subnet.firstseen = timestamp(),
    subnet.partial_uri = {PartialUri}
    SET subnet.self_link = {SubnetSelfLink},
    subnet.project_id = {ProjectId},
    subnet.name = {SubnetName},
    subnet.region = {Region},
    subnet.gateway_address = {GatewayAddress},
    subnet.ip_cidr_range = {IpCidrRange},
    subnet.private_ip_google_access = {PrivateIpGoogleAccess},
    subnet.vpc_partial_uri = {VpcPartialUri},
    subnet.lastupdated = {gcp_update_tag}

    MERGE (vpc)-[r:RESOURCE]->(subnet)
    ON CREATE SET r.firstseen = timestamp()
    SET r.lastupdated = {gcp_update_tag}
    """
    for s in subnets:
        neo4j_session.run(
            query,
            VpcPartialUri=s['vpc_partial_uri'],
            VpcSelfLink=s['vpc_self_link'],
            PartialUri=s['partial_uri'],
            SubnetSelfLink=s['self_link'],
            ProjectId=s['project_id'],
            SubnetName=s['name'],
            Region=s['region'],
            GatewayAddress=s['gateway_address'],
            IpCidrRange=s['ip_cidr_range'],
            PrivateIpGoogleAccess=s['private_ip_google_access'],
            gcp_update_tag=gcp_update_tag
        )