in cartography/intel/gcp/compute.py [0:0]
def _attach_gcp_nic_access_configs(neo4j_session, nic_id, nic, gcp_update_tag):
"""
Attach an access configuration to the GCP NIC.
:param neo4j_session: The Neo4j session
:param instance: The GCP instance
:param gcp_update_tag: The timestamp to set updated nodes to
:return: Nothing
"""
query = """
MATCH (nic{id:{NicId}})
MERGE (ac:GCPNicAccessConfig{id:{AccessConfigId}})
ON CREATE SET ac.firstseen = timestamp(),
ac.access_config_id = {AccessConfigId}
SET ac.type={Type},
ac.name = {Name},
ac.public_ip = {NatIP},
ac.set_public_ptr = {SetPublicPtr},
ac.public_ptr_domain_name = {PublicPtrDomainName},
ac.network_tier = {NetworkTier},
ac.lastupdated = {gcp_update_tag}
MERGE (nic)-[r:RESOURCE]->(ac)
ON CREATE SET r.firstseen = timestamp()
SET r.lastupdated = {gcp_update_tag}
"""
for ac in nic.get('accessConfigs', []):
# Make an ID for GCPNicAccessConfig nodes because GCP doesn't define one but we need to uniquely identify them
access_config_id = f"{nic_id}/accessconfigs/{ac['type']}"
neo4j_session.run(
query,
NicId=nic_id,
AccessConfigId=access_config_id,
Type=ac['type'],
Name=ac['name'],
NatIP=ac.get('natIP', None),
SetPublicPtr=ac.get('setPublicPtr', None),
PublicPtrDomainName=ac.get('publicPtrDomainName', None),
NetworkTier=ac.get('networkTier', None),
gcp_update_tag=gcp_update_tag
)