Skip to content

[DO NOT MERGE] [RFC] attempt to allow impersonation from service account #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
40 changes: 20 additions & 20 deletions pybigquery/sqlalchemy_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ def __init__(
credentials_path=None,
location=None,
credentials_info=None,
with_subject=None,
*args, **kwargs):
super(BigQueryDialect, self).__init__(*args, **kwargs)
self.arraysize = arraysize
self.credentials_path = credentials_path
self.credentials_info = credentials_info
self.with_subject = with_subject
self.location = location
self.dataset_id = None

Expand All @@ -223,28 +225,26 @@ def create_connect_args(self, url):
self.credentials_path = credentials_path or self.credentials_path
self.dataset_id = dataset_id

creds = None
project = url.host

if self.credentials_path:
client = bigquery.Client.from_service_account_json(
self.credentials_path,
location=self.location,
default_query_job_config=default_query_job_config
)
creds = service_account.Credentials.from_service_account_file(
self.credentials_path)
elif self.credentials_info:
credentials = service_account.Credentials.from_service_account_info(
self.credentials_info
)
client = bigquery.Client(
project=self.credentials_info.get('project_id'),
credentials=credentials,
location=self.location,
default_query_job_config=default_query_job_config,
)
else:
client = bigquery.Client(
project=url.host,
location=self.location,
default_query_job_config=default_query_job_config
)
creds = service_account.Credentials.from_service_account_info(
self.credentials_info)
project = self.credentials_info.get('project_id')

if self.with_subject:
creds = creds.with_subject(self.with_subject)

client = bigquery.Client(
credentials=creds,
location=self.location,
project=project,
default_query_job_config=default_query_job_config
)

# if dataset_id is set, then we know the job_config isn't None
if dataset_id:
Expand Down