Skip to content

Commit

Permalink
feat: add common resource helper methods; expose client transport (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Dec 24, 2020
1 parent 298150a commit 1a6068e
Show file tree
Hide file tree
Showing 11 changed files with 1,003 additions and 460 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Types for Google Monitoring Dashboard v1 API

.. automodule:: google.cloud.monitoring_dashboard_v1.types
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from google.cloud.monitoring_dashboard_v1.types import dashboards_service
from google.cloud.monitoring_dashboard_v1.types import layouts

from .transports.base import DashboardsServiceTransport
from .transports.base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import DashboardsServiceGrpcAsyncIOTransport
from .client import DashboardsServiceClient

Expand All @@ -49,10 +49,49 @@ class DashboardsServiceAsyncClient:
DEFAULT_MTLS_ENDPOINT = DashboardsServiceClient.DEFAULT_MTLS_ENDPOINT

dashboard_path = staticmethod(DashboardsServiceClient.dashboard_path)
parse_dashboard_path = staticmethod(DashboardsServiceClient.parse_dashboard_path)

common_billing_account_path = staticmethod(
DashboardsServiceClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
DashboardsServiceClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(DashboardsServiceClient.common_folder_path)
parse_common_folder_path = staticmethod(
DashboardsServiceClient.parse_common_folder_path
)

common_organization_path = staticmethod(
DashboardsServiceClient.common_organization_path
)
parse_common_organization_path = staticmethod(
DashboardsServiceClient.parse_common_organization_path
)

common_project_path = staticmethod(DashboardsServiceClient.common_project_path)
parse_common_project_path = staticmethod(
DashboardsServiceClient.parse_common_project_path
)

common_location_path = staticmethod(DashboardsServiceClient.common_location_path)
parse_common_location_path = staticmethod(
DashboardsServiceClient.parse_common_location_path
)

from_service_account_file = DashboardsServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> DashboardsServiceTransport:
"""Return the transport used by the client instance.
Returns:
DashboardsServiceTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(DashboardsServiceClient).get_transport_class, type(DashboardsServiceClient)
)
Expand All @@ -63,6 +102,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, DashboardsServiceTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the dashboards service client.
Expand All @@ -78,24 +118,30 @@ def __init__(
client_options (ClientOptions): Custom options for the client. It
won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
default endpoint provided by the client. GOOGLE_API_USE_MTLS
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
"always" (always use the default mTLS endpoint), "never" (always
use the default regular endpoint, this is the default value for
the environment variable) and "auto" (auto switch to the default
mTLS endpoint if client SSL credentials is present). However,
the ``api_endpoint`` property takes precedence if provided.
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
use the default regular endpoint) and "auto" (auto switch to the
default mTLS endpoint if client certificate is present, this is
the default value). However, the ``api_endpoint`` property takes
precedence if provided.
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
is "true", then the ``client_cert_source`` property can be used
to provide client certificate for mutual TLS transport. If
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
creation failed for any reason.
"""

self._client = DashboardsServiceClient(
credentials=credentials, transport=transport, client_options=client_options,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def create_dashboard(
Expand Down Expand Up @@ -139,7 +185,7 @@ async def create_dashboard(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_dashboard,
default_timeout=30.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -195,7 +241,7 @@ async def list_dashboards(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_dashboards,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -257,7 +303,7 @@ async def get_dashboard(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_dashboard,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -305,7 +351,7 @@ async def delete_dashboard(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.delete_dashboard,
default_timeout=30.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand Down Expand Up @@ -360,7 +406,7 @@ async def update_dashboard(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.update_dashboard,
default_timeout=30.0,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
Expand All @@ -379,13 +425,13 @@ async def update_dashboard(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-monitoring-dashboard",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("DashboardsServiceAsyncClient",)
Loading

0 comments on commit 1a6068e

Please sign in to comment.