Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit acf8bb2

Browse files
feat: add context manager support in client (#102)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 09d1443 commit acf8bb2

12 files changed

Lines changed: 121 additions & 4 deletions

File tree

google/cloud/channel_v1/services/cloud_channel_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,12 @@ async def list_subscribers(
28572857
# Done; return the response.
28582858
return response
28592859

2860+
async def __aenter__(self):
2861+
return self
2862+
2863+
async def __aexit__(self, exc_type, exc, tb):
2864+
await self.transport.close()
2865+
28602866

28612867
try:
28622868
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/channel_v1/services/cloud_channel_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,7 @@ def __init__(
427427
client_cert_source_for_mtls=client_cert_source_func,
428428
quota_project_id=client_options.quota_project_id,
429429
client_info=client_info,
430-
always_use_jwt_access=(
431-
Transport == type(self).get_transport_class("grpc")
432-
or Transport == type(self).get_transport_class("grpc_asyncio")
433-
),
430+
always_use_jwt_access=True,
434431
)
435432

436433
def list_customers(
@@ -3126,6 +3123,19 @@ def list_subscribers(
31263123
# Done; return the response.
31273124
return response
31283125

3126+
def __enter__(self):
3127+
return self
3128+
3129+
def __exit__(self, type, value, traceback):
3130+
"""Releases underlying transport's resources.
3131+
3132+
.. warning::
3133+
ONLY use as a context manager if the transport is NOT shared
3134+
with other clients! Exiting the with block will CLOSE the transport
3135+
and may cause errors in other clients!
3136+
"""
3137+
self.transport.close()
3138+
31293139

31303140
try:
31313141
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/channel_v1/services/cloud_channel_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ def _prep_wrapped_messages(self, client_info):
296296
),
297297
}
298298

299+
def close(self):
300+
"""Closes resources associated with the transport.
301+
302+
.. warning::
303+
Only call this method if the transport is NOT shared
304+
with other clients - this may cause errors in other clients!
305+
"""
306+
raise NotImplementedError()
307+
299308
@property
300309
def operations_client(self) -> operations_v1.OperationsClient:
301310
"""Return the client designed to process long-running operations."""

google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,5 +1866,8 @@ def list_subscribers(
18661866
)
18671867
return self._stubs["list_subscribers"]
18681868

1869+
def close(self):
1870+
self.grpc_channel.close()
1871+
18691872

18701873
__all__ = ("CloudChannelServiceGrpcTransport",)

google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,5 +1907,8 @@ def list_subscribers(
19071907
)
19081908
return self._stubs["list_subscribers"]
19091909

1910+
def close(self):
1911+
return self.grpc_channel.close()
1912+
19101913

19111914
__all__ = ("CloudChannelServiceGrpcAsyncIOTransport",)

google/cloud/channel_v1/types/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
class EduData(proto.Message):
2828
r"""Required Edu Attributes
29+
2930
Attributes:
3031
institute_type (google.cloud.channel_v1.types.EduData.InstituteType):
3132
Designated institute type of customer.
@@ -60,6 +61,7 @@ class InstituteSize(proto.Enum):
6061

6162
class CloudIdentityInfo(proto.Message):
6263
r"""Cloud Identity information for the Cloud Channel Customer.
64+
6365
Attributes:
6466
customer_type (google.cloud.channel_v1.types.CloudIdentityInfo.CustomerType):
6567
CustomerType indicates verification type
@@ -105,6 +107,7 @@ class CustomerType(proto.Enum):
105107

106108
class Value(proto.Message):
107109
r"""Data type and value of a parameter.
110+
108111
Attributes:
109112
int64_value (int):
110113
Represents an int64 value.

google/cloud/channel_v1/types/customers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
class Customer(proto.Message):
2929
r"""Entity representing a customer of a reseller or distributor.
30+
3031
Attributes:
3132
name (str):
3233
Output only. Resource name of the customer. Format:
@@ -98,6 +99,7 @@ class Customer(proto.Message):
9899

99100
class ContactInfo(proto.Message):
100101
r"""Contact information for a customer account.
102+
101103
Attributes:
102104
first_name (str):
103105
The customer account contact's first name.

google/cloud/channel_v1/types/entitlements.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class SuspensionReason(proto.Enum):
126126

127127
class Parameter(proto.Message):
128128
r"""Definition for extended entitlement parameters.
129+
129130
Attributes:
130131
name (str):
131132
Name of the parameter.
@@ -158,6 +159,7 @@ class AssociationInfo(proto.Message):
158159

159160
class ProvisionedService(proto.Message):
160161
r"""Service provisioned for an entitlement.
162+
161163
Attributes:
162164
provisioning_id (str):
163165
Output only. Provisioning ID of the
@@ -178,6 +180,7 @@ class ProvisionedService(proto.Message):
178180

179181
class CommitmentSettings(proto.Message):
180182
r"""Commitment settings for commitment-based offers.
183+
181184
Attributes:
182185
start_time (google.protobuf.timestamp_pb2.Timestamp):
183186
Output only. Commitment start timestamp.
@@ -195,6 +198,7 @@ class CommitmentSettings(proto.Message):
195198

196199
class RenewalSettings(proto.Message):
197200
r"""Renewal settings for renewable Offers.
201+
198202
Attributes:
199203
enable_renewal (bool):
200204
If false, the plan will be completed at the
@@ -218,6 +222,7 @@ class RenewalSettings(proto.Message):
218222

219223
class TrialSettings(proto.Message):
220224
r"""Settings for trial offers.
225+
221226
Attributes:
222227
trial (bool):
223228
Determines if the entitlement is in a trial or not:
@@ -259,6 +264,7 @@ class TransferableSku(proto.Message):
259264

260265
class TransferEligibility(proto.Message):
261266
r"""Specifies transfer eligibility of a SKU.
267+
262268
Attributes:
263269
is_eligible (bool):
264270
Whether reseller is eligible to transfer the

google/cloud/channel_v1/types/offers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class ParameterType(proto.Enum):
185185

186186
class Constraints(proto.Message):
187187
r"""Represents the constraints for buying the Offer.
188+
188189
Attributes:
189190
customer_constraints (google.cloud.channel_v1.types.CustomerConstraints):
190191
Represents constraints required to purchase
@@ -255,6 +256,7 @@ class Plan(proto.Message):
255256

256257
class PriceByResource(proto.Message):
257258
r"""Represents price by resource type.
259+
258260
Attributes:
259261
resource_type (google.cloud.channel_v1.types.ResourceType):
260262
Resource Type. Example: SEAT
@@ -272,6 +274,7 @@ class PriceByResource(proto.Message):
272274

273275
class Price(proto.Message):
274276
r"""Represents the price of the Offer.
277+
275278
Attributes:
276279
base_price (google.type.money_pb2.Money):
277280
Base price.
@@ -346,6 +349,7 @@ class PriceTier(proto.Message):
346349

347350
class Period(proto.Message):
348351
r"""Represents period in days/months/years.
352+
349353
Attributes:
350354
duration (int):
351355
Total duration of Period Type defined.

google/cloud/channel_v1/types/products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class MarketingInfo(proto.Message):
8585

8686
class Media(proto.Message):
8787
r"""Represents media information.
88+
8889
Attributes:
8990
title (str):
9091
Title of the media.

0 commit comments

Comments
 (0)