in cartography/intel/gcp/compute.py [0:0]
def _attach_instance_tags(neo4j_session, instance, gcp_update_tag):
"""
Attach tags to GCP instance and to the VPCs that they are defined in.
:param neo4j_session: The session
:param instance: The instance object
:param gcp_update_tag: The timestamp
:return: Nothing
"""
query = """
MATCH (i:GCPInstance{id:{InstanceId}})
MERGE (t:GCPNetworkTag{id:{TagId}})
ON CREATE SET t.tag_id = {TagId},
t.value = {TagValue},
t.firstseen = timestamp()
SET t.lastupdated = {gcp_update_tag}
MERGE (i)-[h:TAGGED]->(t)
ON CREATE SET h.firstseen = timestamp()
SET h.lastupdated = {gcp_update_tag}
WITH t
MATCH (vpc:GCPVpc{id:{VpcPartialUri}})
MERGE (vpc)<-[d:DEFINED_IN]-(t)
ON CREATE SET d.firstseen = timestamp()
SET d.lastupdated = {gcp_update_tag}
"""
for tag in instance.get('tags', {}).get('items', []):
for nic in instance.get('networkInterfaces', []):
tag_id = _create_gcp_network_tag_id(nic['vpc_partial_uri'], tag)
neo4j_session.run(
query,
InstanceId=instance['partial_uri'],
TagId=tag_id,
TagValue=tag,
VpcPartialUri=nic['vpc_partial_uri'],
gcp_update_tag=gcp_update_tag
)