blob: 0ecd79e40c5a6a299dd41ac5c30c2b5338cfb73f [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Provides functions of BigQuery client."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from google.cloud import bigquery # pylint: disable=import-error,no-name-in-module
from google.oauth2 import service_account # pylint: disable=import-error,no-name-in-module
from test_analyzer import configs
def CreateClient(project, is_stage=False):
"""Create bigquery client.
Args:
project: a String, represents which project the bigquery belongs to.
is_stage: a Boolean, refers to use secret files for staging or prod.
Returns:
A bigquery.Client object.
"""
secret_json = configs.GetServiceAccountCredentials(is_stage)
credentials = service_account.Credentials.from_service_account_file(
secret_json)
return bigquery.Client(project=project, credentials=credentials)