Skip to content

Commit 1a6068e

Browse files
feat: add common resource helper methods; expose client transport (#34)
1 parent 298150a commit 1a6068e

File tree

11 files changed

+1003
-460
lines changed

11 files changed

+1003
-460
lines changed

packages/google-cloud-monitoring-dashboards/docs/dashboard_v1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Monitoring Dashboard v1 API
33

44
.. automodule:: google.cloud.monitoring_dashboard_v1.types
55
:members:
6+
:show-inheritance:

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/async_client.py

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from google.cloud.monitoring_dashboard_v1.types import dashboards_service
3434
from google.cloud.monitoring_dashboard_v1.types import layouts
3535

36-
from .transports.base import DashboardsServiceTransport
36+
from .transports.base import DashboardsServiceTransport, DEFAULT_CLIENT_INFO
3737
from .transports.grpc_asyncio import DashboardsServiceGrpcAsyncIOTransport
3838
from .client import DashboardsServiceClient
3939

@@ -49,10 +49,49 @@ class DashboardsServiceAsyncClient:
4949
DEFAULT_MTLS_ENDPOINT = DashboardsServiceClient.DEFAULT_MTLS_ENDPOINT
5050

5151
dashboard_path = staticmethod(DashboardsServiceClient.dashboard_path)
52+
parse_dashboard_path = staticmethod(DashboardsServiceClient.parse_dashboard_path)
53+
54+
common_billing_account_path = staticmethod(
55+
DashboardsServiceClient.common_billing_account_path
56+
)
57+
parse_common_billing_account_path = staticmethod(
58+
DashboardsServiceClient.parse_common_billing_account_path
59+
)
60+
61+
common_folder_path = staticmethod(DashboardsServiceClient.common_folder_path)
62+
parse_common_folder_path = staticmethod(
63+
DashboardsServiceClient.parse_common_folder_path
64+
)
65+
66+
common_organization_path = staticmethod(
67+
DashboardsServiceClient.common_organization_path
68+
)
69+
parse_common_organization_path = staticmethod(
70+
DashboardsServiceClient.parse_common_organization_path
71+
)
72+
73+
common_project_path = staticmethod(DashboardsServiceClient.common_project_path)
74+
parse_common_project_path = staticmethod(
75+
DashboardsServiceClient.parse_common_project_path
76+
)
77+
78+
common_location_path = staticmethod(DashboardsServiceClient.common_location_path)
79+
parse_common_location_path = staticmethod(
80+
DashboardsServiceClient.parse_common_location_path
81+
)
5282

5383
from_service_account_file = DashboardsServiceClient.from_service_account_file
5484
from_service_account_json = from_service_account_file
5585

86+
@property
87+
def transport(self) -> DashboardsServiceTransport:
88+
"""Return the transport used by the client instance.
89+
90+
Returns:
91+
DashboardsServiceTransport: The transport used by the client instance.
92+
"""
93+
return self._client.transport
94+
5695
get_transport_class = functools.partial(
5796
type(DashboardsServiceClient).get_transport_class, type(DashboardsServiceClient)
5897
)
@@ -63,6 +102,7 @@ def __init__(
63102
credentials: credentials.Credentials = None,
64103
transport: Union[str, DashboardsServiceTransport] = "grpc_asyncio",
65104
client_options: ClientOptions = None,
105+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
66106
) -> None:
67107
"""Instantiate the dashboards service client.
68108
@@ -78,24 +118,30 @@ def __init__(
78118
client_options (ClientOptions): Custom options for the client. It
79119
won't take effect if a ``transport`` instance is provided.
80120
(1) The ``api_endpoint`` property can be used to override the
81-
default endpoint provided by the client. GOOGLE_API_USE_MTLS
121+
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
82122
environment variable can also be used to override the endpoint:
83123
"always" (always use the default mTLS endpoint), "never" (always
84-
use the default regular endpoint, this is the default value for
85-
the environment variable) and "auto" (auto switch to the default
86-
mTLS endpoint if client SSL credentials is present). However,
87-
the ``api_endpoint`` property takes precedence if provided.
88-
(2) The ``client_cert_source`` property is used to provide client
89-
SSL credentials for mutual TLS transport. If not provided, the
90-
default SSL credentials will be used if present.
124+
use the default regular endpoint) and "auto" (auto switch to the
125+
default mTLS endpoint if client certificate is present, this is
126+
the default value). However, the ``api_endpoint`` property takes
127+
precedence if provided.
128+
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
129+
is "true", then the ``client_cert_source`` property can be used
130+
to provide client certificate for mutual TLS transport. If
131+
not provided, the default SSL client certificate will be used if
132+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
133+
set, no client certificate will be used.
91134
92135
Raises:
93136
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
94137
creation failed for any reason.
95138
"""
96139

97140
self._client = DashboardsServiceClient(
98-
credentials=credentials, transport=transport, client_options=client_options,
141+
credentials=credentials,
142+
transport=transport,
143+
client_options=client_options,
144+
client_info=client_info,
99145
)
100146

101147
async def create_dashboard(
@@ -139,7 +185,7 @@ async def create_dashboard(
139185
rpc = gapic_v1.method_async.wrap_method(
140186
self._client._transport.create_dashboard,
141187
default_timeout=30.0,
142-
client_info=_client_info,
188+
client_info=DEFAULT_CLIENT_INFO,
143189
)
144190

145191
# Certain fields should be provided within the metadata header;
@@ -195,7 +241,7 @@ async def list_dashboards(
195241
rpc = gapic_v1.method_async.wrap_method(
196242
self._client._transport.list_dashboards,
197243
default_timeout=None,
198-
client_info=_client_info,
244+
client_info=DEFAULT_CLIENT_INFO,
199245
)
200246

201247
# Certain fields should be provided within the metadata header;
@@ -257,7 +303,7 @@ async def get_dashboard(
257303
rpc = gapic_v1.method_async.wrap_method(
258304
self._client._transport.get_dashboard,
259305
default_timeout=None,
260-
client_info=_client_info,
306+
client_info=DEFAULT_CLIENT_INFO,
261307
)
262308

263309
# Certain fields should be provided within the metadata header;
@@ -305,7 +351,7 @@ async def delete_dashboard(
305351
rpc = gapic_v1.method_async.wrap_method(
306352
self._client._transport.delete_dashboard,
307353
default_timeout=30.0,
308-
client_info=_client_info,
354+
client_info=DEFAULT_CLIENT_INFO,
309355
)
310356

311357
# Certain fields should be provided within the metadata header;
@@ -360,7 +406,7 @@ async def update_dashboard(
360406
rpc = gapic_v1.method_async.wrap_method(
361407
self._client._transport.update_dashboard,
362408
default_timeout=30.0,
363-
client_info=_client_info,
409+
client_info=DEFAULT_CLIENT_INFO,
364410
)
365411

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

380426

381427
try:
382-
_client_info = gapic_v1.client_info.ClientInfo(
428+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
383429
gapic_version=pkg_resources.get_distribution(
384430
"google-monitoring-dashboard",
385431
).version,
386432
)
387433
except pkg_resources.DistributionNotFound:
388-
_client_info = gapic_v1.client_info.ClientInfo()
434+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
389435

390436

391437
__all__ = ("DashboardsServiceAsyncClient",)

0 commit comments

Comments
 (0)