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

File tree

12 files changed

+121
-4
lines changed

12 files changed

+121
-4
lines changed

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

+6
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

+14-4
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

+9
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

+3
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

+3
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

+3
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

+2
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

+6
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

+4
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

+1
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.

google/cloud/channel_v1/types/service.py

+20
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ class TransferEntitlementsToGoogleRequest(proto.Message):
825825

826826
class ChangeParametersRequest(proto.Message):
827827
r"""Request message for [CloudChannelService.ChangeParametersRequest][].
828+
828829
Attributes:
829830
name (str):
830831
Required. The name of the entitlement to update. Name uses
@@ -1062,6 +1063,7 @@ class ActivateEntitlementRequest(proto.Message):
10621063

10631064
class LookupOfferRequest(proto.Message):
10641065
r"""Request message for LookupOffer.
1066+
10651067
Attributes:
10661068
entitlement (str):
10671069
Required. The resource name of the entitlement to retrieve
@@ -1074,6 +1076,7 @@ class LookupOfferRequest(proto.Message):
10741076

10751077
class ListProductsRequest(proto.Message):
10761078
r"""Request message for ListProducts.
1079+
10771080
Attributes:
10781081
account (str):
10791082
Required. The resource name of the reseller account. Format:
@@ -1102,6 +1105,7 @@ class ListProductsRequest(proto.Message):
11021105

11031106
class ListProductsResponse(proto.Message):
11041107
r"""Response message for ListProducts.
1108+
11051109
Attributes:
11061110
products (Sequence[google.cloud.channel_v1.types.Product]):
11071111
List of Products requested.
@@ -1121,6 +1125,7 @@ def raw_page(self):
11211125

11221126
class ListSkusRequest(proto.Message):
11231127
r"""Request message for ListSkus.
1128+
11241129
Attributes:
11251130
parent (str):
11261131
Required. The resource name of the Product to list SKUs for.
@@ -1154,6 +1159,7 @@ class ListSkusRequest(proto.Message):
11541159

11551160
class ListSkusResponse(proto.Message):
11561161
r"""Response message for ListSkus.
1162+
11571163
Attributes:
11581164
skus (Sequence[google.cloud.channel_v1.types.Sku]):
11591165
The list of SKUs requested.
@@ -1171,6 +1177,7 @@ def raw_page(self):
11711177

11721178
class ListOffersRequest(proto.Message):
11731179
r"""Request message for ListOffers.
1180+
11741181
Attributes:
11751182
parent (str):
11761183
Required. The resource name of the reseller account from
@@ -1208,6 +1215,7 @@ class ListOffersRequest(proto.Message):
12081215

12091216
class ListOffersResponse(proto.Message):
12101217
r"""Response message for ListOffers.
1218+
12111219
Attributes:
12121220
offers (Sequence[google.cloud.channel_v1.types.Offer]):
12131221
The list of Offers requested.
@@ -1225,6 +1233,7 @@ def raw_page(self):
12251233

12261234
class ListPurchasableSkusRequest(proto.Message):
12271235
r"""Request message for ListPurchasableSkus.
1236+
12281237
Attributes:
12291238
create_entitlement_purchase (google.cloud.channel_v1.types.ListPurchasableSkusRequest.CreateEntitlementPurchase):
12301239
List SKUs for CreateEntitlement purchase.
@@ -1306,6 +1315,7 @@ class ChangeType(proto.Enum):
13061315

13071316
class ListPurchasableSkusResponse(proto.Message):
13081317
r"""Response message for ListPurchasableSkus.
1318+
13091319
Attributes:
13101320
purchasable_skus (Sequence[google.cloud.channel_v1.types.PurchasableSku]):
13111321
The list of SKUs requested.
@@ -1337,6 +1347,7 @@ class PurchasableSku(proto.Message):
13371347

13381348
class ListPurchasableOffersRequest(proto.Message):
13391349
r"""Request message for ListPurchasableOffers.
1350+
13401351
Attributes:
13411352
create_entitlement_purchase (google.cloud.channel_v1.types.ListPurchasableOffersRequest.CreateEntitlementPurchase):
13421353
List Offers for CreateEntitlement purchase.
@@ -1363,6 +1374,7 @@ class ListPurchasableOffersRequest(proto.Message):
13631374

13641375
class CreateEntitlementPurchase(proto.Message):
13651376
r"""List Offers for CreateEntitlement purchase.
1377+
13661378
Attributes:
13671379
sku (str):
13681380
Required. SKU that the result should be restricted to.
@@ -1373,6 +1385,7 @@ class CreateEntitlementPurchase(proto.Message):
13731385

13741386
class ChangeOfferPurchase(proto.Message):
13751387
r"""List Offers for ChangeOffer purchase.
1388+
13761389
Attributes:
13771390
entitlement (str):
13781391
Required. Resource name of the entitlement. Format:
@@ -1403,6 +1416,7 @@ class ChangeOfferPurchase(proto.Message):
14031416

14041417
class ListPurchasableOffersResponse(proto.Message):
14051418
r"""Response message for ListPurchasableOffers.
1419+
14061420
Attributes:
14071421
purchasable_offers (Sequence[google.cloud.channel_v1.types.PurchasableOffer]):
14081422
The list of Offers requested.
@@ -1434,6 +1448,7 @@ class PurchasableOffer(proto.Message):
14341448

14351449
class RegisterSubscriberRequest(proto.Message):
14361450
r"""Request Message for RegisterSubscriber.
1451+
14371452
Attributes:
14381453
account (str):
14391454
Required. Resource name of the account.
@@ -1448,6 +1463,7 @@ class RegisterSubscriberRequest(proto.Message):
14481463

14491464
class RegisterSubscriberResponse(proto.Message):
14501465
r"""Response Message for RegisterSubscriber.
1466+
14511467
Attributes:
14521468
topic (str):
14531469
Name of the topic the subscriber will listen
@@ -1459,6 +1475,7 @@ class RegisterSubscriberResponse(proto.Message):
14591475

14601476
class UnregisterSubscriberRequest(proto.Message):
14611477
r"""Request Message for UnregisterSubscriber.
1478+
14621479
Attributes:
14631480
account (str):
14641481
Required. Resource name of the account.
@@ -1473,6 +1490,7 @@ class UnregisterSubscriberRequest(proto.Message):
14731490

14741491
class UnregisterSubscriberResponse(proto.Message):
14751492
r"""Response Message for UnregisterSubscriber.
1493+
14761494
Attributes:
14771495
topic (str):
14781496
Name of the topic the service account
@@ -1484,6 +1502,7 @@ class UnregisterSubscriberResponse(proto.Message):
14841502

14851503
class ListSubscribersRequest(proto.Message):
14861504
r"""Request Message for ListSubscribers.
1505+
14871506
Attributes:
14881507
account (str):
14891508
Required. Resource name of the account.
@@ -1510,6 +1529,7 @@ class ListSubscribersRequest(proto.Message):
15101529

15111530
class ListSubscribersResponse(proto.Message):
15121531
r"""Response Message for ListSubscribers.
1532+
15131533
Attributes:
15141534
topic (str):
15151535
Name of the topic registered with the

0 commit comments

Comments
 (0)