Example #1
0
def start_digitalocean_ingestion(neo4j_session: neo4j.Session,
                                 config: Config) -> None:
    """
    If this module is configured, perform ingestion of DigitalOcean  data. Otherwise warn and exit
    :param neo4j_session: Neo4J session for database interface
    :param config: A cartography.config object
    :return: None
    """

    if not config.digitalocean_token:
        logger.info(
            'DigitalOcean import is not configured - skipping this module. See docs to configure.'
        )
        return

    common_job_parameters = {
        "UPDATE_TAG": config.update_tag,
    }
    manager = Manager(config.digitalocean_token)
    """
    Get Account ID related to this credentials and pass it along in `common_job_parameters` to avoid cleaning up other
    accounts resources
    """
    account = manager.get_account()
    common_job_parameters["DO_ACCOUNT_ID"] = account.uuid

    platform.sync(neo4j_session, account, config.update_tag,
                  common_job_parameters)
    project_resources = management.sync(neo4j_session, manager,
                                        config.update_tag,
                                        common_job_parameters)
    compute.sync(neo4j_session, manager, project_resources, config.update_tag,
                 common_job_parameters)
    return
Example #2
0
def get_account_data(manager: Manager) -> Account:
    """
    API call to DigitalOcean's API v2 in order to get account data.

    :param digitalocean.Manager.Manager manager: instance
    :return: digitalocean.Account.Account instance
    """
    with pong(text=cyan_text("Retrieving account data...")):
        return manager.get_account()