google-cloud-modelarmor 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. google/cloud/modelarmor/__init__.py +117 -0
  2. google/cloud/modelarmor/gapic_version.py +16 -0
  3. google/cloud/modelarmor/py.typed +2 -0
  4. google/cloud/modelarmor_v1/__init__.py +114 -0
  5. google/cloud/modelarmor_v1/gapic_metadata.json +163 -0
  6. google/cloud/modelarmor_v1/gapic_version.py +16 -0
  7. google/cloud/modelarmor_v1/py.typed +2 -0
  8. google/cloud/modelarmor_v1/services/__init__.py +15 -0
  9. google/cloud/modelarmor_v1/services/model_armor/__init__.py +22 -0
  10. google/cloud/modelarmor_v1/services/model_armor/async_client.py +1377 -0
  11. google/cloud/modelarmor_v1/services/model_armor/client.py +1772 -0
  12. google/cloud/modelarmor_v1/services/model_armor/pagers.py +197 -0
  13. google/cloud/modelarmor_v1/services/model_armor/transports/__init__.py +36 -0
  14. google/cloud/modelarmor_v1/services/model_armor/transports/base.py +357 -0
  15. google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py +607 -0
  16. google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py +730 -0
  17. google/cloud/modelarmor_v1/services/model_armor/transports/rest.py +2143 -0
  18. google/cloud/modelarmor_v1/services/model_armor/transports/rest_base.py +638 -0
  19. google/cloud/modelarmor_v1/types/__init__.py +106 -0
  20. google/cloud/modelarmor_v1/types/service.py +1881 -0
  21. google_cloud_modelarmor-0.1.0.dist-info/LICENSE +202 -0
  22. google_cloud_modelarmor-0.1.0.dist-info/METADATA +139 -0
  23. google_cloud_modelarmor-0.1.0.dist-info/RECORD +25 -0
  24. google_cloud_modelarmor-0.1.0.dist-info/WHEEL +5 -0
  25. google_cloud_modelarmor-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,730 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ import inspect
17
+ import json
18
+ import logging as std_logging
19
+ import pickle
20
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
21
+ import warnings
22
+
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import gapic_v1, grpc_helpers_async
25
+ from google.api_core import retry_async as retries
26
+ from google.auth import credentials as ga_credentials # type: ignore
27
+ from google.auth.transport.grpc import SslCredentials # type: ignore
28
+ from google.cloud.location import locations_pb2 # type: ignore
29
+ from google.protobuf import empty_pb2 # type: ignore
30
+ from google.protobuf.json_format import MessageToJson
31
+ import google.protobuf.message
32
+ import grpc # type: ignore
33
+ from grpc.experimental import aio # type: ignore
34
+ import proto # type: ignore
35
+
36
+ from google.cloud.modelarmor_v1.types import service
37
+
38
+ from .base import DEFAULT_CLIENT_INFO, ModelArmorTransport
39
+ from .grpc import ModelArmorGrpcTransport
40
+
41
+ try:
42
+ from google.api_core import client_logging # type: ignore
43
+
44
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
45
+ except ImportError: # pragma: NO COVER
46
+ CLIENT_LOGGING_SUPPORTED = False
47
+
48
+ _LOGGER = std_logging.getLogger(__name__)
49
+
50
+
51
+ class _LoggingClientAIOInterceptor(
52
+ grpc.aio.UnaryUnaryClientInterceptor
53
+ ): # pragma: NO COVER
54
+ async def intercept_unary_unary(self, continuation, client_call_details, request):
55
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
56
+ std_logging.DEBUG
57
+ )
58
+ if logging_enabled: # pragma: NO COVER
59
+ request_metadata = client_call_details.metadata
60
+ if isinstance(request, proto.Message):
61
+ request_payload = type(request).to_json(request)
62
+ elif isinstance(request, google.protobuf.message.Message):
63
+ request_payload = MessageToJson(request)
64
+ else:
65
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
66
+
67
+ request_metadata = {
68
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
69
+ for key, value in request_metadata
70
+ }
71
+ grpc_request = {
72
+ "payload": request_payload,
73
+ "requestMethod": "grpc",
74
+ "metadata": dict(request_metadata),
75
+ }
76
+ _LOGGER.debug(
77
+ f"Sending request for {client_call_details.method}",
78
+ extra={
79
+ "serviceName": "google.cloud.modelarmor.v1.ModelArmor",
80
+ "rpcName": str(client_call_details.method),
81
+ "request": grpc_request,
82
+ "metadata": grpc_request["metadata"],
83
+ },
84
+ )
85
+ response = await continuation(client_call_details, request)
86
+ if logging_enabled: # pragma: NO COVER
87
+ response_metadata = await response.trailing_metadata()
88
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
89
+ metadata = (
90
+ dict([(k, str(v)) for k, v in response_metadata])
91
+ if response_metadata
92
+ else None
93
+ )
94
+ result = await response
95
+ if isinstance(result, proto.Message):
96
+ response_payload = type(result).to_json(result)
97
+ elif isinstance(result, google.protobuf.message.Message):
98
+ response_payload = MessageToJson(result)
99
+ else:
100
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
101
+ grpc_response = {
102
+ "payload": response_payload,
103
+ "metadata": metadata,
104
+ "status": "OK",
105
+ }
106
+ _LOGGER.debug(
107
+ f"Received response to rpc {client_call_details.method}.",
108
+ extra={
109
+ "serviceName": "google.cloud.modelarmor.v1.ModelArmor",
110
+ "rpcName": str(client_call_details.method),
111
+ "response": grpc_response,
112
+ "metadata": grpc_response["metadata"],
113
+ },
114
+ )
115
+ return response
116
+
117
+
118
+ class ModelArmorGrpcAsyncIOTransport(ModelArmorTransport):
119
+ """gRPC AsyncIO backend transport for ModelArmor.
120
+
121
+ Service describing handlers for resources
122
+
123
+ This class defines the same methods as the primary client, so the
124
+ primary client can load the underlying transport implementation
125
+ and call it.
126
+
127
+ It sends protocol buffers over the wire using gRPC (which is built on
128
+ top of HTTP/2); the ``grpcio`` package must be installed.
129
+ """
130
+
131
+ _grpc_channel: aio.Channel
132
+ _stubs: Dict[str, Callable] = {}
133
+
134
+ @classmethod
135
+ def create_channel(
136
+ cls,
137
+ host: str = "modelarmor.googleapis.com",
138
+ credentials: Optional[ga_credentials.Credentials] = None,
139
+ credentials_file: Optional[str] = None,
140
+ scopes: Optional[Sequence[str]] = None,
141
+ quota_project_id: Optional[str] = None,
142
+ **kwargs,
143
+ ) -> aio.Channel:
144
+ """Create and return a gRPC AsyncIO channel object.
145
+ Args:
146
+ host (Optional[str]): The host for the channel to use.
147
+ credentials (Optional[~.Credentials]): The
148
+ authorization credentials to attach to requests. These
149
+ credentials identify this application to the service. If
150
+ none are specified, the client will attempt to ascertain
151
+ the credentials from the environment.
152
+ credentials_file (Optional[str]): A file with credentials that can
153
+ be loaded with :func:`google.auth.load_credentials_from_file`.
154
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
155
+ service. These are only used when credentials are not specified and
156
+ are passed to :func:`google.auth.default`.
157
+ quota_project_id (Optional[str]): An optional project to use for billing
158
+ and quota.
159
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
160
+ channel creation.
161
+ Returns:
162
+ aio.Channel: A gRPC AsyncIO channel object.
163
+ """
164
+
165
+ return grpc_helpers_async.create_channel(
166
+ host,
167
+ credentials=credentials,
168
+ credentials_file=credentials_file,
169
+ quota_project_id=quota_project_id,
170
+ default_scopes=cls.AUTH_SCOPES,
171
+ scopes=scopes,
172
+ default_host=cls.DEFAULT_HOST,
173
+ **kwargs,
174
+ )
175
+
176
+ def __init__(
177
+ self,
178
+ *,
179
+ host: str = "modelarmor.googleapis.com",
180
+ credentials: Optional[ga_credentials.Credentials] = None,
181
+ credentials_file: Optional[str] = None,
182
+ scopes: Optional[Sequence[str]] = None,
183
+ channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
184
+ api_mtls_endpoint: Optional[str] = None,
185
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
186
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
187
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
188
+ quota_project_id: Optional[str] = None,
189
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
190
+ always_use_jwt_access: Optional[bool] = False,
191
+ api_audience: Optional[str] = None,
192
+ ) -> None:
193
+ """Instantiate the transport.
194
+
195
+ Args:
196
+ host (Optional[str]):
197
+ The hostname to connect to (default: 'modelarmor.googleapis.com').
198
+ credentials (Optional[google.auth.credentials.Credentials]): The
199
+ authorization credentials to attach to requests. These
200
+ credentials identify the application to the service; if none
201
+ are specified, the client will attempt to ascertain the
202
+ credentials from the environment.
203
+ This argument is ignored if a ``channel`` instance is provided.
204
+ credentials_file (Optional[str]): A file with credentials that can
205
+ be loaded with :func:`google.auth.load_credentials_from_file`.
206
+ This argument is ignored if a ``channel`` instance is provided.
207
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
208
+ service. These are only used when credentials are not specified and
209
+ are passed to :func:`google.auth.default`.
210
+ channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
211
+ A ``Channel`` instance through which to make calls, or a Callable
212
+ that constructs and returns one. If set to None, ``self.create_channel``
213
+ is used to create the channel. If a Callable is given, it will be called
214
+ with the same arguments as used in ``self.create_channel``.
215
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
216
+ If provided, it overrides the ``host`` argument and tries to create
217
+ a mutual TLS channel with client SSL credentials from
218
+ ``client_cert_source`` or application default SSL credentials.
219
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
220
+ Deprecated. A callback to provide client SSL certificate bytes and
221
+ private key bytes, both in PEM format. It is ignored if
222
+ ``api_mtls_endpoint`` is None.
223
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
224
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
225
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
226
+ A callback to provide client certificate bytes and private key bytes,
227
+ both in PEM format. It is used to configure a mutual TLS channel. It is
228
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
229
+ quota_project_id (Optional[str]): An optional project to use for billing
230
+ and quota.
231
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
232
+ The client info used to send a user-agent string along with
233
+ API requests. If ``None``, then default info will be used.
234
+ Generally, you only need to set this if you're developing
235
+ your own client library.
236
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
237
+ be used for service account credentials.
238
+
239
+ Raises:
240
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
241
+ creation failed for any reason.
242
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
243
+ and ``credentials_file`` are passed.
244
+ """
245
+ self._grpc_channel = None
246
+ self._ssl_channel_credentials = ssl_channel_credentials
247
+ self._stubs: Dict[str, Callable] = {}
248
+
249
+ if api_mtls_endpoint:
250
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
251
+ if client_cert_source:
252
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
253
+
254
+ if isinstance(channel, aio.Channel):
255
+ # Ignore credentials if a channel was passed.
256
+ credentials = None
257
+ self._ignore_credentials = True
258
+ # If a channel was explicitly provided, set it.
259
+ self._grpc_channel = channel
260
+ self._ssl_channel_credentials = None
261
+ else:
262
+ if api_mtls_endpoint:
263
+ host = api_mtls_endpoint
264
+
265
+ # Create SSL credentials with client_cert_source or application
266
+ # default SSL credentials.
267
+ if client_cert_source:
268
+ cert, key = client_cert_source()
269
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
270
+ certificate_chain=cert, private_key=key
271
+ )
272
+ else:
273
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
274
+
275
+ else:
276
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
277
+ cert, key = client_cert_source_for_mtls()
278
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
279
+ certificate_chain=cert, private_key=key
280
+ )
281
+
282
+ # The base transport sets the host, credentials and scopes
283
+ super().__init__(
284
+ host=host,
285
+ credentials=credentials,
286
+ credentials_file=credentials_file,
287
+ scopes=scopes,
288
+ quota_project_id=quota_project_id,
289
+ client_info=client_info,
290
+ always_use_jwt_access=always_use_jwt_access,
291
+ api_audience=api_audience,
292
+ )
293
+
294
+ if not self._grpc_channel:
295
+ # initialize with the provided callable or the default channel
296
+ channel_init = channel or type(self).create_channel
297
+ self._grpc_channel = channel_init(
298
+ self._host,
299
+ # use the credentials which are saved
300
+ credentials=self._credentials,
301
+ # Set ``credentials_file`` to ``None`` here as
302
+ # the credentials that we saved earlier should be used.
303
+ credentials_file=None,
304
+ scopes=self._scopes,
305
+ ssl_credentials=self._ssl_channel_credentials,
306
+ quota_project_id=quota_project_id,
307
+ options=[
308
+ ("grpc.max_send_message_length", -1),
309
+ ("grpc.max_receive_message_length", -1),
310
+ ],
311
+ )
312
+
313
+ self._interceptor = _LoggingClientAIOInterceptor()
314
+ self._grpc_channel._unary_unary_interceptors.append(self._interceptor)
315
+ self._logged_channel = self._grpc_channel
316
+ self._wrap_with_kind = (
317
+ "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
318
+ )
319
+ # Wrap messages. This must be done after self._logged_channel exists
320
+ self._prep_wrapped_messages(client_info)
321
+
322
+ @property
323
+ def grpc_channel(self) -> aio.Channel:
324
+ """Create the channel designed to connect to this service.
325
+
326
+ This property caches on the instance; repeated calls return
327
+ the same channel.
328
+ """
329
+ # Return the channel from cache.
330
+ return self._grpc_channel
331
+
332
+ @property
333
+ def list_templates(
334
+ self,
335
+ ) -> Callable[
336
+ [service.ListTemplatesRequest], Awaitable[service.ListTemplatesResponse]
337
+ ]:
338
+ r"""Return a callable for the list templates method over gRPC.
339
+
340
+ Lists Templates in a given project and location.
341
+
342
+ Returns:
343
+ Callable[[~.ListTemplatesRequest],
344
+ Awaitable[~.ListTemplatesResponse]]:
345
+ A function that, when called, will call the underlying RPC
346
+ on the server.
347
+ """
348
+ # Generate a "stub function" on-the-fly which will actually make
349
+ # the request.
350
+ # gRPC handles serialization and deserialization, so we just need
351
+ # to pass in the functions for each.
352
+ if "list_templates" not in self._stubs:
353
+ self._stubs["list_templates"] = self._logged_channel.unary_unary(
354
+ "/google.cloud.modelarmor.v1.ModelArmor/ListTemplates",
355
+ request_serializer=service.ListTemplatesRequest.serialize,
356
+ response_deserializer=service.ListTemplatesResponse.deserialize,
357
+ )
358
+ return self._stubs["list_templates"]
359
+
360
+ @property
361
+ def get_template(
362
+ self,
363
+ ) -> Callable[[service.GetTemplateRequest], Awaitable[service.Template]]:
364
+ r"""Return a callable for the get template method over gRPC.
365
+
366
+ Gets details of a single Template.
367
+
368
+ Returns:
369
+ Callable[[~.GetTemplateRequest],
370
+ Awaitable[~.Template]]:
371
+ A function that, when called, will call the underlying RPC
372
+ on the server.
373
+ """
374
+ # Generate a "stub function" on-the-fly which will actually make
375
+ # the request.
376
+ # gRPC handles serialization and deserialization, so we just need
377
+ # to pass in the functions for each.
378
+ if "get_template" not in self._stubs:
379
+ self._stubs["get_template"] = self._logged_channel.unary_unary(
380
+ "/google.cloud.modelarmor.v1.ModelArmor/GetTemplate",
381
+ request_serializer=service.GetTemplateRequest.serialize,
382
+ response_deserializer=service.Template.deserialize,
383
+ )
384
+ return self._stubs["get_template"]
385
+
386
+ @property
387
+ def create_template(
388
+ self,
389
+ ) -> Callable[[service.CreateTemplateRequest], Awaitable[service.Template]]:
390
+ r"""Return a callable for the create template method over gRPC.
391
+
392
+ Creates a new Template in a given project and
393
+ location.
394
+
395
+ Returns:
396
+ Callable[[~.CreateTemplateRequest],
397
+ Awaitable[~.Template]]:
398
+ A function that, when called, will call the underlying RPC
399
+ on the server.
400
+ """
401
+ # Generate a "stub function" on-the-fly which will actually make
402
+ # the request.
403
+ # gRPC handles serialization and deserialization, so we just need
404
+ # to pass in the functions for each.
405
+ if "create_template" not in self._stubs:
406
+ self._stubs["create_template"] = self._logged_channel.unary_unary(
407
+ "/google.cloud.modelarmor.v1.ModelArmor/CreateTemplate",
408
+ request_serializer=service.CreateTemplateRequest.serialize,
409
+ response_deserializer=service.Template.deserialize,
410
+ )
411
+ return self._stubs["create_template"]
412
+
413
+ @property
414
+ def update_template(
415
+ self,
416
+ ) -> Callable[[service.UpdateTemplateRequest], Awaitable[service.Template]]:
417
+ r"""Return a callable for the update template method over gRPC.
418
+
419
+ Updates the parameters of a single Template.
420
+
421
+ Returns:
422
+ Callable[[~.UpdateTemplateRequest],
423
+ Awaitable[~.Template]]:
424
+ A function that, when called, will call the underlying RPC
425
+ on the server.
426
+ """
427
+ # Generate a "stub function" on-the-fly which will actually make
428
+ # the request.
429
+ # gRPC handles serialization and deserialization, so we just need
430
+ # to pass in the functions for each.
431
+ if "update_template" not in self._stubs:
432
+ self._stubs["update_template"] = self._logged_channel.unary_unary(
433
+ "/google.cloud.modelarmor.v1.ModelArmor/UpdateTemplate",
434
+ request_serializer=service.UpdateTemplateRequest.serialize,
435
+ response_deserializer=service.Template.deserialize,
436
+ )
437
+ return self._stubs["update_template"]
438
+
439
+ @property
440
+ def delete_template(
441
+ self,
442
+ ) -> Callable[[service.DeleteTemplateRequest], Awaitable[empty_pb2.Empty]]:
443
+ r"""Return a callable for the delete template method over gRPC.
444
+
445
+ Deletes a single Template.
446
+
447
+ Returns:
448
+ Callable[[~.DeleteTemplateRequest],
449
+ Awaitable[~.Empty]]:
450
+ A function that, when called, will call the underlying RPC
451
+ on the server.
452
+ """
453
+ # Generate a "stub function" on-the-fly which will actually make
454
+ # the request.
455
+ # gRPC handles serialization and deserialization, so we just need
456
+ # to pass in the functions for each.
457
+ if "delete_template" not in self._stubs:
458
+ self._stubs["delete_template"] = self._logged_channel.unary_unary(
459
+ "/google.cloud.modelarmor.v1.ModelArmor/DeleteTemplate",
460
+ request_serializer=service.DeleteTemplateRequest.serialize,
461
+ response_deserializer=empty_pb2.Empty.FromString,
462
+ )
463
+ return self._stubs["delete_template"]
464
+
465
+ @property
466
+ def get_floor_setting(
467
+ self,
468
+ ) -> Callable[[service.GetFloorSettingRequest], Awaitable[service.FloorSetting]]:
469
+ r"""Return a callable for the get floor setting method over gRPC.
470
+
471
+ Gets details of a single floor setting of a project
472
+
473
+ Returns:
474
+ Callable[[~.GetFloorSettingRequest],
475
+ Awaitable[~.FloorSetting]]:
476
+ A function that, when called, will call the underlying RPC
477
+ on the server.
478
+ """
479
+ # Generate a "stub function" on-the-fly which will actually make
480
+ # the request.
481
+ # gRPC handles serialization and deserialization, so we just need
482
+ # to pass in the functions for each.
483
+ if "get_floor_setting" not in self._stubs:
484
+ self._stubs["get_floor_setting"] = self._logged_channel.unary_unary(
485
+ "/google.cloud.modelarmor.v1.ModelArmor/GetFloorSetting",
486
+ request_serializer=service.GetFloorSettingRequest.serialize,
487
+ response_deserializer=service.FloorSetting.deserialize,
488
+ )
489
+ return self._stubs["get_floor_setting"]
490
+
491
+ @property
492
+ def update_floor_setting(
493
+ self,
494
+ ) -> Callable[[service.UpdateFloorSettingRequest], Awaitable[service.FloorSetting]]:
495
+ r"""Return a callable for the update floor setting method over gRPC.
496
+
497
+ Updates the parameters of a single floor setting of a
498
+ project
499
+
500
+ Returns:
501
+ Callable[[~.UpdateFloorSettingRequest],
502
+ Awaitable[~.FloorSetting]]:
503
+ A function that, when called, will call the underlying RPC
504
+ on the server.
505
+ """
506
+ # Generate a "stub function" on-the-fly which will actually make
507
+ # the request.
508
+ # gRPC handles serialization and deserialization, so we just need
509
+ # to pass in the functions for each.
510
+ if "update_floor_setting" not in self._stubs:
511
+ self._stubs["update_floor_setting"] = self._logged_channel.unary_unary(
512
+ "/google.cloud.modelarmor.v1.ModelArmor/UpdateFloorSetting",
513
+ request_serializer=service.UpdateFloorSettingRequest.serialize,
514
+ response_deserializer=service.FloorSetting.deserialize,
515
+ )
516
+ return self._stubs["update_floor_setting"]
517
+
518
+ @property
519
+ def sanitize_user_prompt(
520
+ self,
521
+ ) -> Callable[
522
+ [service.SanitizeUserPromptRequest],
523
+ Awaitable[service.SanitizeUserPromptResponse],
524
+ ]:
525
+ r"""Return a callable for the sanitize user prompt method over gRPC.
526
+
527
+ Sanitizes User Prompt.
528
+
529
+ Returns:
530
+ Callable[[~.SanitizeUserPromptRequest],
531
+ Awaitable[~.SanitizeUserPromptResponse]]:
532
+ A function that, when called, will call the underlying RPC
533
+ on the server.
534
+ """
535
+ # Generate a "stub function" on-the-fly which will actually make
536
+ # the request.
537
+ # gRPC handles serialization and deserialization, so we just need
538
+ # to pass in the functions for each.
539
+ if "sanitize_user_prompt" not in self._stubs:
540
+ self._stubs["sanitize_user_prompt"] = self._logged_channel.unary_unary(
541
+ "/google.cloud.modelarmor.v1.ModelArmor/SanitizeUserPrompt",
542
+ request_serializer=service.SanitizeUserPromptRequest.serialize,
543
+ response_deserializer=service.SanitizeUserPromptResponse.deserialize,
544
+ )
545
+ return self._stubs["sanitize_user_prompt"]
546
+
547
+ @property
548
+ def sanitize_model_response(
549
+ self,
550
+ ) -> Callable[
551
+ [service.SanitizeModelResponseRequest],
552
+ Awaitable[service.SanitizeModelResponseResponse],
553
+ ]:
554
+ r"""Return a callable for the sanitize model response method over gRPC.
555
+
556
+ Sanitizes Model Response.
557
+
558
+ Returns:
559
+ Callable[[~.SanitizeModelResponseRequest],
560
+ Awaitable[~.SanitizeModelResponseResponse]]:
561
+ A function that, when called, will call the underlying RPC
562
+ on the server.
563
+ """
564
+ # Generate a "stub function" on-the-fly which will actually make
565
+ # the request.
566
+ # gRPC handles serialization and deserialization, so we just need
567
+ # to pass in the functions for each.
568
+ if "sanitize_model_response" not in self._stubs:
569
+ self._stubs["sanitize_model_response"] = self._logged_channel.unary_unary(
570
+ "/google.cloud.modelarmor.v1.ModelArmor/SanitizeModelResponse",
571
+ request_serializer=service.SanitizeModelResponseRequest.serialize,
572
+ response_deserializer=service.SanitizeModelResponseResponse.deserialize,
573
+ )
574
+ return self._stubs["sanitize_model_response"]
575
+
576
+ def _prep_wrapped_messages(self, client_info):
577
+ """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
578
+ self._wrapped_methods = {
579
+ self.list_templates: self._wrap_method(
580
+ self.list_templates,
581
+ default_retry=retries.AsyncRetry(
582
+ initial=1.0,
583
+ maximum=10.0,
584
+ multiplier=1.3,
585
+ predicate=retries.if_exception_type(
586
+ core_exceptions.ServiceUnavailable,
587
+ ),
588
+ deadline=60.0,
589
+ ),
590
+ default_timeout=60.0,
591
+ client_info=client_info,
592
+ ),
593
+ self.get_template: self._wrap_method(
594
+ self.get_template,
595
+ default_retry=retries.AsyncRetry(
596
+ initial=1.0,
597
+ maximum=10.0,
598
+ multiplier=1.3,
599
+ predicate=retries.if_exception_type(
600
+ core_exceptions.ServiceUnavailable,
601
+ ),
602
+ deadline=60.0,
603
+ ),
604
+ default_timeout=60.0,
605
+ client_info=client_info,
606
+ ),
607
+ self.create_template: self._wrap_method(
608
+ self.create_template,
609
+ default_timeout=60.0,
610
+ client_info=client_info,
611
+ ),
612
+ self.update_template: self._wrap_method(
613
+ self.update_template,
614
+ default_timeout=60.0,
615
+ client_info=client_info,
616
+ ),
617
+ self.delete_template: self._wrap_method(
618
+ self.delete_template,
619
+ default_timeout=60.0,
620
+ client_info=client_info,
621
+ ),
622
+ self.get_floor_setting: self._wrap_method(
623
+ self.get_floor_setting,
624
+ default_retry=retries.AsyncRetry(
625
+ initial=1.0,
626
+ maximum=10.0,
627
+ multiplier=1.3,
628
+ predicate=retries.if_exception_type(
629
+ core_exceptions.ServiceUnavailable,
630
+ ),
631
+ deadline=60.0,
632
+ ),
633
+ default_timeout=60.0,
634
+ client_info=client_info,
635
+ ),
636
+ self.update_floor_setting: self._wrap_method(
637
+ self.update_floor_setting,
638
+ default_timeout=60.0,
639
+ client_info=client_info,
640
+ ),
641
+ self.sanitize_user_prompt: self._wrap_method(
642
+ self.sanitize_user_prompt,
643
+ default_retry=retries.AsyncRetry(
644
+ initial=1.0,
645
+ maximum=10.0,
646
+ multiplier=1.3,
647
+ predicate=retries.if_exception_type(
648
+ core_exceptions.ServiceUnavailable,
649
+ ),
650
+ deadline=60.0,
651
+ ),
652
+ default_timeout=60.0,
653
+ client_info=client_info,
654
+ ),
655
+ self.sanitize_model_response: self._wrap_method(
656
+ self.sanitize_model_response,
657
+ default_retry=retries.AsyncRetry(
658
+ initial=1.0,
659
+ maximum=10.0,
660
+ multiplier=1.3,
661
+ predicate=retries.if_exception_type(
662
+ core_exceptions.ServiceUnavailable,
663
+ ),
664
+ deadline=60.0,
665
+ ),
666
+ default_timeout=60.0,
667
+ client_info=client_info,
668
+ ),
669
+ self.get_location: self._wrap_method(
670
+ self.get_location,
671
+ default_timeout=None,
672
+ client_info=client_info,
673
+ ),
674
+ self.list_locations: self._wrap_method(
675
+ self.list_locations,
676
+ default_timeout=None,
677
+ client_info=client_info,
678
+ ),
679
+ }
680
+
681
+ def _wrap_method(self, func, *args, **kwargs):
682
+ if self._wrap_with_kind: # pragma: NO COVER
683
+ kwargs["kind"] = self.kind
684
+ return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
685
+
686
+ def close(self):
687
+ return self._logged_channel.close()
688
+
689
+ @property
690
+ def kind(self) -> str:
691
+ return "grpc_asyncio"
692
+
693
+ @property
694
+ def list_locations(
695
+ self,
696
+ ) -> Callable[
697
+ [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse
698
+ ]:
699
+ r"""Return a callable for the list locations method over gRPC."""
700
+ # Generate a "stub function" on-the-fly which will actually make
701
+ # the request.
702
+ # gRPC handles serialization and deserialization, so we just need
703
+ # to pass in the functions for each.
704
+ if "list_locations" not in self._stubs:
705
+ self._stubs["list_locations"] = self._logged_channel.unary_unary(
706
+ "/google.cloud.location.Locations/ListLocations",
707
+ request_serializer=locations_pb2.ListLocationsRequest.SerializeToString,
708
+ response_deserializer=locations_pb2.ListLocationsResponse.FromString,
709
+ )
710
+ return self._stubs["list_locations"]
711
+
712
+ @property
713
+ def get_location(
714
+ self,
715
+ ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]:
716
+ r"""Return a callable for the list locations method over gRPC."""
717
+ # Generate a "stub function" on-the-fly which will actually make
718
+ # the request.
719
+ # gRPC handles serialization and deserialization, so we just need
720
+ # to pass in the functions for each.
721
+ if "get_location" not in self._stubs:
722
+ self._stubs["get_location"] = self._logged_channel.unary_unary(
723
+ "/google.cloud.location.Locations/GetLocation",
724
+ request_serializer=locations_pb2.GetLocationRequest.SerializeToString,
725
+ response_deserializer=locations_pb2.Location.FromString,
726
+ )
727
+ return self._stubs["get_location"]
728
+
729
+
730
+ __all__ = ("ModelArmorGrpcAsyncIOTransport",)