Exemplo n.º 1
0
def _api_client_factory(config, threads):
    """Creates the proper initialized API client based on the configuration.

    Args:
        config (object): Inventory configuration on server.
        threads (int): how many threads to use.

    Returns:
        Union[gcp.ApiClientImpl, cai_gcp_client.CaiApiClientImpl]:
            The initialized api client implementation class.
    """
    client_config = config.get_api_quota_configs()
    client_config['domain_super_admin_email'] = config.get_gsuite_admin_email()
    client_config['excluded_resources'] = config.get_excluded_resources()
    if config.get_cai_enabled():
        # TODO: When CAI supports resource exclusion, update the following
        #       method to handle resource exclusion during export time.
        engine, tmpfile = cai_temporary_storage.create_sqlite_db(threads)
        asset_count = cloudasset.load_cloudasset_data(engine, config)
        LOGGER.info('%s total assets loaded from Cloud Asset data.',
                    asset_count)

        if asset_count:
            return cai_gcp_client.CaiApiClientImpl(client_config, engine,
                                                   tmpfile)

    # Default to the non-CAI implementation
    return gcp.ApiClientImpl(client_config)
Exemplo n.º 2
0
    def setUp(self):
        """Setup method."""
        unittest_utils.ForsetiTestCase.setUp(self)
        self.engine, self.dbfile = cai_temporary_storage.create_sqlite_db()
        self.inventory_config = InventoryConfig(
            'organizations/987654321', '', {}, 0, {
                'enabled': True,
                'gcs_path': 'gs://test-bucket'
            })
        self.mock_auth = mock.patch.object(
            google.auth,
            'default',
            return_value=(mock.Mock(spec_set=credentials.Credentials),
                          'test-project')).start()

        self.mock_export_assets = mock.patch.object(
            cloudasset_api.CloudAssetClient, 'export_assets',
            autospec=True).start()
        self.mock_download = mock.patch.object(storage.StorageClient,
                                               'download',
                                               autospec=True).start()
Exemplo n.º 3
0
 def setUp(self):
     """Setup method."""
     ForsetiTestCase.setUp(self)
     self.engine, self.dbfile = cai_temporary_storage.create_sqlite_db()