def load_gcp_projects()

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


def load_gcp_projects(neo4j_session, data, gcp_update_tag):
    """
    Ingest the GCP projects to Neo4j
    :param neo4j_session: The Neo4j session
    :param data: List of GCP projects; output from crm.get_gcp_projects()
    :param gcp_update_tag: The timestamp value to set our new Neo4j nodes with
    :return: Nothing
    """
    for project in data:
        if project.get('parent', None):
            if project['parent']['type'] == "organization":
                query = """
                MERGE (parent:GCPOrganization{id:{ParentId}})
                ON CREATE SET parent.firstseen = timestamp()
                """
                parentid = f"organizations/{project['parent']['id']}"
            elif project['parent']['type'] == "folder":
                query = """
                MERGE (parent:GCPFolder{id:{ParentId}})
                ON CREATE SET parent.firstseen = timestamp()
                """
                parentid = f"folders/{project['parent']['id']}"
        query += """
        MERGE (project:GCPProject{id:{ProjectId}})
        ON CREATE SET project.firstseen = timestamp()
        SET project.projectid = {ProjectId},
        project.displayname = {DisplayName},
        project.lifecyclestate = {LifecycleState},
        project.lastupdated = {gcp_update_tag}
        WITH parent, project
        MERGE (parent)-[r:RESOURCE]->(project)
        ON CREATE SET r.firstseen = timestamp()
        SET r.lastupdated = {gcp_update_tag}
        """
        neo4j_session.run(
            query,
            ParentId=parentid,
            ProjectId=project['projectId'],
            DisplayName=project.get('name', None),
            LifecycleState=project.get('lifecycleState', None),
            gcp_update_tag=gcp_update_tag
        )