Skip to content

Commit

Permalink
Add 'client_options' support, update list method docstrings (via synt…
Browse files Browse the repository at this point in the history
…h). (#8516)
  • Loading branch information
yoshi-automation authored and tseaver committed Jun 28, 2019
1 parent db77953 commit ed958eb
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 50 deletions.
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 @@ -120,6 +121,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -150,6 +152,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 @@ -168,6 +173,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 @@ -176,6 +190,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=alert_policy_service_grpc_transport.AlertPolicyServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -186,7 +201,7 @@ def __init__(
self.transport = transport
else:
self.transport = alert_policy_service_grpc_transport.AlertPolicyServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -280,10 +295,10 @@ def list_alert_policies(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.AlertPolicy` 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.monitoring_v3.types.AlertPolicy` 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 @@ -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 @@ -113,6 +114,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -143,6 +145,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 @@ -161,6 +166,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 @@ -169,6 +183,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=group_service_grpc_transport.GroupServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -179,7 +194,7 @@ def __init__(
self.transport = transport
else:
self.transport = group_service_grpc_transport.GroupServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -270,10 +285,10 @@ def list_groups(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.Group` 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.monitoring_v3.types.Group` 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 @@ -720,10 +735,10 @@ def list_group_members(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.MonitoredResource` 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.monitoring_v3.types.MonitoredResource` 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 @@ -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 @@ -119,6 +120,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -149,6 +151,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 @@ -167,6 +172,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 @@ -175,6 +189,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=metric_service_grpc_transport.MetricServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -185,7 +200,7 @@ def __init__(
self.transport = transport
else:
self.transport = metric_service_grpc_transport.MetricServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -272,10 +287,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.monitoring_v3.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.monitoring_v3.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 @@ -475,10 +490,10 @@ def list_metric_descriptors(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.MetricDescriptor` 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.monitoring_v3.types.MetricDescriptor` 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 @@ -859,10 +874,10 @@ def list_time_series(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.TimeSeries` 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.monitoring_v3.types.TimeSeries` 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 @@ -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 @@ -124,6 +125,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -154,6 +156,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 @@ -172,6 +177,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 @@ -180,6 +194,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=notification_channel_service_grpc_transport.NotificationChannelServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -190,7 +205,7 @@ def __init__(
self.transport = transport
else:
self.transport = notification_channel_service_grpc_transport.NotificationChannelServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -275,10 +290,10 @@ def list_notification_channel_descriptors(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.NotificationChannelDescriptor` 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.monitoring_v3.types.NotificationChannelDescriptor` 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 @@ -482,10 +497,10 @@ def list_notification_channels(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.monitoring_v3.types.NotificationChannel` 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.monitoring_v3.types.NotificationChannel` 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
Loading

0 comments on commit ed958eb

Please sign in to comment.