Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/connectors_service/connectors/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _default_config():
"github": "connectors.sources.github:GitHubDataSource",
"gitlab": "connectors.sources.gitlab:GitLabDataSource",
"gmail": "connectors.sources.gmail:GMailDataSource",
"google_bigquery": "connectors.sources.google_bigquery:GoogleBigqueryDataSource",
"google_cloud_storage": "connectors.sources.google_cloud_storage:GoogleCloudStorageDataSource",
"google_drive": "connectors.sources.google_drive:GoogleDriveDataSource",
"graphql": "connectors.sources.graphql:GraphQLDataSource",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License 2.0;
# you may not use this file except in compliance with the Elastic License 2.0.
#
from .client import GoogleBigqueryClient
from .datasource import GoogleBigqueryDataSource

__all__ = ["GoogleBigqueryClient", "GoogleBigqueryDataSource"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License 2.0;
# you may not use this file except in compliance with the Elastic License 2.0.
#
"""Google Bigquery module which fetches rows from a Bigquery table."""

from connectors_sdk.logger import logger
from google.cloud import bigquery
from google.oauth2 import service_account


class GoogleBigqueryClient:
"""A client to make api calls to Google Bigquery."""

def __init__(self, json_credentials):
"""Initialize the ServiceAccountCreds instance.

Args:
json_credentials(dict): Service account credentials json."""
self.json_credentials = json_credentials
self._logger = logger

def set_logger(self, logger_):
self._logger = logger_

def client(self, project_id=None):
"""Returns an instance of a bigquery client, using the configured credentials,
optionally to a different project_id (configured creds must have permissions to
access and create query jobs in it).

Args:
project_id (string, optional): If connecting to a project other than the
service account credentials default, pass this as a string.

Returns:
bigquery.Client instance

"""
credentials = service_account.Credentials.from_service_account_info(
self.json_credentials
)
if project_id is not None:
return bigquery.Client(credentials=credentials, project=project_id)
else:
return bigquery.Client(credentials=credentials)
Loading
Loading