# Buggy code
def load_gke_clusters(neo4j_session, gke_list, project_id, gcp_update_tag):
    """
    Ingest GCP GKE Clusters to Neo4j

    :type neo4j_session: Neo4j session object
    :param neo4j session: The Neo4j session object

    :type gke_list: list
    :param gke_list: List of GCP GKE Clusters to inject

    :type gcp_update_tag: timestamp
    :param gcp_update_tag: The timestamp value to set our new Neo4j nodes with

    :rtype: NoneType
    :return: Nothing
    """

    query = """
    MERGE(cluster:GKECluster{id:{ClusterSelfLink}})
    ON CREATE SET
        cluster.firstseen = timestamp(),
        cluster.created_at = {ClusterCreateTime}
    SET
        cluster.name = {ClusterName},
        cluster.self_link = {ClusterSelfLink},
        cluster.description = {ClusterDescription},
        cluster.logging_service = {ClusterLoggingService},
        cluster.monitoring_service = {ClusterMonitoringService},
        cluster.network = {ClusterNetwork},
        cluster.subnetwork = {ClusterSubnetwork},
        cluster.cluster_ipv4cidr = {ClusterIPv4Cidr},
        cluster.zone = {ClusterZone},
        cluster.location = {ClusterLocation},
        cluster.endpoint = {ClusterEndpoint},
        cluster.initial_version = {ClusterInitialVersion},
        cluster.current_master_version = {ClusterMasterVersion},
        cluster.status = {ClusterStatus},
        cluster.services_ipv4cidr = {ClusterServicesIPv4Cidr},
        cluster.database_encryption = {ClusterDatabaseEncryption},
        cluster.network_policy = {ClusterNetworkPolicy},
        cluster.master_authorized_networks = {ClusterMasterAuthorizedNetworks},
        cluster.legacy_abac = {ClusterAbac},
        cluster.shielded_nodes = {ClusterShieldedNodes},
        cluster.private_nodes = {ClusterPrivateNodes},
        cluster.private_endpoint_enabled = {ClusterPrivateEndpointEnabled},
        cluster.private_endpoint = {ClusterPrivateEndpoint},
        cluster.public_endpoint = {ClusterPublicEndpoint},
        cluster.masterauth_username = {ClusterMasterUsername},
        cluster.masterauth_password = {ClusterMasterPassword}
    WITH cluster
    MATCH (owner:GCPProject{id:{ProjectId}})
    MERGE (owner)-[r:RESOURCE]->(cluster)
    ON CREATE SET r.firstseen = timestamp()
    SET r.lastupdated = {gcp_update_tag}
    """
    for cluster in gke_list.get("clusters", []):
        neo4j_session.run(
            query,
            ProjectId=project_id,
            ClusterSelfLink=cluster["selfLink"],
            ClusterCreateTime=cluster["createTime"],
            ClusterName=cluster["name"],
            ClusterDescription=cluster.get("description"),
            ClusterLoggingService=cluster.get("loggingService"),
            ClusterMonitoringService=cluster.get("monitoringService"),
            ClusterNetwork=cluster.get("network"),
            ClusterSubnetwork=cluster.get("subnetwork"),
            ClusterIPv4Cidr=cluster.get("clusterIpv4Cidr"),
            ClusterZone=cluster.get("zone"),
            ClusterLocation=cluster.get("location"),
            ClusterEndpoint=cluster.get("endpoint"),
            ClusterInitialVersion=cluster.get("initialClusterVersion"),
            ClusterMasterVersion=cluster.get("currentMasterVersion"),
            ClusterStatus=cluster.get("status"),
            ClusterServicesIPv4Cidr=cluster.get("servicesIpv4Cidr"),
            ClusterDatabaseEncryption=cluster.get("databaseEncryption", {}).get(
                "state"
            ),
            ClusterNetworkPolicy=_process_network_policy(cluster),
            ClusterMasterAuthorizedNetworks=cluster.get(
                "masterAuthorizedNetworksConfig", {}
            ).get("enabled"),
            ClusterAbac=cluster.get("legacyAbac", {}).get("enabled"),
            ClusterShieldedNodes=cluster.get("shieldedNodes", {}).get("enabled"),
            ClusterPrivateNodes=cluster.get("privateClusterConfig", {}).get(
                "enablePrivateNodes"
            ),
            ClusterPrivateEndpointEnabled=cluster.get("privateClusterConfig", {}).get(
                "enablePrivateEndpoint"
            ),
            ClusterPrivateEndpoint=cluster.get("privateClusterConfig", {}).get(
                "privateEndpoint"
            ),
            ClusterPublicEndpoint=cluster.get("privateClusterConfig", {}).get(
                "publicEndpoint"
            ),
            ClusterMasterUsername=cluster.get("masterAuth", {}).get("username"),
            ClusterMasterPassword=cluster.get("masterAuth", {}).get("password"),
            gcp_update_tag=gcp_update_tag,
        )


# Traceback (googleapiclient.errors.HttpError)
Traceback (most recent call last):
File "{path}/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 218, in start_gcp_ingestion
_sync_multiple_projects(neo4j_session, resources, projects, config.update_tag, common_job_parameters)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 177, in _sync_multiple_projects
_sync_single_project(neo4j_session, resources, project_id, gcp_update_tag, common_job_parameters)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 155, in _sync_single_project
gke.sync_gke_clusters(neo4j_session, resources.container, project_id, gcp_update_tag, common_job_parameters)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/gke.py", line 197, in sync_gke_clusters
gke_res = get_gke_clusters(container, project_id)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/gke.py", line 28, in get_gke_clusters
res = req.execute()
File "{path}/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "{path}/site-packages/googleapiclient/http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://container.googleapis.com/v1/projects/{ProjectName}}/zones/-/clusters?alt=json returned "Required "container.clusters.list" permission(s) for "projects/{ProjectName}".">

# Fixed code
def load_gke_clusters(neo4j_session, cluster_resp, project_id, gcp_update_tag):
    """
    Ingest GCP GKE Clusters to Neo4j

    :type neo4j_session: Neo4j session object
    :param neo4j session: The Neo4j session object

    :type cluster_resp: Dict
    :param cluster_resp: A cluster response object from the GKE API

    :type gcp_update_tag: timestamp
    :param gcp_update_tag: The timestamp value to set our new Neo4j nodes with

    :rtype: NoneType
    :return: Nothing
    """

    query = """
    MERGE(cluster:GKECluster{id:{ClusterSelfLink}})
    ON CREATE SET
        cluster.firstseen = timestamp(),
        cluster.created_at = {ClusterCreateTime}
    SET
        cluster.name = {ClusterName},
        cluster.self_link = {ClusterSelfLink},
        cluster.description = {ClusterDescription},
        cluster.logging_service = {ClusterLoggingService},
        cluster.monitoring_service = {ClusterMonitoringService},
        cluster.network = {ClusterNetwork},
        cluster.subnetwork = {ClusterSubnetwork},
        cluster.cluster_ipv4cidr = {ClusterIPv4Cidr},
        cluster.zone = {ClusterZone},
        cluster.location = {ClusterLocation},
        cluster.endpoint = {ClusterEndpoint},
        cluster.initial_version = {ClusterInitialVersion},
        cluster.current_master_version = {ClusterMasterVersion},
        cluster.status = {ClusterStatus},
        cluster.services_ipv4cidr = {ClusterServicesIPv4Cidr},
        cluster.database_encryption = {ClusterDatabaseEncryption},
        cluster.network_policy = {ClusterNetworkPolicy},
        cluster.master_authorized_networks = {ClusterMasterAuthorizedNetworks},
        cluster.legacy_abac = {ClusterAbac},
        cluster.shielded_nodes = {ClusterShieldedNodes},
        cluster.private_nodes = {ClusterPrivateNodes},
        cluster.private_endpoint_enabled = {ClusterPrivateEndpointEnabled},
        cluster.private_endpoint = {ClusterPrivateEndpoint},
        cluster.public_endpoint = {ClusterPublicEndpoint},
        cluster.masterauth_username = {ClusterMasterUsername},
        cluster.masterauth_password = {ClusterMasterPassword}
    WITH cluster
    MATCH (owner:GCPProject{id:{ProjectId}})
    MERGE (owner)-[r:RESOURCE]->(cluster)
    ON CREATE SET r.firstseen = timestamp()
    SET r.lastupdated = {gcp_update_tag}
    """
    for cluster in cluster_resp.get("clusters", []):
        neo4j_session.run(
            query,
            ProjectId=project_id,
            ClusterSelfLink=cluster["selfLink"],
            ClusterCreateTime=cluster["createTime"],
            ClusterName=cluster["name"],
            ClusterDescription=cluster.get("description"),
            ClusterLoggingService=cluster.get("loggingService"),
            ClusterMonitoringService=cluster.get("monitoringService"),
            ClusterNetwork=cluster.get("network"),
            ClusterSubnetwork=cluster.get("subnetwork"),
            ClusterIPv4Cidr=cluster.get("clusterIpv4Cidr"),
            ClusterZone=cluster.get("zone"),
            ClusterLocation=cluster.get("location"),
            ClusterEndpoint=cluster.get("endpoint"),
            ClusterInitialVersion=cluster.get("initialClusterVersion"),
            ClusterMasterVersion=cluster.get("currentMasterVersion"),
            ClusterStatus=cluster.get("status"),
            ClusterServicesIPv4Cidr=cluster.get("servicesIpv4Cidr"),
            ClusterDatabaseEncryption=cluster.get("databaseEncryption", {}).get(
                "state"
            ),
            ClusterNetworkPolicy=_process_network_policy(cluster),
            ClusterMasterAuthorizedNetworks=cluster.get(
                "masterAuthorizedNetworksConfig", {}
            ).get("enabled"),
            ClusterAbac=cluster.get("legacyAbac", {}).get("enabled"),
            ClusterShieldedNodes=cluster.get("shieldedNodes", {}).get("enabled"),
            ClusterPrivateNodes=cluster.get("privateClusterConfig", {}).get(
                "enablePrivateNodes"
            ),
            ClusterPrivateEndpointEnabled=cluster.get("privateClusterConfig", {}).get(
                "enablePrivateEndpoint"
            ),
            ClusterPrivateEndpoint=cluster.get("privateClusterConfig", {}).get(
                "privateEndpoint"
            ),
            ClusterPublicEndpoint=cluster.get("privateClusterConfig", {}).get(
                "publicEndpoint"
            ),
            ClusterMasterUsername=cluster.get("masterAuth", {}).get("username"),
            ClusterMasterPassword=cluster.get("masterAuth", {}).get("password"),
            gcp_update_tag=gcp_update_tag,
        )