Skip to content
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

Logging: Add 'client_options' support, update list method docstrings (via synth). #8535

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
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
33 changes: 24 additions & 9 deletions logging/google/cloud/logging_v2/gapic/config_service_v2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.

Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 28 additions & 13 deletions logging/google/cloud/logging_v2/gapic/logging_service_v2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.

Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 20 additions & 5 deletions logging/google/cloud/logging_v2/gapic/metrics_service_v2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,6 +100,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.

Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions logging/google/cloud/logging_v2/proto/log_entry_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions logging/google/cloud/logging_v2/proto/logging_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions logging/synth.metadata
Original file line number Diff line number Diff line change
@@ -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"
}
},
{
Expand Down