1# -*- coding: utf-8 -*-
2# Copyright 2022 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#
16from collections import OrderedDict
17import functools
18import re
19from typing import (
20 Dict,
21 Mapping,
22 MutableMapping,
23 MutableSequence,
24 Optional,
25 Sequence,
26 Tuple,
27 Type,
28 Union,
29)
30
31from google.api_core import exceptions as core_exceptions
32from google.api_core import gapic_v1
33from google.api_core import retry as retries
34from google.api_core.client_options import ClientOptions
35from google.auth import credentials as ga_credentials # type: ignore
36from google.oauth2 import service_account # type: ignore
37
38from google.cloud.resourcemanager_v3 import gapic_version as package_version
39
40try:
41 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
42except AttributeError: # pragma: NO COVER
43 OptionalRetry = Union[retries.Retry, object] # type: ignore
44
45from google.api_core import operation # type: ignore
46from google.api_core import operation_async # type: ignore
47from google.iam.v1 import iam_policy_pb2 # type: ignore
48from google.iam.v1 import policy_pb2 # type: ignore
49from google.longrunning import operations_pb2
50from google.protobuf import field_mask_pb2 # type: ignore
51from google.protobuf import timestamp_pb2 # type: ignore
52
53from google.cloud.resourcemanager_v3.services.tag_values import pagers
54from google.cloud.resourcemanager_v3.types import tag_values
55
56from .client import TagValuesClient
57from .transports.base import DEFAULT_CLIENT_INFO, TagValuesTransport
58from .transports.grpc_asyncio import TagValuesGrpcAsyncIOTransport
59
60
61class TagValuesAsyncClient:
62 """Allow users to create and manage tag values."""
63
64 _client: TagValuesClient
65
66 DEFAULT_ENDPOINT = TagValuesClient.DEFAULT_ENDPOINT
67 DEFAULT_MTLS_ENDPOINT = TagValuesClient.DEFAULT_MTLS_ENDPOINT
68
69 tag_value_path = staticmethod(TagValuesClient.tag_value_path)
70 parse_tag_value_path = staticmethod(TagValuesClient.parse_tag_value_path)
71 common_billing_account_path = staticmethod(
72 TagValuesClient.common_billing_account_path
73 )
74 parse_common_billing_account_path = staticmethod(
75 TagValuesClient.parse_common_billing_account_path
76 )
77 common_folder_path = staticmethod(TagValuesClient.common_folder_path)
78 parse_common_folder_path = staticmethod(TagValuesClient.parse_common_folder_path)
79 common_organization_path = staticmethod(TagValuesClient.common_organization_path)
80 parse_common_organization_path = staticmethod(
81 TagValuesClient.parse_common_organization_path
82 )
83 common_project_path = staticmethod(TagValuesClient.common_project_path)
84 parse_common_project_path = staticmethod(TagValuesClient.parse_common_project_path)
85 common_location_path = staticmethod(TagValuesClient.common_location_path)
86 parse_common_location_path = staticmethod(
87 TagValuesClient.parse_common_location_path
88 )
89
90 @classmethod
91 def from_service_account_info(cls, info: dict, *args, **kwargs):
92 """Creates an instance of this client using the provided credentials
93 info.
94
95 Args:
96 info (dict): The service account private key info.
97 args: Additional arguments to pass to the constructor.
98 kwargs: Additional arguments to pass to the constructor.
99
100 Returns:
101 TagValuesAsyncClient: The constructed client.
102 """
103 return TagValuesClient.from_service_account_info.__func__(TagValuesAsyncClient, info, *args, **kwargs) # type: ignore
104
105 @classmethod
106 def from_service_account_file(cls, filename: str, *args, **kwargs):
107 """Creates an instance of this client using the provided credentials
108 file.
109
110 Args:
111 filename (str): The path to the service account private key json
112 file.
113 args: Additional arguments to pass to the constructor.
114 kwargs: Additional arguments to pass to the constructor.
115
116 Returns:
117 TagValuesAsyncClient: The constructed client.
118 """
119 return TagValuesClient.from_service_account_file.__func__(TagValuesAsyncClient, filename, *args, **kwargs) # type: ignore
120
121 from_service_account_json = from_service_account_file
122
123 @classmethod
124 def get_mtls_endpoint_and_cert_source(
125 cls, client_options: Optional[ClientOptions] = None
126 ):
127 """Return the API endpoint and client cert source for mutual TLS.
128
129 The client cert source is determined in the following order:
130 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
131 client cert source is None.
132 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
133 default client cert source exists, use the default one; otherwise the client cert
134 source is None.
135
136 The API endpoint is determined in the following order:
137 (1) if `client_options.api_endpoint` if provided, use the provided one.
138 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
139 default mTLS endpoint; if the environment variable is "never", use the default API
140 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
141 use the default API endpoint.
142
143 More details can be found at https://google.aip.dev/auth/4114.
144
145 Args:
146 client_options (google.api_core.client_options.ClientOptions): Custom options for the
147 client. Only the `api_endpoint` and `client_cert_source` properties may be used
148 in this method.
149
150 Returns:
151 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
152 client cert source to use.
153
154 Raises:
155 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
156 """
157 return TagValuesClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
158
159 @property
160 def transport(self) -> TagValuesTransport:
161 """Returns the transport used by the client instance.
162
163 Returns:
164 TagValuesTransport: The transport used by the client instance.
165 """
166 return self._client.transport
167
168 get_transport_class = functools.partial(
169 type(TagValuesClient).get_transport_class, type(TagValuesClient)
170 )
171
172 def __init__(
173 self,
174 *,
175 credentials: Optional[ga_credentials.Credentials] = None,
176 transport: Union[str, TagValuesTransport] = "grpc_asyncio",
177 client_options: Optional[ClientOptions] = None,
178 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
179 ) -> None:
180 """Instantiates the tag values client.
181
182 Args:
183 credentials (Optional[google.auth.credentials.Credentials]): The
184 authorization credentials to attach to requests. These
185 credentials identify the application to the service; if none
186 are specified, the client will attempt to ascertain the
187 credentials from the environment.
188 transport (Union[str, ~.TagValuesTransport]): The
189 transport to use. If set to None, a transport is chosen
190 automatically.
191 client_options (ClientOptions): Custom options for the client. It
192 won't take effect if a ``transport`` instance is provided.
193 (1) The ``api_endpoint`` property can be used to override the
194 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
195 environment variable can also be used to override the endpoint:
196 "always" (always use the default mTLS endpoint), "never" (always
197 use the default regular endpoint) and "auto" (auto switch to the
198 default mTLS endpoint if client certificate is present, this is
199 the default value). However, the ``api_endpoint`` property takes
200 precedence if provided.
201 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
202 is "true", then the ``client_cert_source`` property can be used
203 to provide client certificate for mutual TLS transport. If
204 not provided, the default SSL client certificate will be used if
205 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
206 set, no client certificate will be used.
207
208 Raises:
209 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
210 creation failed for any reason.
211 """
212 self._client = TagValuesClient(
213 credentials=credentials,
214 transport=transport,
215 client_options=client_options,
216 client_info=client_info,
217 )
218
219 async def list_tag_values(
220 self,
221 request: Optional[Union[tag_values.ListTagValuesRequest, dict]] = None,
222 *,
223 parent: Optional[str] = None,
224 retry: OptionalRetry = gapic_v1.method.DEFAULT,
225 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
226 metadata: Sequence[Tuple[str, str]] = (),
227 ) -> pagers.ListTagValuesAsyncPager:
228 r"""Lists all TagValues for a specific TagKey.
229
230 .. code-block:: python
231
232 # This snippet has been automatically generated and should be regarded as a
233 # code template only.
234 # It will require modifications to work:
235 # - It may require correct/in-range values for request initialization.
236 # - It may require specifying regional endpoints when creating the service
237 # client as shown in:
238 # https://googleapis.dev/python/google-api-core/latest/client_options.html
239 from google.cloud import resourcemanager_v3
240
241 async def sample_list_tag_values():
242 # Create a client
243 client = resourcemanager_v3.TagValuesAsyncClient()
244
245 # Initialize request argument(s)
246 request = resourcemanager_v3.ListTagValuesRequest(
247 parent="parent_value",
248 )
249
250 # Make the request
251 page_result = client.list_tag_values(request=request)
252
253 # Handle the response
254 async for response in page_result:
255 print(response)
256
257 Args:
258 request (Optional[Union[google.cloud.resourcemanager_v3.types.ListTagValuesRequest, dict]]):
259 The request object. The request message for listing TagValues for the
260 specified TagKey. Resource name for TagKey, parent of
261 the TagValues to be listed, in the format
262 ``tagKeys/123``.
263 parent (:class:`str`):
264 Required.
265 This corresponds to the ``parent`` field
266 on the ``request`` instance; if ``request`` is provided, this
267 should not be set.
268 retry (google.api_core.retry.Retry): Designation of what errors, if any,
269 should be retried.
270 timeout (float): The timeout for this request.
271 metadata (Sequence[Tuple[str, str]]): Strings which should be
272 sent along with the request as metadata.
273
274 Returns:
275 google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesAsyncPager:
276 The ListTagValues response.
277 Iterating over this object will yield
278 results and resolve additional pages
279 automatically.
280
281 """
282 # Create or coerce a protobuf request object.
283 # Quick check: If we got a request object, we should *not* have
284 # gotten any keyword arguments that map to the request.
285 has_flattened_params = any([parent])
286 if request is not None and has_flattened_params:
287 raise ValueError(
288 "If the `request` argument is set, then none of "
289 "the individual field arguments should be set."
290 )
291
292 request = tag_values.ListTagValuesRequest(request)
293
294 # If we have keyword arguments corresponding to fields on the
295 # request, apply these.
296 if parent is not None:
297 request.parent = parent
298
299 # Wrap the RPC method; this adds retry and timeout information,
300 # and friendly error handling.
301 rpc = gapic_v1.method_async.wrap_method(
302 self._client._transport.list_tag_values,
303 default_retry=retries.Retry(
304 initial=0.1,
305 maximum=60.0,
306 multiplier=1.3,
307 predicate=retries.if_exception_type(
308 core_exceptions.ServiceUnavailable,
309 ),
310 deadline=60.0,
311 ),
312 default_timeout=60.0,
313 client_info=DEFAULT_CLIENT_INFO,
314 )
315
316 # Send the request.
317 response = await rpc(
318 request,
319 retry=retry,
320 timeout=timeout,
321 metadata=metadata,
322 )
323
324 # This method is paged; wrap the response in a pager, which provides
325 # an `__aiter__` convenience method.
326 response = pagers.ListTagValuesAsyncPager(
327 method=rpc,
328 request=request,
329 response=response,
330 metadata=metadata,
331 )
332
333 # Done; return the response.
334 return response
335
336 async def get_tag_value(
337 self,
338 request: Optional[Union[tag_values.GetTagValueRequest, dict]] = None,
339 *,
340 name: Optional[str] = None,
341 retry: OptionalRetry = gapic_v1.method.DEFAULT,
342 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
343 metadata: Sequence[Tuple[str, str]] = (),
344 ) -> tag_values.TagValue:
345 r"""Retrieves a TagValue. This method will return
346 ``PERMISSION_DENIED`` if the value does not exist or the user
347 does not have permission to view it.
348
349 .. code-block:: python
350
351 # This snippet has been automatically generated and should be regarded as a
352 # code template only.
353 # It will require modifications to work:
354 # - It may require correct/in-range values for request initialization.
355 # - It may require specifying regional endpoints when creating the service
356 # client as shown in:
357 # https://googleapis.dev/python/google-api-core/latest/client_options.html
358 from google.cloud import resourcemanager_v3
359
360 async def sample_get_tag_value():
361 # Create a client
362 client = resourcemanager_v3.TagValuesAsyncClient()
363
364 # Initialize request argument(s)
365 request = resourcemanager_v3.GetTagValueRequest(
366 name="name_value",
367 )
368
369 # Make the request
370 response = await client.get_tag_value(request=request)
371
372 # Handle the response
373 print(response)
374
375 Args:
376 request (Optional[Union[google.cloud.resourcemanager_v3.types.GetTagValueRequest, dict]]):
377 The request object. The request message for getting a
378 TagValue.
379 name (:class:`str`):
380 Required. Resource name for TagValue to be fetched in
381 the format ``tagValues/456``.
382
383 This corresponds to the ``name`` field
384 on the ``request`` instance; if ``request`` is provided, this
385 should not be set.
386 retry (google.api_core.retry.Retry): Designation of what errors, if any,
387 should be retried.
388 timeout (float): The timeout for this request.
389 metadata (Sequence[Tuple[str, str]]): Strings which should be
390 sent along with the request as metadata.
391
392 Returns:
393 google.cloud.resourcemanager_v3.types.TagValue:
394 A TagValue is a child of a particular
395 TagKey. This is used to group cloud
396 resources for the purpose of controlling
397 them using policies.
398
399 """
400 # Create or coerce a protobuf request object.
401 # Quick check: If we got a request object, we should *not* have
402 # gotten any keyword arguments that map to the request.
403 has_flattened_params = any([name])
404 if request is not None and has_flattened_params:
405 raise ValueError(
406 "If the `request` argument is set, then none of "
407 "the individual field arguments should be set."
408 )
409
410 request = tag_values.GetTagValueRequest(request)
411
412 # If we have keyword arguments corresponding to fields on the
413 # request, apply these.
414 if name is not None:
415 request.name = name
416
417 # Wrap the RPC method; this adds retry and timeout information,
418 # and friendly error handling.
419 rpc = gapic_v1.method_async.wrap_method(
420 self._client._transport.get_tag_value,
421 default_retry=retries.Retry(
422 initial=0.1,
423 maximum=60.0,
424 multiplier=1.3,
425 predicate=retries.if_exception_type(
426 core_exceptions.ServiceUnavailable,
427 ),
428 deadline=60.0,
429 ),
430 default_timeout=60.0,
431 client_info=DEFAULT_CLIENT_INFO,
432 )
433
434 # Certain fields should be provided within the metadata header;
435 # add these here.
436 metadata = tuple(metadata) + (
437 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
438 )
439
440 # Send the request.
441 response = await rpc(
442 request,
443 retry=retry,
444 timeout=timeout,
445 metadata=metadata,
446 )
447
448 # Done; return the response.
449 return response
450
451 async def get_namespaced_tag_value(
452 self,
453 request: Optional[Union[tag_values.GetNamespacedTagValueRequest, dict]] = None,
454 *,
455 name: Optional[str] = None,
456 retry: OptionalRetry = gapic_v1.method.DEFAULT,
457 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
458 metadata: Sequence[Tuple[str, str]] = (),
459 ) -> tag_values.TagValue:
460 r"""Retrieves a TagValue by its namespaced name. This method will
461 return ``PERMISSION_DENIED`` if the value does not exist or the
462 user does not have permission to view it.
463
464 .. code-block:: python
465
466 # This snippet has been automatically generated and should be regarded as a
467 # code template only.
468 # It will require modifications to work:
469 # - It may require correct/in-range values for request initialization.
470 # - It may require specifying regional endpoints when creating the service
471 # client as shown in:
472 # https://googleapis.dev/python/google-api-core/latest/client_options.html
473 from google.cloud import resourcemanager_v3
474
475 async def sample_get_namespaced_tag_value():
476 # Create a client
477 client = resourcemanager_v3.TagValuesAsyncClient()
478
479 # Initialize request argument(s)
480 request = resourcemanager_v3.GetNamespacedTagValueRequest(
481 name="name_value",
482 )
483
484 # Make the request
485 response = await client.get_namespaced_tag_value(request=request)
486
487 # Handle the response
488 print(response)
489
490 Args:
491 request (Optional[Union[google.cloud.resourcemanager_v3.types.GetNamespacedTagValueRequest, dict]]):
492 The request object. The request message for getting a
493 TagValue by its namespaced name.
494 name (:class:`str`):
495 Required. A namespaced tag value name in the following
496 format:
497
498 ``{parentId}/{tagKeyShort}/{tagValueShort}``
499
500 Examples:
501
502 - ``42/foo/abc`` for a value with short name "abc"
503 under the key with short name "foo" under the
504 organization with ID 42
505 - ``r2-d2/bar/xyz`` for a value with short name "xyz"
506 under the key with short name "bar" under the project
507 with ID "r2-d2"
508
509 This corresponds to the ``name`` field
510 on the ``request`` instance; if ``request`` is provided, this
511 should not be set.
512 retry (google.api_core.retry.Retry): Designation of what errors, if any,
513 should be retried.
514 timeout (float): The timeout for this request.
515 metadata (Sequence[Tuple[str, str]]): Strings which should be
516 sent along with the request as metadata.
517
518 Returns:
519 google.cloud.resourcemanager_v3.types.TagValue:
520 A TagValue is a child of a particular
521 TagKey. This is used to group cloud
522 resources for the purpose of controlling
523 them using policies.
524
525 """
526 # Create or coerce a protobuf request object.
527 # Quick check: If we got a request object, we should *not* have
528 # gotten any keyword arguments that map to the request.
529 has_flattened_params = any([name])
530 if request is not None and has_flattened_params:
531 raise ValueError(
532 "If the `request` argument is set, then none of "
533 "the individual field arguments should be set."
534 )
535
536 request = tag_values.GetNamespacedTagValueRequest(request)
537
538 # If we have keyword arguments corresponding to fields on the
539 # request, apply these.
540 if name is not None:
541 request.name = name
542
543 # Wrap the RPC method; this adds retry and timeout information,
544 # and friendly error handling.
545 rpc = gapic_v1.method_async.wrap_method(
546 self._client._transport.get_namespaced_tag_value,
547 default_timeout=None,
548 client_info=DEFAULT_CLIENT_INFO,
549 )
550
551 # Send the request.
552 response = await rpc(
553 request,
554 retry=retry,
555 timeout=timeout,
556 metadata=metadata,
557 )
558
559 # Done; return the response.
560 return response
561
562 async def create_tag_value(
563 self,
564 request: Optional[Union[tag_values.CreateTagValueRequest, dict]] = None,
565 *,
566 tag_value: Optional[tag_values.TagValue] = None,
567 retry: OptionalRetry = gapic_v1.method.DEFAULT,
568 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
569 metadata: Sequence[Tuple[str, str]] = (),
570 ) -> operation_async.AsyncOperation:
571 r"""Creates a TagValue as a child of the specified
572 TagKey. If a another request with the same parameters is
573 sent while the original request is in process the second
574 request will receive an error. A maximum of 1000
575 TagValues can exist under a TagKey at any given time.
576
577 .. code-block:: python
578
579 # This snippet has been automatically generated and should be regarded as a
580 # code template only.
581 # It will require modifications to work:
582 # - It may require correct/in-range values for request initialization.
583 # - It may require specifying regional endpoints when creating the service
584 # client as shown in:
585 # https://googleapis.dev/python/google-api-core/latest/client_options.html
586 from google.cloud import resourcemanager_v3
587
588 async def sample_create_tag_value():
589 # Create a client
590 client = resourcemanager_v3.TagValuesAsyncClient()
591
592 # Initialize request argument(s)
593 tag_value = resourcemanager_v3.TagValue()
594 tag_value.short_name = "short_name_value"
595
596 request = resourcemanager_v3.CreateTagValueRequest(
597 tag_value=tag_value,
598 )
599
600 # Make the request
601 operation = client.create_tag_value(request=request)
602
603 print("Waiting for operation to complete...")
604
605 response = (await operation).result()
606
607 # Handle the response
608 print(response)
609
610 Args:
611 request (Optional[Union[google.cloud.resourcemanager_v3.types.CreateTagValueRequest, dict]]):
612 The request object. The request message for creating a
613 TagValue.
614 tag_value (:class:`google.cloud.resourcemanager_v3.types.TagValue`):
615 Required. The TagValue to be created. Only fields
616 ``short_name``, ``description``, and ``parent`` are
617 considered during the creation request.
618
619 This corresponds to the ``tag_value`` field
620 on the ``request`` instance; if ``request`` is provided, this
621 should not be set.
622 retry (google.api_core.retry.Retry): Designation of what errors, if any,
623 should be retried.
624 timeout (float): The timeout for this request.
625 metadata (Sequence[Tuple[str, str]]): Strings which should be
626 sent along with the request as metadata.
627
628 Returns:
629 google.api_core.operation_async.AsyncOperation:
630 An object representing a long-running operation.
631
632 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.TagValue` A TagValue is a child of a particular TagKey. This is used to group
633 cloud resources for the purpose of controlling them
634 using policies.
635
636 """
637 # Create or coerce a protobuf request object.
638 # Quick check: If we got a request object, we should *not* have
639 # gotten any keyword arguments that map to the request.
640 has_flattened_params = any([tag_value])
641 if request is not None and has_flattened_params:
642 raise ValueError(
643 "If the `request` argument is set, then none of "
644 "the individual field arguments should be set."
645 )
646
647 request = tag_values.CreateTagValueRequest(request)
648
649 # If we have keyword arguments corresponding to fields on the
650 # request, apply these.
651 if tag_value is not None:
652 request.tag_value = tag_value
653
654 # Wrap the RPC method; this adds retry and timeout information,
655 # and friendly error handling.
656 rpc = gapic_v1.method_async.wrap_method(
657 self._client._transport.create_tag_value,
658 default_timeout=60.0,
659 client_info=DEFAULT_CLIENT_INFO,
660 )
661
662 # Send the request.
663 response = await rpc(
664 request,
665 retry=retry,
666 timeout=timeout,
667 metadata=metadata,
668 )
669
670 # Wrap the response in an operation future.
671 response = operation_async.from_gapic(
672 response,
673 self._client._transport.operations_client,
674 tag_values.TagValue,
675 metadata_type=tag_values.CreateTagValueMetadata,
676 )
677
678 # Done; return the response.
679 return response
680
681 async def update_tag_value(
682 self,
683 request: Optional[Union[tag_values.UpdateTagValueRequest, dict]] = None,
684 *,
685 tag_value: Optional[tag_values.TagValue] = None,
686 update_mask: Optional[field_mask_pb2.FieldMask] = None,
687 retry: OptionalRetry = gapic_v1.method.DEFAULT,
688 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
689 metadata: Sequence[Tuple[str, str]] = (),
690 ) -> operation_async.AsyncOperation:
691 r"""Updates the attributes of the TagValue resource.
692
693 .. code-block:: python
694
695 # This snippet has been automatically generated and should be regarded as a
696 # code template only.
697 # It will require modifications to work:
698 # - It may require correct/in-range values for request initialization.
699 # - It may require specifying regional endpoints when creating the service
700 # client as shown in:
701 # https://googleapis.dev/python/google-api-core/latest/client_options.html
702 from google.cloud import resourcemanager_v3
703
704 async def sample_update_tag_value():
705 # Create a client
706 client = resourcemanager_v3.TagValuesAsyncClient()
707
708 # Initialize request argument(s)
709 tag_value = resourcemanager_v3.TagValue()
710 tag_value.short_name = "short_name_value"
711
712 request = resourcemanager_v3.UpdateTagValueRequest(
713 tag_value=tag_value,
714 )
715
716 # Make the request
717 operation = client.update_tag_value(request=request)
718
719 print("Waiting for operation to complete...")
720
721 response = (await operation).result()
722
723 # Handle the response
724 print(response)
725
726 Args:
727 request (Optional[Union[google.cloud.resourcemanager_v3.types.UpdateTagValueRequest, dict]]):
728 The request object. The request message for updating a
729 TagValue.
730 tag_value (:class:`google.cloud.resourcemanager_v3.types.TagValue`):
731 Required. The new definition of the TagValue. Only
732 fields ``description`` and ``etag`` fields can be
733 updated by this request. If the ``etag`` field is
734 nonempty, it must match the ``etag`` field of the
735 existing ControlGroup. Otherwise, ``ABORTED`` will be
736 returned.
737
738 This corresponds to the ``tag_value`` field
739 on the ``request`` instance; if ``request`` is provided, this
740 should not be set.
741 update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
742 Optional. Fields to be updated.
743 This corresponds to the ``update_mask`` field
744 on the ``request`` instance; if ``request`` is provided, this
745 should not be set.
746 retry (google.api_core.retry.Retry): Designation of what errors, if any,
747 should be retried.
748 timeout (float): The timeout for this request.
749 metadata (Sequence[Tuple[str, str]]): Strings which should be
750 sent along with the request as metadata.
751
752 Returns:
753 google.api_core.operation_async.AsyncOperation:
754 An object representing a long-running operation.
755
756 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.TagValue` A TagValue is a child of a particular TagKey. This is used to group
757 cloud resources for the purpose of controlling them
758 using policies.
759
760 """
761 # Create or coerce a protobuf request object.
762 # Quick check: If we got a request object, we should *not* have
763 # gotten any keyword arguments that map to the request.
764 has_flattened_params = any([tag_value, update_mask])
765 if request is not None and has_flattened_params:
766 raise ValueError(
767 "If the `request` argument is set, then none of "
768 "the individual field arguments should be set."
769 )
770
771 request = tag_values.UpdateTagValueRequest(request)
772
773 # If we have keyword arguments corresponding to fields on the
774 # request, apply these.
775 if tag_value is not None:
776 request.tag_value = tag_value
777 if update_mask is not None:
778 request.update_mask = update_mask
779
780 # Wrap the RPC method; this adds retry and timeout information,
781 # and friendly error handling.
782 rpc = gapic_v1.method_async.wrap_method(
783 self._client._transport.update_tag_value,
784 default_timeout=60.0,
785 client_info=DEFAULT_CLIENT_INFO,
786 )
787
788 # Certain fields should be provided within the metadata header;
789 # add these here.
790 metadata = tuple(metadata) + (
791 gapic_v1.routing_header.to_grpc_metadata(
792 (("tag_value.name", request.tag_value.name),)
793 ),
794 )
795
796 # Send the request.
797 response = await rpc(
798 request,
799 retry=retry,
800 timeout=timeout,
801 metadata=metadata,
802 )
803
804 # Wrap the response in an operation future.
805 response = operation_async.from_gapic(
806 response,
807 self._client._transport.operations_client,
808 tag_values.TagValue,
809 metadata_type=tag_values.UpdateTagValueMetadata,
810 )
811
812 # Done; return the response.
813 return response
814
815 async def delete_tag_value(
816 self,
817 request: Optional[Union[tag_values.DeleteTagValueRequest, dict]] = None,
818 *,
819 name: Optional[str] = None,
820 retry: OptionalRetry = gapic_v1.method.DEFAULT,
821 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
822 metadata: Sequence[Tuple[str, str]] = (),
823 ) -> operation_async.AsyncOperation:
824 r"""Deletes a TagValue. The TagValue cannot have any
825 bindings when it is deleted.
826
827 .. code-block:: python
828
829 # This snippet has been automatically generated and should be regarded as a
830 # code template only.
831 # It will require modifications to work:
832 # - It may require correct/in-range values for request initialization.
833 # - It may require specifying regional endpoints when creating the service
834 # client as shown in:
835 # https://googleapis.dev/python/google-api-core/latest/client_options.html
836 from google.cloud import resourcemanager_v3
837
838 async def sample_delete_tag_value():
839 # Create a client
840 client = resourcemanager_v3.TagValuesAsyncClient()
841
842 # Initialize request argument(s)
843 request = resourcemanager_v3.DeleteTagValueRequest(
844 name="name_value",
845 )
846
847 # Make the request
848 operation = client.delete_tag_value(request=request)
849
850 print("Waiting for operation to complete...")
851
852 response = (await operation).result()
853
854 # Handle the response
855 print(response)
856
857 Args:
858 request (Optional[Union[google.cloud.resourcemanager_v3.types.DeleteTagValueRequest, dict]]):
859 The request object. The request message for deleting a
860 TagValue.
861 name (:class:`str`):
862 Required. Resource name for TagValue
863 to be deleted in the format
864 tagValues/456.
865
866 This corresponds to the ``name`` field
867 on the ``request`` instance; if ``request`` is provided, this
868 should not be set.
869 retry (google.api_core.retry.Retry): Designation of what errors, if any,
870 should be retried.
871 timeout (float): The timeout for this request.
872 metadata (Sequence[Tuple[str, str]]): Strings which should be
873 sent along with the request as metadata.
874
875 Returns:
876 google.api_core.operation_async.AsyncOperation:
877 An object representing a long-running operation.
878
879 The result type for the operation will be :class:`google.cloud.resourcemanager_v3.types.TagValue` A TagValue is a child of a particular TagKey. This is used to group
880 cloud resources for the purpose of controlling them
881 using policies.
882
883 """
884 # Create or coerce a protobuf request object.
885 # Quick check: If we got a request object, we should *not* have
886 # gotten any keyword arguments that map to the request.
887 has_flattened_params = any([name])
888 if request is not None and has_flattened_params:
889 raise ValueError(
890 "If the `request` argument is set, then none of "
891 "the individual field arguments should be set."
892 )
893
894 request = tag_values.DeleteTagValueRequest(request)
895
896 # If we have keyword arguments corresponding to fields on the
897 # request, apply these.
898 if name is not None:
899 request.name = name
900
901 # Wrap the RPC method; this adds retry and timeout information,
902 # and friendly error handling.
903 rpc = gapic_v1.method_async.wrap_method(
904 self._client._transport.delete_tag_value,
905 default_timeout=60.0,
906 client_info=DEFAULT_CLIENT_INFO,
907 )
908
909 # Certain fields should be provided within the metadata header;
910 # add these here.
911 metadata = tuple(metadata) + (
912 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
913 )
914
915 # Send the request.
916 response = await rpc(
917 request,
918 retry=retry,
919 timeout=timeout,
920 metadata=metadata,
921 )
922
923 # Wrap the response in an operation future.
924 response = operation_async.from_gapic(
925 response,
926 self._client._transport.operations_client,
927 tag_values.TagValue,
928 metadata_type=tag_values.DeleteTagValueMetadata,
929 )
930
931 # Done; return the response.
932 return response
933
934 async def get_iam_policy(
935 self,
936 request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None,
937 *,
938 resource: Optional[str] = None,
939 retry: OptionalRetry = gapic_v1.method.DEFAULT,
940 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
941 metadata: Sequence[Tuple[str, str]] = (),
942 ) -> policy_pb2.Policy:
943 r"""Gets the access control policy for a TagValue. The returned
944 policy may be empty if no such policy or resource exists. The
945 ``resource`` field should be the TagValue's resource name. For
946 example: ``tagValues/1234``. The caller must have the
947 ``cloudresourcemanager.googleapis.com/tagValues.getIamPolicy``
948 permission on the identified TagValue to get the access control
949 policy.
950
951 .. code-block:: python
952
953 # This snippet has been automatically generated and should be regarded as a
954 # code template only.
955 # It will require modifications to work:
956 # - It may require correct/in-range values for request initialization.
957 # - It may require specifying regional endpoints when creating the service
958 # client as shown in:
959 # https://googleapis.dev/python/google-api-core/latest/client_options.html
960 from google.cloud import resourcemanager_v3
961 from google.iam.v1 import iam_policy_pb2 # type: ignore
962
963 async def sample_get_iam_policy():
964 # Create a client
965 client = resourcemanager_v3.TagValuesAsyncClient()
966
967 # Initialize request argument(s)
968 request = iam_policy_pb2.GetIamPolicyRequest(
969 resource="resource_value",
970 )
971
972 # Make the request
973 response = await client.get_iam_policy(request=request)
974
975 # Handle the response
976 print(response)
977
978 Args:
979 request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]):
980 The request object. Request message for ``GetIamPolicy`` method.
981 resource (:class:`str`):
982 REQUIRED: The resource for which the
983 policy is being requested. See the
984 operation documentation for the
985 appropriate value for this field.
986
987 This corresponds to the ``resource`` field
988 on the ``request`` instance; if ``request`` is provided, this
989 should not be set.
990 retry (google.api_core.retry.Retry): Designation of what errors, if any,
991 should be retried.
992 timeout (float): The timeout for this request.
993 metadata (Sequence[Tuple[str, str]]): Strings which should be
994 sent along with the request as metadata.
995
996 Returns:
997 google.iam.v1.policy_pb2.Policy:
998 An Identity and Access Management (IAM) policy, which specifies access
999 controls for Google Cloud resources.
1000
1001 A Policy is a collection of bindings. A binding binds
1002 one or more members, or principals, to a single role.
1003 Principals can be user accounts, service accounts,
1004 Google groups, and domains (such as G Suite). A role
1005 is a named list of permissions; each role can be an
1006 IAM predefined role or a user-created custom role.
1007
1008 For some types of Google Cloud resources, a binding
1009 can also specify a condition, which is a logical
1010 expression that allows access to a resource only if
1011 the expression evaluates to true. A condition can add
1012 constraints based on attributes of the request, the
1013 resource, or both. To learn which resources support
1014 conditions in their IAM policies, see the [IAM
1015 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
1016
1017 **JSON example:**
1018
1019 {
1020 "bindings": [
1021 {
1022 "role":
1023 "roles/resourcemanager.organizationAdmin",
1024 "members": [ "user:mike@example.com",
1025 "group:admins@example.com",
1026 "domain:google.com",
1027 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1028 ]
1029
1030 }, { "role":
1031 "roles/resourcemanager.organizationViewer",
1032 "members": [ "user:eve@example.com" ],
1033 "condition": { "title": "expirable access",
1034 "description": "Does not grant access after
1035 Sep 2020", "expression": "request.time <
1036 timestamp('2020-10-01T00:00:00.000Z')", } }
1037
1038 ], "etag": "BwWWja0YfJA=", "version": 3
1039
1040 }
1041
1042 **YAML example:**
1043
1044 bindings: - members: - user:\ mike@example.com -
1045 group:\ admins@example.com - domain:google.com -
1046 serviceAccount:\ my-project-id@appspot.gserviceaccount.com
1047 role: roles/resourcemanager.organizationAdmin -
1048 members: - user:\ eve@example.com role:
1049 roles/resourcemanager.organizationViewer
1050 condition: title: expirable access description:
1051 Does not grant access after Sep 2020 expression:
1052 request.time <
1053 timestamp('2020-10-01T00:00:00.000Z') etag:
1054 BwWWja0YfJA= version: 3
1055
1056 For a description of IAM and its features, see the
1057 [IAM
1058 documentation](\ https://cloud.google.com/iam/docs/).
1059
1060 """
1061 # Create or coerce a protobuf request object.
1062 # Quick check: If we got a request object, we should *not* have
1063 # gotten any keyword arguments that map to the request.
1064 has_flattened_params = any([resource])
1065 if request is not None and has_flattened_params:
1066 raise ValueError(
1067 "If the `request` argument is set, then none of "
1068 "the individual field arguments should be set."
1069 )
1070
1071 # The request isn't a proto-plus wrapped type,
1072 # so it must be constructed via keyword expansion.
1073 if isinstance(request, dict):
1074 request = iam_policy_pb2.GetIamPolicyRequest(**request)
1075 elif not request:
1076 request = iam_policy_pb2.GetIamPolicyRequest(
1077 resource=resource,
1078 )
1079
1080 # Wrap the RPC method; this adds retry and timeout information,
1081 # and friendly error handling.
1082 rpc = gapic_v1.method_async.wrap_method(
1083 self._client._transport.get_iam_policy,
1084 default_retry=retries.Retry(
1085 initial=0.1,
1086 maximum=60.0,
1087 multiplier=1.3,
1088 predicate=retries.if_exception_type(
1089 core_exceptions.ServiceUnavailable,
1090 ),
1091 deadline=60.0,
1092 ),
1093 default_timeout=60.0,
1094 client_info=DEFAULT_CLIENT_INFO,
1095 )
1096
1097 # Certain fields should be provided within the metadata header;
1098 # add these here.
1099 metadata = tuple(metadata) + (
1100 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1101 )
1102
1103 # Send the request.
1104 response = await rpc(
1105 request,
1106 retry=retry,
1107 timeout=timeout,
1108 metadata=metadata,
1109 )
1110
1111 # Done; return the response.
1112 return response
1113
1114 async def set_iam_policy(
1115 self,
1116 request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None,
1117 *,
1118 resource: Optional[str] = None,
1119 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1120 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1121 metadata: Sequence[Tuple[str, str]] = (),
1122 ) -> policy_pb2.Policy:
1123 r"""Sets the access control policy on a TagValue, replacing any
1124 existing policy. The ``resource`` field should be the TagValue's
1125 resource name. For example: ``tagValues/1234``. The caller must
1126 have ``resourcemanager.tagValues.setIamPolicy`` permission on
1127 the identified tagValue.
1128
1129 .. code-block:: python
1130
1131 # This snippet has been automatically generated and should be regarded as a
1132 # code template only.
1133 # It will require modifications to work:
1134 # - It may require correct/in-range values for request initialization.
1135 # - It may require specifying regional endpoints when creating the service
1136 # client as shown in:
1137 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1138 from google.cloud import resourcemanager_v3
1139 from google.iam.v1 import iam_policy_pb2 # type: ignore
1140
1141 async def sample_set_iam_policy():
1142 # Create a client
1143 client = resourcemanager_v3.TagValuesAsyncClient()
1144
1145 # Initialize request argument(s)
1146 request = iam_policy_pb2.SetIamPolicyRequest(
1147 resource="resource_value",
1148 )
1149
1150 # Make the request
1151 response = await client.set_iam_policy(request=request)
1152
1153 # Handle the response
1154 print(response)
1155
1156 Args:
1157 request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]):
1158 The request object. Request message for ``SetIamPolicy`` method.
1159 resource (:class:`str`):
1160 REQUIRED: The resource for which the
1161 policy is being specified. See the
1162 operation documentation for the
1163 appropriate value for this field.
1164
1165 This corresponds to the ``resource`` field
1166 on the ``request`` instance; if ``request`` is provided, this
1167 should not be set.
1168 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1169 should be retried.
1170 timeout (float): The timeout for this request.
1171 metadata (Sequence[Tuple[str, str]]): Strings which should be
1172 sent along with the request as metadata.
1173
1174 Returns:
1175 google.iam.v1.policy_pb2.Policy:
1176 An Identity and Access Management (IAM) policy, which specifies access
1177 controls for Google Cloud resources.
1178
1179 A Policy is a collection of bindings. A binding binds
1180 one or more members, or principals, to a single role.
1181 Principals can be user accounts, service accounts,
1182 Google groups, and domains (such as G Suite). A role
1183 is a named list of permissions; each role can be an
1184 IAM predefined role or a user-created custom role.
1185
1186 For some types of Google Cloud resources, a binding
1187 can also specify a condition, which is a logical
1188 expression that allows access to a resource only if
1189 the expression evaluates to true. A condition can add
1190 constraints based on attributes of the request, the
1191 resource, or both. To learn which resources support
1192 conditions in their IAM policies, see the [IAM
1193 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
1194
1195 **JSON example:**
1196
1197 {
1198 "bindings": [
1199 {
1200 "role":
1201 "roles/resourcemanager.organizationAdmin",
1202 "members": [ "user:mike@example.com",
1203 "group:admins@example.com",
1204 "domain:google.com",
1205 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1206 ]
1207
1208 }, { "role":
1209 "roles/resourcemanager.organizationViewer",
1210 "members": [ "user:eve@example.com" ],
1211 "condition": { "title": "expirable access",
1212 "description": "Does not grant access after
1213 Sep 2020", "expression": "request.time <
1214 timestamp('2020-10-01T00:00:00.000Z')", } }
1215
1216 ], "etag": "BwWWja0YfJA=", "version": 3
1217
1218 }
1219
1220 **YAML example:**
1221
1222 bindings: - members: - user:\ mike@example.com -
1223 group:\ admins@example.com - domain:google.com -
1224 serviceAccount:\ my-project-id@appspot.gserviceaccount.com
1225 role: roles/resourcemanager.organizationAdmin -
1226 members: - user:\ eve@example.com role:
1227 roles/resourcemanager.organizationViewer
1228 condition: title: expirable access description:
1229 Does not grant access after Sep 2020 expression:
1230 request.time <
1231 timestamp('2020-10-01T00:00:00.000Z') etag:
1232 BwWWja0YfJA= version: 3
1233
1234 For a description of IAM and its features, see the
1235 [IAM
1236 documentation](\ https://cloud.google.com/iam/docs/).
1237
1238 """
1239 # Create or coerce a protobuf request object.
1240 # Quick check: If we got a request object, we should *not* have
1241 # gotten any keyword arguments that map to the request.
1242 has_flattened_params = any([resource])
1243 if request is not None and has_flattened_params:
1244 raise ValueError(
1245 "If the `request` argument is set, then none of "
1246 "the individual field arguments should be set."
1247 )
1248
1249 # The request isn't a proto-plus wrapped type,
1250 # so it must be constructed via keyword expansion.
1251 if isinstance(request, dict):
1252 request = iam_policy_pb2.SetIamPolicyRequest(**request)
1253 elif not request:
1254 request = iam_policy_pb2.SetIamPolicyRequest(
1255 resource=resource,
1256 )
1257
1258 # Wrap the RPC method; this adds retry and timeout information,
1259 # and friendly error handling.
1260 rpc = gapic_v1.method_async.wrap_method(
1261 self._client._transport.set_iam_policy,
1262 default_timeout=60.0,
1263 client_info=DEFAULT_CLIENT_INFO,
1264 )
1265
1266 # Certain fields should be provided within the metadata header;
1267 # add these here.
1268 metadata = tuple(metadata) + (
1269 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1270 )
1271
1272 # Send the request.
1273 response = await rpc(
1274 request,
1275 retry=retry,
1276 timeout=timeout,
1277 metadata=metadata,
1278 )
1279
1280 # Done; return the response.
1281 return response
1282
1283 async def test_iam_permissions(
1284 self,
1285 request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None,
1286 *,
1287 resource: Optional[str] = None,
1288 permissions: Optional[MutableSequence[str]] = None,
1289 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1290 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1291 metadata: Sequence[Tuple[str, str]] = (),
1292 ) -> iam_policy_pb2.TestIamPermissionsResponse:
1293 r"""Returns permissions that a caller has on the specified TagValue.
1294 The ``resource`` field should be the TagValue's resource name.
1295 For example: ``tagValues/1234``.
1296
1297 There are no permissions required for making this API call.
1298
1299 .. code-block:: python
1300
1301 # This snippet has been automatically generated and should be regarded as a
1302 # code template only.
1303 # It will require modifications to work:
1304 # - It may require correct/in-range values for request initialization.
1305 # - It may require specifying regional endpoints when creating the service
1306 # client as shown in:
1307 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1308 from google.cloud import resourcemanager_v3
1309 from google.iam.v1 import iam_policy_pb2 # type: ignore
1310
1311 async def sample_test_iam_permissions():
1312 # Create a client
1313 client = resourcemanager_v3.TagValuesAsyncClient()
1314
1315 # Initialize request argument(s)
1316 request = iam_policy_pb2.TestIamPermissionsRequest(
1317 resource="resource_value",
1318 permissions=['permissions_value1', 'permissions_value2'],
1319 )
1320
1321 # Make the request
1322 response = await client.test_iam_permissions(request=request)
1323
1324 # Handle the response
1325 print(response)
1326
1327 Args:
1328 request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]):
1329 The request object. Request message for ``TestIamPermissions`` method.
1330 resource (:class:`str`):
1331 REQUIRED: The resource for which the
1332 policy detail is being requested. See
1333 the operation documentation for the
1334 appropriate value for this field.
1335
1336 This corresponds to the ``resource`` field
1337 on the ``request`` instance; if ``request`` is provided, this
1338 should not be set.
1339 permissions (:class:`MutableSequence[str]`):
1340 The set of permissions to check for the ``resource``.
1341 Permissions with wildcards (such as '*' or 'storage.*')
1342 are not allowed. For more information see `IAM
1343 Overview <https://cloud.google.com/iam/docs/overview#permissions>`__.
1344
1345 This corresponds to the ``permissions`` field
1346 on the ``request`` instance; if ``request`` is provided, this
1347 should not be set.
1348 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1349 should be retried.
1350 timeout (float): The timeout for this request.
1351 metadata (Sequence[Tuple[str, str]]): Strings which should be
1352 sent along with the request as metadata.
1353
1354 Returns:
1355 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse:
1356 Response message for TestIamPermissions method.
1357 """
1358 # Create or coerce a protobuf request object.
1359 # Quick check: If we got a request object, we should *not* have
1360 # gotten any keyword arguments that map to the request.
1361 has_flattened_params = any([resource, permissions])
1362 if request is not None and has_flattened_params:
1363 raise ValueError(
1364 "If the `request` argument is set, then none of "
1365 "the individual field arguments should be set."
1366 )
1367
1368 # The request isn't a proto-plus wrapped type,
1369 # so it must be constructed via keyword expansion.
1370 if isinstance(request, dict):
1371 request = iam_policy_pb2.TestIamPermissionsRequest(**request)
1372 elif not request:
1373 request = iam_policy_pb2.TestIamPermissionsRequest(
1374 resource=resource,
1375 permissions=permissions,
1376 )
1377
1378 # Wrap the RPC method; this adds retry and timeout information,
1379 # and friendly error handling.
1380 rpc = gapic_v1.method_async.wrap_method(
1381 self._client._transport.test_iam_permissions,
1382 default_timeout=None,
1383 client_info=DEFAULT_CLIENT_INFO,
1384 )
1385
1386 # Certain fields should be provided within the metadata header;
1387 # add these here.
1388 metadata = tuple(metadata) + (
1389 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1390 )
1391
1392 # Send the request.
1393 response = await rpc(
1394 request,
1395 retry=retry,
1396 timeout=timeout,
1397 metadata=metadata,
1398 )
1399
1400 # Done; return the response.
1401 return response
1402
1403 async def get_operation(
1404 self,
1405 request: Optional[operations_pb2.GetOperationRequest] = None,
1406 *,
1407 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1408 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1409 metadata: Sequence[Tuple[str, str]] = (),
1410 ) -> operations_pb2.Operation:
1411 r"""Gets the latest state of a long-running operation.
1412
1413 Args:
1414 request (:class:`~.operations_pb2.GetOperationRequest`):
1415 The request object. Request message for
1416 `GetOperation` method.
1417 retry (google.api_core.retry.Retry): Designation of what errors,
1418 if any, should be retried.
1419 timeout (float): The timeout for this request.
1420 metadata (Sequence[Tuple[str, str]]): Strings which should be
1421 sent along with the request as metadata.
1422 Returns:
1423 ~.operations_pb2.Operation:
1424 An ``Operation`` object.
1425 """
1426 # Create or coerce a protobuf request object.
1427 # The request isn't a proto-plus wrapped type,
1428 # so it must be constructed via keyword expansion.
1429 if isinstance(request, dict):
1430 request = operations_pb2.GetOperationRequest(**request)
1431
1432 # Wrap the RPC method; this adds retry and timeout information,
1433 # and friendly error handling.
1434 rpc = gapic_v1.method.wrap_method(
1435 self._client._transport.get_operation,
1436 default_timeout=None,
1437 client_info=DEFAULT_CLIENT_INFO,
1438 )
1439
1440 # Certain fields should be provided within the metadata header;
1441 # add these here.
1442 metadata = tuple(metadata) + (
1443 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1444 )
1445
1446 # Send the request.
1447 response = await rpc(
1448 request,
1449 retry=retry,
1450 timeout=timeout,
1451 metadata=metadata,
1452 )
1453
1454 # Done; return the response.
1455 return response
1456
1457 async def __aenter__(self):
1458 return self
1459
1460 async def __aexit__(self, exc_type, exc, tb):
1461 await self.transport.close()
1462
1463
1464DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1465 gapic_version=package_version.__version__
1466)
1467
1468
1469__all__ = ("TagValuesAsyncClient",)