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

Commit 173b3db

Browse files
feat: add context manager support in client (#37)
- [ ] 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 faef60d commit 173b3db

File tree

11 files changed

+110
-4
lines changed

11 files changed

+110
-4
lines changed

google/cloud/network_security_v1beta1/services/network_security/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,12 @@ async def delete_client_tls_policy(
15771577
# Done; return the response.
15781578
return response
15791579

1580+
async def __aenter__(self):
1581+
return self
1582+
1583+
async def __aexit__(self, exc_type, exc, tb):
1584+
await self.transport.close()
1585+
15801586

15811587
try:
15821588
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/network_security_v1beta1/services/network_security/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,7 @@ def __init__(
402402
client_cert_source_for_mtls=client_cert_source_func,
403403
quota_project_id=client_options.quota_project_id,
404404
client_info=client_info,
405-
always_use_jwt_access=(
406-
Transport == type(self).get_transport_class("grpc")
407-
or Transport == type(self).get_transport_class("grpc_asyncio")
408-
),
405+
always_use_jwt_access=True,
409406
)
410407

411408
def list_authorization_policies(
@@ -1818,6 +1815,19 @@ def delete_client_tls_policy(
18181815
# Done; return the response.
18191816
return response
18201817

1818+
def __enter__(self):
1819+
return self
1820+
1821+
def __exit__(self, type, value, traceback):
1822+
"""Releases underlying transport's resources.
1823+
1824+
.. warning::
1825+
ONLY use as a context manager if the transport is NOT shared
1826+
with other clients! Exiting the with block will CLOSE the transport
1827+
and may cause errors in other clients!
1828+
"""
1829+
self.transport.close()
1830+
18211831

18221832
try:
18231833
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/network_security_v1beta1/services/network_security/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ def _prep_wrapped_messages(self, client_info):
244244
),
245245
}
246246

247+
def close(self):
248+
"""Closes resources associated with the transport.
249+
250+
.. warning::
251+
Only call this method if the transport is NOT shared
252+
with other clients - this may cause errors in other clients!
253+
"""
254+
raise NotImplementedError()
255+
247256
@property
248257
def operations_client(self) -> operations_v1.OperationsClient:
249258
"""Return the client designed to process long-running operations."""

google/cloud/network_security_v1beta1/services/network_security/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,5 +685,8 @@ def delete_client_tls_policy(
685685
)
686686
return self._stubs["delete_client_tls_policy"]
687687

688+
def close(self):
689+
self.grpc_channel.close()
690+
688691

689692
__all__ = ("NetworkSecurityGrpcTransport",)

google/cloud/network_security_v1beta1/services/network_security/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,8 @@ def delete_client_tls_policy(
698698
)
699699
return self._stubs["delete_client_tls_policy"]
700700

701+
def close(self):
702+
return self.grpc_channel.close()
703+
701704

702705
__all__ = ("NetworkSecurityGrpcAsyncIOTransport",)

google/cloud/network_security_v1beta1/types/authorization_policy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Action(proto.Enum):
7777

7878
class Rule(proto.Message):
7979
r"""Specification of rules.
80+
8081
Attributes:
8182
sources (Sequence[google.cloud.network_security_v1beta1.types.AuthorizationPolicy.Rule.Source]):
8283
Optional. List of attributes for the traffic source. All of
@@ -96,6 +97,7 @@ class Rule(proto.Message):
9697

9798
class Source(proto.Message):
9899
r"""Specification of traffic source attributes.
100+
99101
Attributes:
100102
principals (Sequence[str]):
101103
Optional. List of peer identities to match for
@@ -115,6 +117,7 @@ class Source(proto.Message):
115117

116118
class Destination(proto.Message):
117119
r"""Specification of traffic destination attributes.
120+
118121
Attributes:
119122
hosts (Sequence[str]):
120123
Required. List of host names to match. Matched against HOST
@@ -138,6 +141,7 @@ class Destination(proto.Message):
138141

139142
class HttpHeaderMatch(proto.Message):
140143
r"""Specification of HTTP header match atrributes.
144+
141145
Attributes:
142146
regex_match (str):
143147
Required. The value of the header must match
@@ -186,6 +190,7 @@ class HttpHeaderMatch(proto.Message):
186190

187191
class ListAuthorizationPoliciesRequest(proto.Message):
188192
r"""Request used with the ListAuthorizationPolicies method.
193+
189194
Attributes:
190195
parent (str):
191196
Required. The project and location from which the
@@ -209,6 +214,7 @@ class ListAuthorizationPoliciesRequest(proto.Message):
209214

210215
class ListAuthorizationPoliciesResponse(proto.Message):
211216
r"""Response returned by the ListAuthorizationPolicies method.
217+
212218
Attributes:
213219
authorization_policies (Sequence[google.cloud.network_security_v1beta1.types.AuthorizationPolicy]):
214220
List of AuthorizationPolicies resources.
@@ -231,6 +237,7 @@ def raw_page(self):
231237

232238
class GetAuthorizationPolicyRequest(proto.Message):
233239
r"""Request used by the GetAuthorizationPolicy method.
240+
234241
Attributes:
235242
name (str):
236243
Required. A name of the AuthorizationPolicy to get. Must be
@@ -243,6 +250,7 @@ class GetAuthorizationPolicyRequest(proto.Message):
243250

244251
class CreateAuthorizationPolicyRequest(proto.Message):
245252
r"""Request used by the CreateAuthorizationPolicy method.
253+
246254
Attributes:
247255
parent (str):
248256
Required. The parent resource of the AuthorizationPolicy.
@@ -267,6 +275,7 @@ class CreateAuthorizationPolicyRequest(proto.Message):
267275

268276
class UpdateAuthorizationPolicyRequest(proto.Message):
269277
r"""Request used by the UpdateAuthorizationPolicy method.
278+
270279
Attributes:
271280
update_mask (google.protobuf.field_mask_pb2.FieldMask):
272281
Optional. Field mask is used to specify the fields to be
@@ -290,6 +299,7 @@ class UpdateAuthorizationPolicyRequest(proto.Message):
290299

291300
class DeleteAuthorizationPolicyRequest(proto.Message):
292301
r"""Request used by the DeleteAuthorizationPolicy method.
302+
293303
Attributes:
294304
name (str):
295305
Required. A name of the AuthorizationPolicy to delete. Must

google/cloud/network_security_v1beta1/types/client_tls_policy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ClientTlsPolicy(proto.Message):
8989

9090
class ListClientTlsPoliciesRequest(proto.Message):
9191
r"""Request used by the ListClientTlsPolicies method.
92+
9293
Attributes:
9394
parent (str):
9495
Required. The project and location from which the
@@ -111,6 +112,7 @@ class ListClientTlsPoliciesRequest(proto.Message):
111112

112113
class ListClientTlsPoliciesResponse(proto.Message):
113114
r"""Response returned by the ListClientTlsPolicies method.
115+
114116
Attributes:
115117
client_tls_policies (Sequence[google.cloud.network_security_v1beta1.types.ClientTlsPolicy]):
116118
List of ClientTlsPolicy resources.
@@ -133,6 +135,7 @@ def raw_page(self):
133135

134136
class GetClientTlsPolicyRequest(proto.Message):
135137
r"""Request used by the GetClientTlsPolicy method.
138+
136139
Attributes:
137140
name (str):
138141
Required. A name of the ClientTlsPolicy to get. Must be in
@@ -145,6 +148,7 @@ class GetClientTlsPolicyRequest(proto.Message):
145148

146149
class CreateClientTlsPolicyRequest(proto.Message):
147150
r"""Request used by the CreateClientTlsPolicy method.
151+
148152
Attributes:
149153
parent (str):
150154
Required. The parent resource of the ClientTlsPolicy. Must
@@ -167,6 +171,7 @@ class CreateClientTlsPolicyRequest(proto.Message):
167171

168172
class UpdateClientTlsPolicyRequest(proto.Message):
169173
r"""Request used by UpdateClientTlsPolicy method.
174+
170175
Attributes:
171176
update_mask (google.protobuf.field_mask_pb2.FieldMask):
172177
Optional. Field mask is used to specify the fields to be
@@ -187,6 +192,7 @@ class UpdateClientTlsPolicyRequest(proto.Message):
187192

188193
class DeleteClientTlsPolicyRequest(proto.Message):
189194
r"""Request used by the DeleteClientTlsPolicy method.
195+
190196
Attributes:
191197
name (str):
192198
Required. A name of the ClientTlsPolicy to delete. Must be

google/cloud/network_security_v1beta1/types/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
class OperationMetadata(proto.Message):
2727
r"""Represents the metadata of the long-running operation.
28+
2829
Attributes:
2930
create_time (google.protobuf.timestamp_pb2.Timestamp):
3031
Output only. The time the operation was

google/cloud/network_security_v1beta1/types/server_tls_policy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ServerTlsPolicy(proto.Message):
8181

8282
class MTLSPolicy(proto.Message):
8383
r"""Specification of the MTLSPolicy.
84+
8485
Attributes:
8586
client_validation_ca (Sequence[google.cloud.network_security_v1beta1.types.ValidationCA]):
8687
Required. Defines the mechanism to obtain the
@@ -106,6 +107,7 @@ class MTLSPolicy(proto.Message):
106107

107108
class ListServerTlsPoliciesRequest(proto.Message):
108109
r"""Request used by the ListServerTlsPolicies method.
110+
109111
Attributes:
110112
parent (str):
111113
Required. The project and location from which the
@@ -128,6 +130,7 @@ class ListServerTlsPoliciesRequest(proto.Message):
128130

129131
class ListServerTlsPoliciesResponse(proto.Message):
130132
r"""Response returned by the ListServerTlsPolicies method.
133+
131134
Attributes:
132135
server_tls_policies (Sequence[google.cloud.network_security_v1beta1.types.ServerTlsPolicy]):
133136
List of ServerTlsPolicy resources.
@@ -150,6 +153,7 @@ def raw_page(self):
150153

151154
class GetServerTlsPolicyRequest(proto.Message):
152155
r"""Request used by the GetServerTlsPolicy method.
156+
153157
Attributes:
154158
name (str):
155159
Required. A name of the ServerTlsPolicy to get. Must be in
@@ -162,6 +166,7 @@ class GetServerTlsPolicyRequest(proto.Message):
162166

163167
class CreateServerTlsPolicyRequest(proto.Message):
164168
r"""Request used by the CreateServerTlsPolicy method.
169+
165170
Attributes:
166171
parent (str):
167172
Required. The parent resource of the ServerTlsPolicy. Must
@@ -184,6 +189,7 @@ class CreateServerTlsPolicyRequest(proto.Message):
184189

185190
class UpdateServerTlsPolicyRequest(proto.Message):
186191
r"""Request used by UpdateServerTlsPolicy method.
192+
187193
Attributes:
188194
update_mask (google.protobuf.field_mask_pb2.FieldMask):
189195
Optional. Field mask is used to specify the fields to be
@@ -204,6 +210,7 @@ class UpdateServerTlsPolicyRequest(proto.Message):
204210

205211
class DeleteServerTlsPolicyRequest(proto.Message):
206212
r"""Request used by the DeleteServerTlsPolicy method.
213+
207214
Attributes:
208215
name (str):
209216
Required. A name of the ServerTlsPolicy to delete. Must be

google/cloud/network_security_v1beta1/types/tls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
class GrpcEndpoint(proto.Message):
3131
r"""Specification of the GRPC Endpoint.
32+
3233
Attributes:
3334
target_uri (str):
3435
Required. The target URI of the gRPC

0 commit comments

Comments
 (0)