From 87c08d67ba2ef0fe9a65b700a6f7c975d256267a Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 28 Jun 2019 13:39:40 -0400 Subject: [PATCH] Add 'client_options' support, update list method docstrings (via synth). Supersedes #8320. --- .../gapic/config_service_v2_client.py | 33 +++++++++++---- .../gapic/logging_service_v2_client.py | 41 +++++++++++++------ .../gapic/metrics_service_v2_client.py | 25 ++++++++--- .../config_service_v2_grpc_transport.py | 8 +++- .../logging_service_v2_grpc_transport.py | 8 +++- .../metrics_service_v2_grpc_transport.py | 8 +++- .../cloud/logging_v2/proto/log_entry_pb2.py | 1 + .../logging_v2/proto/logging_config_pb2.py | 1 + .../logging_v2/proto/logging_metrics_pb2.py | 1 + .../cloud/logging_v2/proto/logging_pb2.py | 1 + logging/synth.metadata | 10 ++--- 11 files changed, 99 insertions(+), 38 deletions(-) diff --git a/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py b/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py index 3e52190f050e..7102218ca68c 100644 --- a/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py +++ b/logging/google/cloud/logging_v2/gapic/config_service_v2_client.py @@ -21,6 +21,7 @@ import warnings from google.oauth2 import service_account +import google.api_core.client_options import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -109,6 +110,7 @@ def __init__( credentials=None, client_config=None, client_info=None, + client_options=None, ): """Constructor. @@ -139,6 +141,9 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + client_options (Union[dict, google.api_core.client_options.ClientOptions]): + Client options used to set user options on the client. API Endpoint + should be set through client_options. """ # Raise deprecation warnings for things we want to go away. if client_config is not None: @@ -157,6 +162,15 @@ def __init__( stacklevel=2, ) + api_endpoint = self.SERVICE_ADDRESS + if client_options: + if type(client_options) == dict: + client_options = google.api_core.client_options.from_dict( + client_options + ) + if client_options.api_endpoint: + api_endpoint = client_options.api_endpoint + # Instantiate the transport. # The transport is responsible for handling serialization and # deserialization and actually sending data to the service. @@ -165,6 +179,7 @@ def __init__( self.transport = transport( credentials=credentials, default_class=config_service_v2_grpc_transport.ConfigServiceV2GrpcTransport, + address=api_endpoint, ) else: if credentials: @@ -175,7 +190,7 @@ def __init__( self.transport = transport else: self.transport = config_service_v2_grpc_transport.ConfigServiceV2GrpcTransport( - address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials + address=api_endpoint, channel=channel, credentials=credentials ) if client_info is None: @@ -257,10 +272,10 @@ def list_sinks( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`~google.cloud.logging_v2.types.LogSink` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`~google.cloud.logging_v2.types.LogSink` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request @@ -753,10 +768,10 @@ def list_exclusions( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`~google.cloud.logging_v2.types.LogExclusion` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`~google.cloud.logging_v2.types.LogExclusion` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request diff --git a/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py b/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py index 13a4ad4cfcd9..4c24acbb2bed 100644 --- a/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py +++ b/logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py @@ -21,6 +21,7 @@ import warnings from google.oauth2 import service_account +import google.api_core.client_options import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -94,6 +95,7 @@ def __init__( credentials=None, client_config=None, client_info=None, + client_options=None, ): """Constructor. @@ -124,6 +126,9 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + client_options (Union[dict, google.api_core.client_options.ClientOptions]): + Client options used to set user options on the client. API Endpoint + should be set through client_options. """ # Raise deprecation warnings for things we want to go away. if client_config is not None: @@ -142,6 +147,15 @@ def __init__( stacklevel=2, ) + api_endpoint = self.SERVICE_ADDRESS + if client_options: + if type(client_options) == dict: + client_options = google.api_core.client_options.from_dict( + client_options + ) + if client_options.api_endpoint: + api_endpoint = client_options.api_endpoint + # Instantiate the transport. # The transport is responsible for handling serialization and # deserialization and actually sending data to the service. @@ -150,6 +164,7 @@ def __init__( self.transport = transport( credentials=credentials, default_class=logging_service_v2_grpc_transport.LoggingServiceV2GrpcTransport, + address=api_endpoint, ) else: if credentials: @@ -160,7 +175,7 @@ def __init__( self.transport = transport else: self.transport = logging_service_v2_grpc_transport.LoggingServiceV2GrpcTransport( - address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials + address=api_endpoint, channel=channel, credentials=credentials ) if client_info is None: @@ -500,10 +515,10 @@ def list_log_entries( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`~google.cloud.logging_v2.types.LogEntry` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`~google.cloud.logging_v2.types.LogEntry` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request @@ -590,10 +605,10 @@ def list_monitored_resource_descriptors( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`~google.cloud.logging_v2.types.MonitoredResourceDescriptor` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`~google.cloud.logging_v2.types.MonitoredResourceDescriptor` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request @@ -692,10 +707,10 @@ def list_logs( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`str` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`str` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request diff --git a/logging/google/cloud/logging_v2/gapic/metrics_service_v2_client.py b/logging/google/cloud/logging_v2/gapic/metrics_service_v2_client.py index 0ee7a871f5e3..22a9a32aef55 100644 --- a/logging/google/cloud/logging_v2/gapic/metrics_service_v2_client.py +++ b/logging/google/cloud/logging_v2/gapic/metrics_service_v2_client.py @@ -21,6 +21,7 @@ import warnings from google.oauth2 import service_account +import google.api_core.client_options import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -99,6 +100,7 @@ def __init__( credentials=None, client_config=None, client_info=None, + client_options=None, ): """Constructor. @@ -129,6 +131,9 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + client_options (Union[dict, google.api_core.client_options.ClientOptions]): + Client options used to set user options on the client. API Endpoint + should be set through client_options. """ # Raise deprecation warnings for things we want to go away. if client_config is not None: @@ -147,6 +152,15 @@ def __init__( stacklevel=2, ) + api_endpoint = self.SERVICE_ADDRESS + if client_options: + if type(client_options) == dict: + client_options = google.api_core.client_options.from_dict( + client_options + ) + if client_options.api_endpoint: + api_endpoint = client_options.api_endpoint + # Instantiate the transport. # The transport is responsible for handling serialization and # deserialization and actually sending data to the service. @@ -155,6 +169,7 @@ def __init__( self.transport = transport( credentials=credentials, default_class=metrics_service_v2_grpc_transport.MetricsServiceV2GrpcTransport, + address=api_endpoint, ) else: if credentials: @@ -165,7 +180,7 @@ def __init__( self.transport = transport else: self.transport = metrics_service_v2_grpc_transport.MetricsServiceV2GrpcTransport( - address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials + address=api_endpoint, channel=channel, credentials=credentials ) if client_info is None: @@ -244,10 +259,10 @@ def list_log_metrics( that is provided to the method. Returns: - A :class:`~google.gax.PageIterator` instance. By default, this - is an iterable of :class:`~google.cloud.logging_v2.types.LogMetric` instances. - This object can also be configured to iterate over the pages - of the response through the `options` parameter. + A :class:`~google.api_core.page_iterator.PageIterator` instance. + An iterable of :class:`~google.cloud.logging_v2.types.LogMetric` instances. + You can also iterate over the pages of the response + using its `pages` property. Raises: google.api_core.exceptions.GoogleAPICallError: If the request diff --git a/logging/google/cloud/logging_v2/gapic/transports/config_service_v2_grpc_transport.py b/logging/google/cloud/logging_v2/gapic/transports/config_service_v2_grpc_transport.py index 3ef9f6949eab..61f6a0fd514b 100644 --- a/logging/google/cloud/logging_v2/gapic/transports/config_service_v2_grpc_transport.py +++ b/logging/google/cloud/logging_v2/gapic/transports/config_service_v2_grpc_transport.py @@ -77,7 +77,9 @@ def __init__( } @classmethod - def create_channel(cls, address="logging.googleapis.com:443", credentials=None): + def create_channel( + cls, address="logging.googleapis.com:443", credentials=None, **kwargs + ): """Create and return a gRPC channel object. Args: @@ -87,12 +89,14 @@ def create_channel(cls, address="logging.googleapis.com:443", credentials=None): credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. + kwargs (dict): Keyword arguments, which are passed to the + channel creation. Returns: grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, credentials=credentials, scopes=cls._OAUTH_SCOPES + address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs ) @property diff --git a/logging/google/cloud/logging_v2/gapic/transports/logging_service_v2_grpc_transport.py b/logging/google/cloud/logging_v2/gapic/transports/logging_service_v2_grpc_transport.py index 388b9e644431..c09932918fb9 100644 --- a/logging/google/cloud/logging_v2/gapic/transports/logging_service_v2_grpc_transport.py +++ b/logging/google/cloud/logging_v2/gapic/transports/logging_service_v2_grpc_transport.py @@ -75,7 +75,9 @@ def __init__( } @classmethod - def create_channel(cls, address="logging.googleapis.com:443", credentials=None): + def create_channel( + cls, address="logging.googleapis.com:443", credentials=None, **kwargs + ): """Create and return a gRPC channel object. Args: @@ -85,12 +87,14 @@ def create_channel(cls, address="logging.googleapis.com:443", credentials=None): credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. + kwargs (dict): Keyword arguments, which are passed to the + channel creation. Returns: grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, credentials=credentials, scopes=cls._OAUTH_SCOPES + address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs ) @property diff --git a/logging/google/cloud/logging_v2/gapic/transports/metrics_service_v2_grpc_transport.py b/logging/google/cloud/logging_v2/gapic/transports/metrics_service_v2_grpc_transport.py index 4b1e18149f24..badaea4b3c98 100644 --- a/logging/google/cloud/logging_v2/gapic/transports/metrics_service_v2_grpc_transport.py +++ b/logging/google/cloud/logging_v2/gapic/transports/metrics_service_v2_grpc_transport.py @@ -77,7 +77,9 @@ def __init__( } @classmethod - def create_channel(cls, address="logging.googleapis.com:443", credentials=None): + def create_channel( + cls, address="logging.googleapis.com:443", credentials=None, **kwargs + ): """Create and return a gRPC channel object. Args: @@ -87,12 +89,14 @@ def create_channel(cls, address="logging.googleapis.com:443", credentials=None): credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. + kwargs (dict): Keyword arguments, which are passed to the + channel creation. Returns: grpc.Channel: A gRPC channel object. """ return google.api_core.grpc_helpers.create_channel( - address, credentials=credentials, scopes=cls._OAUTH_SCOPES + address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs ) @property diff --git a/logging/google/cloud/logging_v2/proto/log_entry_pb2.py b/logging/google/cloud/logging_v2/proto/log_entry_pb2.py index 3aa17006be30..6dc9ec5817f1 100644 --- a/logging/google/cloud/logging_v2/proto/log_entry_pb2.py +++ b/logging/google/cloud/logging_v2/proto/log_entry_pb2.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/logging_v2/proto/log_entry.proto diff --git a/logging/google/cloud/logging_v2/proto/logging_config_pb2.py b/logging/google/cloud/logging_v2/proto/logging_config_pb2.py index d62ef9c95eec..cf50eedc6090 100644 --- a/logging/google/cloud/logging_v2/proto/logging_config_pb2.py +++ b/logging/google/cloud/logging_v2/proto/logging_config_pb2.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/logging_v2/proto/logging_config.proto diff --git a/logging/google/cloud/logging_v2/proto/logging_metrics_pb2.py b/logging/google/cloud/logging_v2/proto/logging_metrics_pb2.py index 54dc8f703c20..fc50185871d2 100644 --- a/logging/google/cloud/logging_v2/proto/logging_metrics_pb2.py +++ b/logging/google/cloud/logging_v2/proto/logging_metrics_pb2.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/logging_v2/proto/logging_metrics.proto diff --git a/logging/google/cloud/logging_v2/proto/logging_pb2.py b/logging/google/cloud/logging_v2/proto/logging_pb2.py index a37710bcf382..2438534d754b 100644 --- a/logging/google/cloud/logging_v2/proto/logging_pb2.py +++ b/logging/google/cloud/logging_v2/proto/logging_pb2.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/logging_v2/proto/logging.proto diff --git a/logging/synth.metadata b/logging/synth.metadata index ecd32783bf21..7be7882c8885 100644 --- a/logging/synth.metadata +++ b/logging/synth.metadata @@ -1,19 +1,19 @@ { - "updateTime": "2019-05-21T12:25:22.738575Z", + "updateTime": "2019-06-28T17:38:07.047804Z", "sources": [ { "generator": { "name": "artman", - "version": "0.20.0", - "dockerImage": "googleapis/artman@sha256:3246adac900f4bdbd62920e80de2e5877380e44036b3feae13667ec255ebf5ec" + "version": "0.29.2", + "dockerImage": "googleapis/artman@sha256:45263333b058a4b3c26a8b7680a2710f43eae3d250f791a6cb66423991dcb2df" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "32a10f69e2c9ce15bba13ab1ff928bacebb25160", - "internalRef": "249058354" + "sha": "84c8ad4e52f8eec8f08a60636cfa597b86969b5c", + "internalRef": "255474859" } }, {