示例#1
0
 def get_client(self):
     if self._client is None:
         credentials = self._get_credentials()
         # Add client library info for better error tracking
         client_info = ClientInfo(client_library_version='airflow_v' + version.version)
         self._client = container_v1.ClusterManagerClient(credentials=credentials, client_info=client_info)
     return self._client
示例#2
0
 def client(self) -> SecretManagerServiceClient:
     """Create an authenticated KMS client"""
     _client = SecretManagerServiceClient(
         credentials=self.credentials,
         client_info=ClientInfo(client_library_version='airflow_v' +
                                version))
     return _client
示例#3
0
 def test_google_client_info_custom_useragent(self):
     got = google_client_info("custom-user-agent").to_grpc_metadata()
     want = ClientInfo(
         user_agent="custom-user-agent",
         python_version="%d.%d.%d" %
         (vers.major, vers.minor, vers.micro or 0),
     ).to_grpc_metadata()
     self.assertEqual(got, want)
示例#4
0
 def test_google_client_info_default_useragent(self):
     got = google_client_info().to_grpc_metadata()
     want = ClientInfo(
         user_agent=DEFAULT_USER_AGENT,
         python_version="%d.%d.%d" %
         (vers.major, vers.minor, vers.micro or 0),
     ).to_grpc_metadata()
     self.assertEqual(got, want)
 def _logging_service_client(self) -> LoggingServiceV2Client:
     """The Cloud logging service v2 client."""
     credentials, _ = self._credentials_and_project
     client = LoggingServiceV2Client(
         credentials=credentials,
         client_info=ClientInfo(client_library_version='airflow_v' + version.version),
     )
     return client
示例#6
0
    def __init__(self):
        # This facade is currently using both libraries as the Cloud Client library doesn't support locations

        # Cloud Client
        client_info = ClientInfo(user_agent=get_user_agent())
        self.cloud_client = kms.KeyManagementServiceClient(client_info=client_info)
        # self.cloud_client = kms.KeyManagementServiceClient()

        super().__init__('cloudkms', 'v1')  # API Client
示例#7
0
    def __init__(self, project_id, location):
        self.project_id = project_id
        self.location = location

        # Add client library info for better error tracking
        client_info = ClientInfo(client_library_version='airflow_v' +
                                 version.version)
        self.client = container_v1.ClusterManagerClient(
            client_info=client_info)
 def _client(self) -> gcp_logging.Client:
     """The Cloud Library API client"""
     credentials, project = self._credentials_and_project
     client = gcp_logging.Client(
         credentials=credentials,
         project=project,
         client_info=ClientInfo(client_library_version='airflow_v' + version.version),
     )
     return client
def google_client_info(user_agent=None):
    """
    Return a google.api_core.gapic_v1.client_info.ClientInfo
    containg the user_agent and python_version for this library
    """

    return ClientInfo(
        user_agent=user_agent or DEFAULT_USER_AGENT,
        python_version='%d.%d.%d' % (vers.major, vers.minor, vers.micro or 0),
    )
 def _client(self) -> gcp_logging.Client:
     """Google Cloud Library API client"""
     credentials = get_credentials_and_project_id(
         key_path=self.gcp_key_path,
         scopes=self.scopes,
     )
     client = gcp_logging.Client(
         credentials=credentials,
         client_info=ClientInfo(client_library_version='airflow_v' +
                                version.version))
     return client
 def client(self) -> SecretManagerServiceClient:
     """
     Create an authenticated KMS client
     """
     scopes = _get_scopes(self.gcp_scopes)
     self.credentials, self.project_id = get_credentials_and_project_id(
         key_path=self.gcp_key_path, scopes=scopes)
     _client = SecretManagerServiceClient(
         credentials=self.credentials,
         client_info=ClientInfo(client_library_version='airflow_v' +
                                version.version))
     return _client
示例#12
0
    def client_info(self) -> ClientInfo:
        """
        Return client information used to generate a user-agent for API calls.

        It allows for better errors tracking.

        This object is only used by the google-cloud-* libraries that are built specifically for
        the Google Cloud. It is not supported by The Google APIs Python Client that use Discovery
        based APIs.
        """
        client_info = ClientInfo(client_library_version='airflow_v' + version.version)
        return client_info
    def get_client(self):
        """
        Returns ClusterManagerCLinet object.

        :rtype: google.cloud.container_v1.ClusterManagerCLinet
        """
        if self._client is None:
            credentials = self._get_credentials()
            # Add client library info for better error tracking
            client_info = ClientInfo(client_library_version='airflow_v' +
                                     version.version)
            self._client = container_v1.ClusterManagerClient(
                credentials=credentials, client_info=client_info)
        return self._client
示例#14
0
    def _client(self) -> gcp_logging.Client:
        """Google Cloud Library API client"""
        if self.gcp_conn_id:
            from airflow.providers.google.common.hooks.base_google import GoogleBaseHook

            hook = GoogleBaseHook(gcp_conn_id=self.gcp_conn_id)
            credentials = hook._get_credentials()  # pylint: disable=protected-access
        else:
            # Use Application Default Credentials
            credentials = None
        client = gcp_logging.Client(
            credentials=credentials,
            client_info=ClientInfo(client_library_version='airflow_v' +
                                   version.version))
        return client
 def get_uptime_client(self):
     client_info = ClientInfo(user_agent=get_user_agent())
     client = stackdrivermonitoring.UptimeCheckServiceClient(client_info=client_info)
     return client
示例#16
0
 def get_client(self, project_id: str):
     client_info = ClientInfo(user_agent=get_user_agent())
     client = storage.Client(project=project_id, client_info=client_info)
     return client
示例#17
0
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from google.api_core.gapic_v1.client_info import ClientInfo

from airflow import version

GOOGLE_DEFAULT_DEFERRABLE_METHOD_NAME = 'execute_complete'

CLIENT_INFO = ClientInfo(client_library_version='airflow_v' + version.version)
示例#18
0
    def _get_client_info(self):
        from google.api_core.gapic_v1.client_info import ClientInfo

        return ClientInfo(user_agent=self.USER_AGENT)
示例#19
0
 def get_client(self, project_id: str):
     client_info = ClientInfo(user_agent=get_user_agent())
     client = stackdriverlogging.Client(project=project_id,
                                        client_info=client_info)
     return client
示例#20
0
def connect(
    instance_id,
    database_id,
    project=None,
    credentials=None,
    pool=None,
    user_agent=None,
):
    """Creates a connection to a Google Cloud Spanner database.

    :type instance_id: str
    :param instance_id: The ID of the instance to connect to.

    :type database_id: str
    :param database_id: The ID of the database to connect to.

    :type project: str
    :param project: (Optional) The ID of the project which owns the
                    instances, tables and data. If not provided, will
                    attempt to determine from the environment.

    :type credentials: Union[:class:`~google.auth.credentials.Credentials`, str]
    :param credentials: (Optional) The authorization credentials to attach to
                        requests. These credentials identify this application
                        to the service. These credentials may be specified as
                        a file path indicating where to retrieve the service
                        account JSON for the credentials to connect to
                        Cloud Spanner. If none are specified, the client will
                        attempt to ascertain the credentials from the
                        environment.

    :type pool: Concrete subclass of
                :class:`~google.cloud.spanner_v1.pool.AbstractSessionPool`.
    :param pool: (Optional). Session pool to be used by database.

    :type user_agent: str
    :param user_agent: (Optional) User agent to be used with this connection's
                       requests.

    :rtype: :class:`google.cloud.spanner_dbapi.connection.Connection`
    :returns: Connection object associated with the given Google Cloud Spanner
              resource.

    :raises: :class:`ValueError` in case of given instance/database
             doesn't exist.
    """

    client_info = ClientInfo(user_agent=user_agent or DEFAULT_USER_AGENT,
                             python_version=PY_VERSION)

    if isinstance(credentials, str):
        client = spanner.Client.from_service_account_json(
            credentials, project=project, client_info=client_info)
    else:
        client = spanner.Client(project=project,
                                credentials=credentials,
                                client_info=client_info)

    instance = client.instance(instance_id)
    if not instance.exists():
        raise ValueError("instance '%s' does not exist." % instance_id)

    database = instance.database(database_id, pool=pool)
    if not database.exists():
        raise ValueError("database '%s' does not exist." % database_id)

    conn = Connection(instance, database)
    if pool is not None:
        conn._own_pool = False

    return conn
 def get_alerts_client(self):
     client_info = ClientInfo(user_agent=get_user_agent())
     client = stackdrivermonitoring.AlertPolicyServiceClient(client_info=client_info)
     return client
示例#22
0
    ExceptionInterceptor,
    LoggingInterceptor,
)

_logger = logging.getLogger(__name__)

_SERVICE_CLIENT_TEMPLATE = "{}Client"

_VALID_API_VERSIONS = ["v10", "v9", "v8"]
_DEFAULT_VERSION = _VALID_API_VERSIONS[0]

# Retrieve the version of this client library to be sent in the user-agent
# information of API calls.
try:
    _CLIENT_INFO = ClientInfo(
        client_library_version=pkg_resources.get_distribution(
            "google-ads", ).version, )
except pkg_resources.DistributionNotFound:
    _CLIENT_INFO = ClientInfo()

# See options at grpc.github.io/grpc/core/group__grpc__arg__keys.html
_GRPC_CHANNEL_OPTIONS = [
    ("grpc.max_metadata_size", 16 * 1024 * 1024),
    ("grpc.max_receive_message_length", 64 * 1024 * 1024),
]

unary_stream_single_threading_option = util.get_nested_attr(
    grpc, "experimental.ChannelOptions.SingleThreadedUnaryStream", None)

if unary_stream_single_threading_option:
    _GRPC_CHANNEL_OPTIONS.append((unary_stream_single_threading_option, 1))