in cartography/intel/gcp/compute.py [0:0]
def transform_gcp_subnets(subnet_res):
"""
Add additional fields to the subnet object to make it easier to process in `load_gcp_subnets()`.
:param subnet_res: The response object returned from compute.subnetworks.list()
:return: A transformed subnet_res
"""
# The `id` in the response object has the form `projects/{project}/regions/{region}/subnetworks`.
# We can include this in each subnet object in the list to form the partial_uri later on.
prefix = subnet_res['id']
projectid = prefix.split('/')[1]
subnet_list = []
for s in subnet_res.get('items', []):
subnet = {}
# Has the form `projects/{project}/regions/{region}/subnetworks/{subnet_name}`
partial_uri = f"{prefix}/{s['name']}"
subnet['id'] = partial_uri
subnet['partial_uri'] = partial_uri
# Let's maintain an on-node reference to the VPC that this subnet belongs to.
subnet['vpc_self_link'] = s['network']
subnet['vpc_partial_uri'] = _parse_compute_full_uri_to_partial_uri(s['network'])
subnet['name'] = s['name']
subnet['project_id'] = projectid
# Region looks like "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region name}"
subnet['region'] = s['region'].split('/')[-1]
subnet['gateway_address'] = s.get('gatewayAddress', None)
subnet['ip_cidr_range'] = s.get('ipCidrRange', None)
subnet['self_link'] = s['selfLink']
subnet['private_ip_google_access'] = s.get('privateIpGoogleAccess', None)
subnet_list.append(subnet)
return subnet_list