Example #1
0
def get_client(project_id, scopes=None, credentials=None):
    """
    Get a client for a specified project.

    :param project_id:  Name of the project to create a bigquery library client for
    :param scopes: List of Google scopes as strings
    :param credentials: Google credentials object (ignored if scopes is defined,
        uses delegated credentials instead)

    :return:  A bigquery Client object.
    """
    if scopes:
        credentials, project_id = default()
        credentials = auth.delegated_credentials(credentials, scopes=scopes)
    return bigquery.Client(project=project_id, credentials=credentials)
Example #2
0
    def __init__(self, project_id: str, scopes=None, credentials=None):
        """
        Get a storage client for a specified project.

        :param project_id: Identifies the project to create a cloud storage client for
        :param scopes: List of Google scopes as strings
        :param credentials: Google credentials object (ignored if scopes is defined,
            uses delegated credentials instead)

        :return:  A StorageClient instance
        """
        if scopes:
            credentials, project_id = default()
            credentials = auth.delegated_credentials(credentials,
                                                     scopes=scopes)
        super().__init__(project=project_id, credentials=credentials)
Example #3
0
def get_access_token():
    """
    Obtains GCP Bearer token

    :return: returns the access_token
    """

    scopes = [
        'https://www.googleapis.com/auth/cloud-platform', 'email', 'profile'
    ]

    credentials, _ = default()
    credentials = auth.delegated_credentials(credentials, scopes=scopes)

    request = req.Request()
    credentials.refresh(request)
    access_token = credentials.token

    return access_token
Example #4
0
def get_client(project_id=None, scopes=None):
    """
    Get a client for a specified project.

    :param project_id:  Name of the project to create a bigquery library client for
        It is being nice for now, but will begin to require users to provide
        the project_id.
    :param scopes: List of Google scopes as strings

    :return:  A bigquery Client object.
    """
    if scopes:
        credentials, project_id = default()
        credentials = auth.delegated_credentials(credentials, scopes=scopes)
        return bigquery.Client(project=project_id, credentials=credentials)
    if project_id is None:
        LOGGER.info(f"You should specify project_id for a reliable experience."
                    f"Defaulting to {os.environ.get(PROJECT_ID)}.")
        return bigquery.Client()
    return bigquery.Client(project=project_id)