Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/tag_values/client.py: 63%
284 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-06 06:03 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-06 06:03 +0000
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 os
18import re
19from typing import (
20 Dict,
21 Mapping,
22 MutableMapping,
23 MutableSequence,
24 Optional,
25 Sequence,
26 Tuple,
27 Type,
28 Union,
29 cast,
30)
32from google.api_core import client_options as client_options_lib
33from google.api_core import exceptions as core_exceptions
34from google.api_core import gapic_v1
35from google.api_core import retry as retries
36from google.auth import credentials as ga_credentials # type: ignore
37from google.auth.exceptions import MutualTLSChannelError # type: ignore
38from google.auth.transport import mtls # type: ignore
39from google.auth.transport.grpc import SslCredentials # type: ignore
40from google.oauth2 import service_account # type: ignore
42from google.cloud.resourcemanager_v3 import gapic_version as package_version
44try:
45 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
46except AttributeError: # pragma: NO COVER
47 OptionalRetry = Union[retries.Retry, object] # type: ignore
49from google.api_core import operation # type: ignore
50from google.api_core import operation_async # type: ignore
51from google.iam.v1 import iam_policy_pb2 # type: ignore
52from google.iam.v1 import policy_pb2 # type: ignore
53from google.longrunning import operations_pb2
54from google.protobuf import field_mask_pb2 # type: ignore
55from google.protobuf import timestamp_pb2 # type: ignore
57from google.cloud.resourcemanager_v3.services.tag_values import pagers
58from google.cloud.resourcemanager_v3.types import tag_values
60from .transports.base import DEFAULT_CLIENT_INFO, TagValuesTransport
61from .transports.grpc import TagValuesGrpcTransport
62from .transports.grpc_asyncio import TagValuesGrpcAsyncIOTransport
63from .transports.rest import TagValuesRestTransport
66class TagValuesClientMeta(type):
67 """Metaclass for the TagValues client.
69 This provides class-level methods for building and retrieving
70 support objects (e.g. transport) without polluting the client instance
71 objects.
72 """
74 _transport_registry = OrderedDict() # type: Dict[str, Type[TagValuesTransport]]
75 _transport_registry["grpc"] = TagValuesGrpcTransport
76 _transport_registry["grpc_asyncio"] = TagValuesGrpcAsyncIOTransport
77 _transport_registry["rest"] = TagValuesRestTransport
79 def get_transport_class(
80 cls,
81 label: Optional[str] = None,
82 ) -> Type[TagValuesTransport]:
83 """Returns an appropriate transport class.
85 Args:
86 label: The name of the desired transport. If none is
87 provided, then the first transport in the registry is used.
89 Returns:
90 The transport class to use.
91 """
92 # If a specific transport is requested, return that one.
93 if label:
94 return cls._transport_registry[label]
96 # No transport is requested; return the default (that is, the first one
97 # in the dictionary).
98 return next(iter(cls._transport_registry.values()))
101class TagValuesClient(metaclass=TagValuesClientMeta):
102 """Allow users to create and manage tag values."""
104 @staticmethod
105 def _get_default_mtls_endpoint(api_endpoint):
106 """Converts api endpoint to mTLS endpoint.
108 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
109 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
110 Args:
111 api_endpoint (Optional[str]): the api endpoint to convert.
112 Returns:
113 str: converted mTLS api endpoint.
114 """
115 if not api_endpoint:
116 return api_endpoint
118 mtls_endpoint_re = re.compile(
119 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
120 )
122 m = mtls_endpoint_re.match(api_endpoint)
123 name, mtls, sandbox, googledomain = m.groups()
124 if mtls or not googledomain:
125 return api_endpoint
127 if sandbox:
128 return api_endpoint.replace(
129 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
130 )
132 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
134 DEFAULT_ENDPOINT = "cloudresourcemanager.googleapis.com"
135 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
136 DEFAULT_ENDPOINT
137 )
139 @classmethod
140 def from_service_account_info(cls, info: dict, *args, **kwargs):
141 """Creates an instance of this client using the provided credentials
142 info.
144 Args:
145 info (dict): The service account private key info.
146 args: Additional arguments to pass to the constructor.
147 kwargs: Additional arguments to pass to the constructor.
149 Returns:
150 TagValuesClient: The constructed client.
151 """
152 credentials = service_account.Credentials.from_service_account_info(info)
153 kwargs["credentials"] = credentials
154 return cls(*args, **kwargs)
156 @classmethod
157 def from_service_account_file(cls, filename: str, *args, **kwargs):
158 """Creates an instance of this client using the provided credentials
159 file.
161 Args:
162 filename (str): The path to the service account private key json
163 file.
164 args: Additional arguments to pass to the constructor.
165 kwargs: Additional arguments to pass to the constructor.
167 Returns:
168 TagValuesClient: The constructed client.
169 """
170 credentials = service_account.Credentials.from_service_account_file(filename)
171 kwargs["credentials"] = credentials
172 return cls(*args, **kwargs)
174 from_service_account_json = from_service_account_file
176 @property
177 def transport(self) -> TagValuesTransport:
178 """Returns the transport used by the client instance.
180 Returns:
181 TagValuesTransport: The transport used by the client
182 instance.
183 """
184 return self._transport
186 @staticmethod
187 def tag_value_path(
188 tag_value: str,
189 ) -> str:
190 """Returns a fully-qualified tag_value string."""
191 return "tagValues/{tag_value}".format(
192 tag_value=tag_value,
193 )
195 @staticmethod
196 def parse_tag_value_path(path: str) -> Dict[str, str]:
197 """Parses a tag_value path into its component segments."""
198 m = re.match(r"^tagValues/(?P<tag_value>.+?)$", path)
199 return m.groupdict() if m else {}
201 @staticmethod
202 def common_billing_account_path(
203 billing_account: str,
204 ) -> str:
205 """Returns a fully-qualified billing_account string."""
206 return "billingAccounts/{billing_account}".format(
207 billing_account=billing_account,
208 )
210 @staticmethod
211 def parse_common_billing_account_path(path: str) -> Dict[str, str]:
212 """Parse a billing_account path into its component segments."""
213 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
214 return m.groupdict() if m else {}
216 @staticmethod
217 def common_folder_path(
218 folder: str,
219 ) -> str:
220 """Returns a fully-qualified folder string."""
221 return "folders/{folder}".format(
222 folder=folder,
223 )
225 @staticmethod
226 def parse_common_folder_path(path: str) -> Dict[str, str]:
227 """Parse a folder path into its component segments."""
228 m = re.match(r"^folders/(?P<folder>.+?)$", path)
229 return m.groupdict() if m else {}
231 @staticmethod
232 def common_organization_path(
233 organization: str,
234 ) -> str:
235 """Returns a fully-qualified organization string."""
236 return "organizations/{organization}".format(
237 organization=organization,
238 )
240 @staticmethod
241 def parse_common_organization_path(path: str) -> Dict[str, str]:
242 """Parse a organization path into its component segments."""
243 m = re.match(r"^organizations/(?P<organization>.+?)$", path)
244 return m.groupdict() if m else {}
246 @staticmethod
247 def common_project_path(
248 project: str,
249 ) -> str:
250 """Returns a fully-qualified project string."""
251 return "projects/{project}".format(
252 project=project,
253 )
255 @staticmethod
256 def parse_common_project_path(path: str) -> Dict[str, str]:
257 """Parse a project path into its component segments."""
258 m = re.match(r"^projects/(?P<project>.+?)$", path)
259 return m.groupdict() if m else {}
261 @staticmethod
262 def common_location_path(
263 project: str,
264 location: str,
265 ) -> str:
266 """Returns a fully-qualified location string."""
267 return "projects/{project}/locations/{location}".format(
268 project=project,
269 location=location,
270 )
272 @staticmethod
273 def parse_common_location_path(path: str) -> Dict[str, str]:
274 """Parse a location path into its component segments."""
275 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
276 return m.groupdict() if m else {}
278 @classmethod
279 def get_mtls_endpoint_and_cert_source(
280 cls, client_options: Optional[client_options_lib.ClientOptions] = None
281 ):
282 """Return the API endpoint and client cert source for mutual TLS.
284 The client cert source is determined in the following order:
285 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
286 client cert source is None.
287 (2) if `client_options.client_cert_source` is provided, use the provided one; if the
288 default client cert source exists, use the default one; otherwise the client cert
289 source is None.
291 The API endpoint is determined in the following order:
292 (1) if `client_options.api_endpoint` if provided, use the provided one.
293 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
294 default mTLS endpoint; if the environment variable is "never", use the default API
295 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
296 use the default API endpoint.
298 More details can be found at https://google.aip.dev/auth/4114.
300 Args:
301 client_options (google.api_core.client_options.ClientOptions): Custom options for the
302 client. Only the `api_endpoint` and `client_cert_source` properties may be used
303 in this method.
305 Returns:
306 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
307 client cert source to use.
309 Raises:
310 google.auth.exceptions.MutualTLSChannelError: If any errors happen.
311 """
312 if client_options is None:
313 client_options = client_options_lib.ClientOptions()
314 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
315 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
316 if use_client_cert not in ("true", "false"):
317 raise ValueError(
318 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
319 )
320 if use_mtls_endpoint not in ("auto", "never", "always"):
321 raise MutualTLSChannelError(
322 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
323 )
325 # Figure out the client cert source to use.
326 client_cert_source = None
327 if use_client_cert == "true":
328 if client_options.client_cert_source:
329 client_cert_source = client_options.client_cert_source
330 elif mtls.has_default_client_cert_source():
331 client_cert_source = mtls.default_client_cert_source()
333 # Figure out which api endpoint to use.
334 if client_options.api_endpoint is not None:
335 api_endpoint = client_options.api_endpoint
336 elif use_mtls_endpoint == "always" or (
337 use_mtls_endpoint == "auto" and client_cert_source
338 ):
339 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
340 else:
341 api_endpoint = cls.DEFAULT_ENDPOINT
343 return api_endpoint, client_cert_source
345 def __init__(
346 self,
347 *,
348 credentials: Optional[ga_credentials.Credentials] = None,
349 transport: Optional[Union[str, TagValuesTransport]] = None,
350 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
351 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
352 ) -> None:
353 """Instantiates the tag values client.
355 Args:
356 credentials (Optional[google.auth.credentials.Credentials]): The
357 authorization credentials to attach to requests. These
358 credentials identify the application to the service; if none
359 are specified, the client will attempt to ascertain the
360 credentials from the environment.
361 transport (Union[str, TagValuesTransport]): The
362 transport to use. If set to None, a transport is chosen
363 automatically.
364 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the
365 client. It won't take effect if a ``transport`` instance is provided.
366 (1) The ``api_endpoint`` property can be used to override the
367 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
368 environment variable can also be used to override the endpoint:
369 "always" (always use the default mTLS endpoint), "never" (always
370 use the default regular endpoint) and "auto" (auto switch to the
371 default mTLS endpoint if client certificate is present, this is
372 the default value). However, the ``api_endpoint`` property takes
373 precedence if provided.
374 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
375 is "true", then the ``client_cert_source`` property can be used
376 to provide client certificate for mutual TLS transport. If
377 not provided, the default SSL client certificate will be used if
378 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
379 set, no client certificate will be used.
380 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
381 The client info used to send a user-agent string along with
382 API requests. If ``None``, then default info will be used.
383 Generally, you only need to set this if you're developing
384 your own client library.
386 Raises:
387 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
388 creation failed for any reason.
389 """
390 if isinstance(client_options, dict):
391 client_options = client_options_lib.from_dict(client_options)
392 if client_options is None:
393 client_options = client_options_lib.ClientOptions()
394 client_options = cast(client_options_lib.ClientOptions, client_options)
396 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(
397 client_options
398 )
400 api_key_value = getattr(client_options, "api_key", None)
401 if api_key_value and credentials:
402 raise ValueError(
403 "client_options.api_key and credentials are mutually exclusive"
404 )
406 # Save or instantiate the transport.
407 # Ordinarily, we provide the transport, but allowing a custom transport
408 # instance provides an extensibility point for unusual situations.
409 if isinstance(transport, TagValuesTransport):
410 # transport is a TagValuesTransport instance.
411 if credentials or client_options.credentials_file or api_key_value:
412 raise ValueError(
413 "When providing a transport instance, "
414 "provide its credentials directly."
415 )
416 if client_options.scopes:
417 raise ValueError(
418 "When providing a transport instance, provide its scopes "
419 "directly."
420 )
421 self._transport = transport
422 else:
423 import google.auth._default # type: ignore
425 if api_key_value and hasattr(
426 google.auth._default, "get_api_key_credentials"
427 ):
428 credentials = google.auth._default.get_api_key_credentials(
429 api_key_value
430 )
432 Transport = type(self).get_transport_class(transport)
433 self._transport = Transport(
434 credentials=credentials,
435 credentials_file=client_options.credentials_file,
436 host=api_endpoint,
437 scopes=client_options.scopes,
438 client_cert_source_for_mtls=client_cert_source_func,
439 quota_project_id=client_options.quota_project_id,
440 client_info=client_info,
441 always_use_jwt_access=True,
442 api_audience=client_options.api_audience,
443 )
445 def list_tag_values(
446 self,
447 request: Optional[Union[tag_values.ListTagValuesRequest, dict]] = None,
448 *,
449 parent: Optional[str] = None,
450 retry: OptionalRetry = gapic_v1.method.DEFAULT,
451 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
452 metadata: Sequence[Tuple[str, str]] = (),
453 ) -> pagers.ListTagValuesPager:
454 r"""Lists all TagValues for a specific TagKey.
456 .. code-block:: python
458 # This snippet has been automatically generated and should be regarded as a
459 # code template only.
460 # It will require modifications to work:
461 # - It may require correct/in-range values for request initialization.
462 # - It may require specifying regional endpoints when creating the service
463 # client as shown in:
464 # https://googleapis.dev/python/google-api-core/latest/client_options.html
465 from google.cloud import resourcemanager_v3
467 def sample_list_tag_values():
468 # Create a client
469 client = resourcemanager_v3.TagValuesClient()
471 # Initialize request argument(s)
472 request = resourcemanager_v3.ListTagValuesRequest(
473 parent="parent_value",
474 )
476 # Make the request
477 page_result = client.list_tag_values(request=request)
479 # Handle the response
480 for response in page_result:
481 print(response)
483 Args:
484 request (Union[google.cloud.resourcemanager_v3.types.ListTagValuesRequest, dict]):
485 The request object. The request message for listing TagValues for the
486 specified TagKey. Resource name for TagKey, parent of
487 the TagValues to be listed, in the format
488 ``tagKeys/123``.
489 parent (str):
490 Required.
491 This corresponds to the ``parent`` field
492 on the ``request`` instance; if ``request`` is provided, this
493 should not be set.
494 retry (google.api_core.retry.Retry): Designation of what errors, if any,
495 should be retried.
496 timeout (float): The timeout for this request.
497 metadata (Sequence[Tuple[str, str]]): Strings which should be
498 sent along with the request as metadata.
500 Returns:
501 google.cloud.resourcemanager_v3.services.tag_values.pagers.ListTagValuesPager:
502 The ListTagValues response.
503 Iterating over this object will yield
504 results and resolve additional pages
505 automatically.
507 """
508 # Create or coerce a protobuf request object.
509 # Quick check: If we got a request object, we should *not* have
510 # gotten any keyword arguments that map to the request.
511 has_flattened_params = any([parent])
512 if request is not None and has_flattened_params:
513 raise ValueError(
514 "If the `request` argument is set, then none of "
515 "the individual field arguments should be set."
516 )
518 # Minor optimization to avoid making a copy if the user passes
519 # in a tag_values.ListTagValuesRequest.
520 # There's no risk of modifying the input as we've already verified
521 # there are no flattened fields.
522 if not isinstance(request, tag_values.ListTagValuesRequest):
523 request = tag_values.ListTagValuesRequest(request)
524 # If we have keyword arguments corresponding to fields on the
525 # request, apply these.
526 if parent is not None:
527 request.parent = parent
529 # Wrap the RPC method; this adds retry and timeout information,
530 # and friendly error handling.
531 rpc = self._transport._wrapped_methods[self._transport.list_tag_values]
533 # Send the request.
534 response = rpc(
535 request,
536 retry=retry,
537 timeout=timeout,
538 metadata=metadata,
539 )
541 # This method is paged; wrap the response in a pager, which provides
542 # an `__iter__` convenience method.
543 response = pagers.ListTagValuesPager(
544 method=rpc,
545 request=request,
546 response=response,
547 metadata=metadata,
548 )
550 # Done; return the response.
551 return response
553 def get_tag_value(
554 self,
555 request: Optional[Union[tag_values.GetTagValueRequest, dict]] = None,
556 *,
557 name: Optional[str] = None,
558 retry: OptionalRetry = gapic_v1.method.DEFAULT,
559 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
560 metadata: Sequence[Tuple[str, str]] = (),
561 ) -> tag_values.TagValue:
562 r"""Retrieves a TagValue. This method will return
563 ``PERMISSION_DENIED`` if the value does not exist or the user
564 does not have permission to view it.
566 .. code-block:: python
568 # This snippet has been automatically generated and should be regarded as a
569 # code template only.
570 # It will require modifications to work:
571 # - It may require correct/in-range values for request initialization.
572 # - It may require specifying regional endpoints when creating the service
573 # client as shown in:
574 # https://googleapis.dev/python/google-api-core/latest/client_options.html
575 from google.cloud import resourcemanager_v3
577 def sample_get_tag_value():
578 # Create a client
579 client = resourcemanager_v3.TagValuesClient()
581 # Initialize request argument(s)
582 request = resourcemanager_v3.GetTagValueRequest(
583 name="name_value",
584 )
586 # Make the request
587 response = client.get_tag_value(request=request)
589 # Handle the response
590 print(response)
592 Args:
593 request (Union[google.cloud.resourcemanager_v3.types.GetTagValueRequest, dict]):
594 The request object. The request message for getting a
595 TagValue.
596 name (str):
597 Required. Resource name for TagValue to be fetched in
598 the format ``tagValues/456``.
600 This corresponds to the ``name`` field
601 on the ``request`` instance; if ``request`` is provided, this
602 should not be set.
603 retry (google.api_core.retry.Retry): Designation of what errors, if any,
604 should be retried.
605 timeout (float): The timeout for this request.
606 metadata (Sequence[Tuple[str, str]]): Strings which should be
607 sent along with the request as metadata.
609 Returns:
610 google.cloud.resourcemanager_v3.types.TagValue:
611 A TagValue is a child of a particular
612 TagKey. This is used to group cloud
613 resources for the purpose of controlling
614 them using policies.
616 """
617 # Create or coerce a protobuf request object.
618 # Quick check: If we got a request object, we should *not* have
619 # gotten any keyword arguments that map to the request.
620 has_flattened_params = any([name])
621 if request is not None and has_flattened_params:
622 raise ValueError(
623 "If the `request` argument is set, then none of "
624 "the individual field arguments should be set."
625 )
627 # Minor optimization to avoid making a copy if the user passes
628 # in a tag_values.GetTagValueRequest.
629 # There's no risk of modifying the input as we've already verified
630 # there are no flattened fields.
631 if not isinstance(request, tag_values.GetTagValueRequest):
632 request = tag_values.GetTagValueRequest(request)
633 # If we have keyword arguments corresponding to fields on the
634 # request, apply these.
635 if name is not None:
636 request.name = name
638 # Wrap the RPC method; this adds retry and timeout information,
639 # and friendly error handling.
640 rpc = self._transport._wrapped_methods[self._transport.get_tag_value]
642 # Certain fields should be provided within the metadata header;
643 # add these here.
644 metadata = tuple(metadata) + (
645 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
646 )
648 # Send the request.
649 response = rpc(
650 request,
651 retry=retry,
652 timeout=timeout,
653 metadata=metadata,
654 )
656 # Done; return the response.
657 return response
659 def get_namespaced_tag_value(
660 self,
661 request: Optional[Union[tag_values.GetNamespacedTagValueRequest, dict]] = None,
662 *,
663 name: Optional[str] = None,
664 retry: OptionalRetry = gapic_v1.method.DEFAULT,
665 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
666 metadata: Sequence[Tuple[str, str]] = (),
667 ) -> tag_values.TagValue:
668 r"""Retrieves a TagValue by its namespaced name. This method will
669 return ``PERMISSION_DENIED`` if the value does not exist or the
670 user does not have permission to view it.
672 .. code-block:: python
674 # This snippet has been automatically generated and should be regarded as a
675 # code template only.
676 # It will require modifications to work:
677 # - It may require correct/in-range values for request initialization.
678 # - It may require specifying regional endpoints when creating the service
679 # client as shown in:
680 # https://googleapis.dev/python/google-api-core/latest/client_options.html
681 from google.cloud import resourcemanager_v3
683 def sample_get_namespaced_tag_value():
684 # Create a client
685 client = resourcemanager_v3.TagValuesClient()
687 # Initialize request argument(s)
688 request = resourcemanager_v3.GetNamespacedTagValueRequest(
689 name="name_value",
690 )
692 # Make the request
693 response = client.get_namespaced_tag_value(request=request)
695 # Handle the response
696 print(response)
698 Args:
699 request (Union[google.cloud.resourcemanager_v3.types.GetNamespacedTagValueRequest, dict]):
700 The request object. The request message for getting a
701 TagValue by its namespaced name.
702 name (str):
703 Required. A namespaced tag value name in the following
704 format:
706 ``{parentId}/{tagKeyShort}/{tagValueShort}``
708 Examples:
710 - ``42/foo/abc`` for a value with short name "abc"
711 under the key with short name "foo" under the
712 organization with ID 42
713 - ``r2-d2/bar/xyz`` for a value with short name "xyz"
714 under the key with short name "bar" under the project
715 with ID "r2-d2"
717 This corresponds to the ``name`` field
718 on the ``request`` instance; if ``request`` is provided, this
719 should not be set.
720 retry (google.api_core.retry.Retry): Designation of what errors, if any,
721 should be retried.
722 timeout (float): The timeout for this request.
723 metadata (Sequence[Tuple[str, str]]): Strings which should be
724 sent along with the request as metadata.
726 Returns:
727 google.cloud.resourcemanager_v3.types.TagValue:
728 A TagValue is a child of a particular
729 TagKey. This is used to group cloud
730 resources for the purpose of controlling
731 them using policies.
733 """
734 # Create or coerce a protobuf request object.
735 # Quick check: If we got a request object, we should *not* have
736 # gotten any keyword arguments that map to the request.
737 has_flattened_params = any([name])
738 if request is not None and has_flattened_params:
739 raise ValueError(
740 "If the `request` argument is set, then none of "
741 "the individual field arguments should be set."
742 )
744 # Minor optimization to avoid making a copy if the user passes
745 # in a tag_values.GetNamespacedTagValueRequest.
746 # There's no risk of modifying the input as we've already verified
747 # there are no flattened fields.
748 if not isinstance(request, tag_values.GetNamespacedTagValueRequest):
749 request = tag_values.GetNamespacedTagValueRequest(request)
750 # If we have keyword arguments corresponding to fields on the
751 # request, apply these.
752 if name is not None:
753 request.name = name
755 # Wrap the RPC method; this adds retry and timeout information,
756 # and friendly error handling.
757 rpc = self._transport._wrapped_methods[self._transport.get_namespaced_tag_value]
759 # Send the request.
760 response = rpc(
761 request,
762 retry=retry,
763 timeout=timeout,
764 metadata=metadata,
765 )
767 # Done; return the response.
768 return response
770 def create_tag_value(
771 self,
772 request: Optional[Union[tag_values.CreateTagValueRequest, dict]] = None,
773 *,
774 tag_value: Optional[tag_values.TagValue] = None,
775 retry: OptionalRetry = gapic_v1.method.DEFAULT,
776 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
777 metadata: Sequence[Tuple[str, str]] = (),
778 ) -> operation.Operation:
779 r"""Creates a TagValue as a child of the specified
780 TagKey. If a another request with the same parameters is
781 sent while the original request is in process the second
782 request will receive an error. A maximum of 1000
783 TagValues can exist under a TagKey at any given time.
785 .. code-block:: python
787 # This snippet has been automatically generated and should be regarded as a
788 # code template only.
789 # It will require modifications to work:
790 # - It may require correct/in-range values for request initialization.
791 # - It may require specifying regional endpoints when creating the service
792 # client as shown in:
793 # https://googleapis.dev/python/google-api-core/latest/client_options.html
794 from google.cloud import resourcemanager_v3
796 def sample_create_tag_value():
797 # Create a client
798 client = resourcemanager_v3.TagValuesClient()
800 # Initialize request argument(s)
801 tag_value = resourcemanager_v3.TagValue()
802 tag_value.short_name = "short_name_value"
804 request = resourcemanager_v3.CreateTagValueRequest(
805 tag_value=tag_value,
806 )
808 # Make the request
809 operation = client.create_tag_value(request=request)
811 print("Waiting for operation to complete...")
813 response = operation.result()
815 # Handle the response
816 print(response)
818 Args:
819 request (Union[google.cloud.resourcemanager_v3.types.CreateTagValueRequest, dict]):
820 The request object. The request message for creating a
821 TagValue.
822 tag_value (google.cloud.resourcemanager_v3.types.TagValue):
823 Required. The TagValue to be created. Only fields
824 ``short_name``, ``description``, and ``parent`` are
825 considered during the creation request.
827 This corresponds to the ``tag_value`` field
828 on the ``request`` instance; if ``request`` is provided, this
829 should not be set.
830 retry (google.api_core.retry.Retry): Designation of what errors, if any,
831 should be retried.
832 timeout (float): The timeout for this request.
833 metadata (Sequence[Tuple[str, str]]): Strings which should be
834 sent along with the request as metadata.
836 Returns:
837 google.api_core.operation.Operation:
838 An object representing a long-running operation.
840 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
841 cloud resources for the purpose of controlling them
842 using policies.
844 """
845 # Create or coerce a protobuf request object.
846 # Quick check: If we got a request object, we should *not* have
847 # gotten any keyword arguments that map to the request.
848 has_flattened_params = any([tag_value])
849 if request is not None and has_flattened_params:
850 raise ValueError(
851 "If the `request` argument is set, then none of "
852 "the individual field arguments should be set."
853 )
855 # Minor optimization to avoid making a copy if the user passes
856 # in a tag_values.CreateTagValueRequest.
857 # There's no risk of modifying the input as we've already verified
858 # there are no flattened fields.
859 if not isinstance(request, tag_values.CreateTagValueRequest):
860 request = tag_values.CreateTagValueRequest(request)
861 # If we have keyword arguments corresponding to fields on the
862 # request, apply these.
863 if tag_value is not None:
864 request.tag_value = tag_value
866 # Wrap the RPC method; this adds retry and timeout information,
867 # and friendly error handling.
868 rpc = self._transport._wrapped_methods[self._transport.create_tag_value]
870 # Send the request.
871 response = rpc(
872 request,
873 retry=retry,
874 timeout=timeout,
875 metadata=metadata,
876 )
878 # Wrap the response in an operation future.
879 response = operation.from_gapic(
880 response,
881 self._transport.operations_client,
882 tag_values.TagValue,
883 metadata_type=tag_values.CreateTagValueMetadata,
884 )
886 # Done; return the response.
887 return response
889 def update_tag_value(
890 self,
891 request: Optional[Union[tag_values.UpdateTagValueRequest, dict]] = None,
892 *,
893 tag_value: Optional[tag_values.TagValue] = None,
894 update_mask: Optional[field_mask_pb2.FieldMask] = None,
895 retry: OptionalRetry = gapic_v1.method.DEFAULT,
896 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
897 metadata: Sequence[Tuple[str, str]] = (),
898 ) -> operation.Operation:
899 r"""Updates the attributes of the TagValue resource.
901 .. code-block:: python
903 # This snippet has been automatically generated and should be regarded as a
904 # code template only.
905 # It will require modifications to work:
906 # - It may require correct/in-range values for request initialization.
907 # - It may require specifying regional endpoints when creating the service
908 # client as shown in:
909 # https://googleapis.dev/python/google-api-core/latest/client_options.html
910 from google.cloud import resourcemanager_v3
912 def sample_update_tag_value():
913 # Create a client
914 client = resourcemanager_v3.TagValuesClient()
916 # Initialize request argument(s)
917 tag_value = resourcemanager_v3.TagValue()
918 tag_value.short_name = "short_name_value"
920 request = resourcemanager_v3.UpdateTagValueRequest(
921 tag_value=tag_value,
922 )
924 # Make the request
925 operation = client.update_tag_value(request=request)
927 print("Waiting for operation to complete...")
929 response = operation.result()
931 # Handle the response
932 print(response)
934 Args:
935 request (Union[google.cloud.resourcemanager_v3.types.UpdateTagValueRequest, dict]):
936 The request object. The request message for updating a
937 TagValue.
938 tag_value (google.cloud.resourcemanager_v3.types.TagValue):
939 Required. The new definition of the TagValue. Only
940 fields ``description`` and ``etag`` fields can be
941 updated by this request. If the ``etag`` field is
942 nonempty, it must match the ``etag`` field of the
943 existing ControlGroup. Otherwise, ``ABORTED`` will be
944 returned.
946 This corresponds to the ``tag_value`` field
947 on the ``request`` instance; if ``request`` is provided, this
948 should not be set.
949 update_mask (google.protobuf.field_mask_pb2.FieldMask):
950 Optional. Fields to be updated.
951 This corresponds to the ``update_mask`` field
952 on the ``request`` instance; if ``request`` is provided, this
953 should not be set.
954 retry (google.api_core.retry.Retry): Designation of what errors, if any,
955 should be retried.
956 timeout (float): The timeout for this request.
957 metadata (Sequence[Tuple[str, str]]): Strings which should be
958 sent along with the request as metadata.
960 Returns:
961 google.api_core.operation.Operation:
962 An object representing a long-running operation.
964 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
965 cloud resources for the purpose of controlling them
966 using policies.
968 """
969 # Create or coerce a protobuf request object.
970 # Quick check: If we got a request object, we should *not* have
971 # gotten any keyword arguments that map to the request.
972 has_flattened_params = any([tag_value, update_mask])
973 if request is not None and has_flattened_params:
974 raise ValueError(
975 "If the `request` argument is set, then none of "
976 "the individual field arguments should be set."
977 )
979 # Minor optimization to avoid making a copy if the user passes
980 # in a tag_values.UpdateTagValueRequest.
981 # There's no risk of modifying the input as we've already verified
982 # there are no flattened fields.
983 if not isinstance(request, tag_values.UpdateTagValueRequest):
984 request = tag_values.UpdateTagValueRequest(request)
985 # If we have keyword arguments corresponding to fields on the
986 # request, apply these.
987 if tag_value is not None:
988 request.tag_value = tag_value
989 if update_mask is not None:
990 request.update_mask = update_mask
992 # Wrap the RPC method; this adds retry and timeout information,
993 # and friendly error handling.
994 rpc = self._transport._wrapped_methods[self._transport.update_tag_value]
996 # Certain fields should be provided within the metadata header;
997 # add these here.
998 metadata = tuple(metadata) + (
999 gapic_v1.routing_header.to_grpc_metadata(
1000 (("tag_value.name", request.tag_value.name),)
1001 ),
1002 )
1004 # Send the request.
1005 response = rpc(
1006 request,
1007 retry=retry,
1008 timeout=timeout,
1009 metadata=metadata,
1010 )
1012 # Wrap the response in an operation future.
1013 response = operation.from_gapic(
1014 response,
1015 self._transport.operations_client,
1016 tag_values.TagValue,
1017 metadata_type=tag_values.UpdateTagValueMetadata,
1018 )
1020 # Done; return the response.
1021 return response
1023 def delete_tag_value(
1024 self,
1025 request: Optional[Union[tag_values.DeleteTagValueRequest, dict]] = None,
1026 *,
1027 name: Optional[str] = None,
1028 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1029 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1030 metadata: Sequence[Tuple[str, str]] = (),
1031 ) -> operation.Operation:
1032 r"""Deletes a TagValue. The TagValue cannot have any
1033 bindings when it is deleted.
1035 .. code-block:: python
1037 # This snippet has been automatically generated and should be regarded as a
1038 # code template only.
1039 # It will require modifications to work:
1040 # - It may require correct/in-range values for request initialization.
1041 # - It may require specifying regional endpoints when creating the service
1042 # client as shown in:
1043 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1044 from google.cloud import resourcemanager_v3
1046 def sample_delete_tag_value():
1047 # Create a client
1048 client = resourcemanager_v3.TagValuesClient()
1050 # Initialize request argument(s)
1051 request = resourcemanager_v3.DeleteTagValueRequest(
1052 name="name_value",
1053 )
1055 # Make the request
1056 operation = client.delete_tag_value(request=request)
1058 print("Waiting for operation to complete...")
1060 response = operation.result()
1062 # Handle the response
1063 print(response)
1065 Args:
1066 request (Union[google.cloud.resourcemanager_v3.types.DeleteTagValueRequest, dict]):
1067 The request object. The request message for deleting a
1068 TagValue.
1069 name (str):
1070 Required. Resource name for TagValue
1071 to be deleted in the format
1072 tagValues/456.
1074 This corresponds to the ``name`` field
1075 on the ``request`` instance; if ``request`` is provided, this
1076 should not be set.
1077 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1078 should be retried.
1079 timeout (float): The timeout for this request.
1080 metadata (Sequence[Tuple[str, str]]): Strings which should be
1081 sent along with the request as metadata.
1083 Returns:
1084 google.api_core.operation.Operation:
1085 An object representing a long-running operation.
1087 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
1088 cloud resources for the purpose of controlling them
1089 using policies.
1091 """
1092 # Create or coerce a protobuf request object.
1093 # Quick check: If we got a request object, we should *not* have
1094 # gotten any keyword arguments that map to the request.
1095 has_flattened_params = any([name])
1096 if request is not None and has_flattened_params:
1097 raise ValueError(
1098 "If the `request` argument is set, then none of "
1099 "the individual field arguments should be set."
1100 )
1102 # Minor optimization to avoid making a copy if the user passes
1103 # in a tag_values.DeleteTagValueRequest.
1104 # There's no risk of modifying the input as we've already verified
1105 # there are no flattened fields.
1106 if not isinstance(request, tag_values.DeleteTagValueRequest):
1107 request = tag_values.DeleteTagValueRequest(request)
1108 # If we have keyword arguments corresponding to fields on the
1109 # request, apply these.
1110 if name is not None:
1111 request.name = name
1113 # Wrap the RPC method; this adds retry and timeout information,
1114 # and friendly error handling.
1115 rpc = self._transport._wrapped_methods[self._transport.delete_tag_value]
1117 # Certain fields should be provided within the metadata header;
1118 # add these here.
1119 metadata = tuple(metadata) + (
1120 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1121 )
1123 # Send the request.
1124 response = rpc(
1125 request,
1126 retry=retry,
1127 timeout=timeout,
1128 metadata=metadata,
1129 )
1131 # Wrap the response in an operation future.
1132 response = operation.from_gapic(
1133 response,
1134 self._transport.operations_client,
1135 tag_values.TagValue,
1136 metadata_type=tag_values.DeleteTagValueMetadata,
1137 )
1139 # Done; return the response.
1140 return response
1142 def get_iam_policy(
1143 self,
1144 request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None,
1145 *,
1146 resource: Optional[str] = None,
1147 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1148 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1149 metadata: Sequence[Tuple[str, str]] = (),
1150 ) -> policy_pb2.Policy:
1151 r"""Gets the access control policy for a TagValue. The returned
1152 policy may be empty if no such policy or resource exists. The
1153 ``resource`` field should be the TagValue's resource name. For
1154 example: ``tagValues/1234``. The caller must have the
1155 ``cloudresourcemanager.googleapis.com/tagValues.getIamPolicy``
1156 permission on the identified TagValue to get the access control
1157 policy.
1159 .. code-block:: python
1161 # This snippet has been automatically generated and should be regarded as a
1162 # code template only.
1163 # It will require modifications to work:
1164 # - It may require correct/in-range values for request initialization.
1165 # - It may require specifying regional endpoints when creating the service
1166 # client as shown in:
1167 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1168 from google.cloud import resourcemanager_v3
1169 from google.iam.v1 import iam_policy_pb2 # type: ignore
1171 def sample_get_iam_policy():
1172 # Create a client
1173 client = resourcemanager_v3.TagValuesClient()
1175 # Initialize request argument(s)
1176 request = iam_policy_pb2.GetIamPolicyRequest(
1177 resource="resource_value",
1178 )
1180 # Make the request
1181 response = client.get_iam_policy(request=request)
1183 # Handle the response
1184 print(response)
1186 Args:
1187 request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]):
1188 The request object. Request message for ``GetIamPolicy`` method.
1189 resource (str):
1190 REQUIRED: The resource for which the
1191 policy is being requested. See the
1192 operation documentation for the
1193 appropriate value for this field.
1195 This corresponds to the ``resource`` field
1196 on the ``request`` instance; if ``request`` is provided, this
1197 should not be set.
1198 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1199 should be retried.
1200 timeout (float): The timeout for this request.
1201 metadata (Sequence[Tuple[str, str]]): Strings which should be
1202 sent along with the request as metadata.
1204 Returns:
1205 google.iam.v1.policy_pb2.Policy:
1206 An Identity and Access Management (IAM) policy, which specifies access
1207 controls for Google Cloud resources.
1209 A Policy is a collection of bindings. A binding binds
1210 one or more members, or principals, to a single role.
1211 Principals can be user accounts, service accounts,
1212 Google groups, and domains (such as G Suite). A role
1213 is a named list of permissions; each role can be an
1214 IAM predefined role or a user-created custom role.
1216 For some types of Google Cloud resources, a binding
1217 can also specify a condition, which is a logical
1218 expression that allows access to a resource only if
1219 the expression evaluates to true. A condition can add
1220 constraints based on attributes of the request, the
1221 resource, or both. To learn which resources support
1222 conditions in their IAM policies, see the [IAM
1223 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
1225 **JSON example:**
1227 {
1228 "bindings": [
1229 {
1230 "role":
1231 "roles/resourcemanager.organizationAdmin",
1232 "members": [ "user:mike@example.com",
1233 "group:admins@example.com",
1234 "domain:google.com",
1235 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1236 ]
1238 }, { "role":
1239 "roles/resourcemanager.organizationViewer",
1240 "members": [ "user:eve@example.com" ],
1241 "condition": { "title": "expirable access",
1242 "description": "Does not grant access after
1243 Sep 2020", "expression": "request.time <
1244 timestamp('2020-10-01T00:00:00.000Z')", } }
1246 ], "etag": "BwWWja0YfJA=", "version": 3
1248 }
1250 **YAML example:**
1252 bindings: - members: - user:\ mike@example.com -
1253 group:\ admins@example.com - domain:google.com -
1254 serviceAccount:\ my-project-id@appspot.gserviceaccount.com
1255 role: roles/resourcemanager.organizationAdmin -
1256 members: - user:\ eve@example.com role:
1257 roles/resourcemanager.organizationViewer
1258 condition: title: expirable access description:
1259 Does not grant access after Sep 2020 expression:
1260 request.time <
1261 timestamp('2020-10-01T00:00:00.000Z') etag:
1262 BwWWja0YfJA= version: 3
1264 For a description of IAM and its features, see the
1265 [IAM
1266 documentation](\ https://cloud.google.com/iam/docs/).
1268 """
1269 # Create or coerce a protobuf request object.
1270 # Quick check: If we got a request object, we should *not* have
1271 # gotten any keyword arguments that map to the request.
1272 has_flattened_params = any([resource])
1273 if request is not None and has_flattened_params:
1274 raise ValueError(
1275 "If the `request` argument is set, then none of "
1276 "the individual field arguments should be set."
1277 )
1279 if isinstance(request, dict):
1280 # The request isn't a proto-plus wrapped type,
1281 # so it must be constructed via keyword expansion.
1282 request = iam_policy_pb2.GetIamPolicyRequest(**request)
1283 elif not request:
1284 # Null request, just make one.
1285 request = iam_policy_pb2.GetIamPolicyRequest()
1286 if resource is not None:
1287 request.resource = resource
1289 # Wrap the RPC method; this adds retry and timeout information,
1290 # and friendly error handling.
1291 rpc = self._transport._wrapped_methods[self._transport.get_iam_policy]
1293 # Certain fields should be provided within the metadata header;
1294 # add these here.
1295 metadata = tuple(metadata) + (
1296 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1297 )
1299 # Send the request.
1300 response = rpc(
1301 request,
1302 retry=retry,
1303 timeout=timeout,
1304 metadata=metadata,
1305 )
1307 # Done; return the response.
1308 return response
1310 def set_iam_policy(
1311 self,
1312 request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None,
1313 *,
1314 resource: Optional[str] = None,
1315 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1316 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1317 metadata: Sequence[Tuple[str, str]] = (),
1318 ) -> policy_pb2.Policy:
1319 r"""Sets the access control policy on a TagValue, replacing any
1320 existing policy. The ``resource`` field should be the TagValue's
1321 resource name. For example: ``tagValues/1234``. The caller must
1322 have ``resourcemanager.tagValues.setIamPolicy`` permission on
1323 the identified tagValue.
1325 .. code-block:: python
1327 # This snippet has been automatically generated and should be regarded as a
1328 # code template only.
1329 # It will require modifications to work:
1330 # - It may require correct/in-range values for request initialization.
1331 # - It may require specifying regional endpoints when creating the service
1332 # client as shown in:
1333 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1334 from google.cloud import resourcemanager_v3
1335 from google.iam.v1 import iam_policy_pb2 # type: ignore
1337 def sample_set_iam_policy():
1338 # Create a client
1339 client = resourcemanager_v3.TagValuesClient()
1341 # Initialize request argument(s)
1342 request = iam_policy_pb2.SetIamPolicyRequest(
1343 resource="resource_value",
1344 )
1346 # Make the request
1347 response = client.set_iam_policy(request=request)
1349 # Handle the response
1350 print(response)
1352 Args:
1353 request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]):
1354 The request object. Request message for ``SetIamPolicy`` method.
1355 resource (str):
1356 REQUIRED: The resource for which the
1357 policy is being specified. See the
1358 operation documentation for the
1359 appropriate value for this field.
1361 This corresponds to the ``resource`` field
1362 on the ``request`` instance; if ``request`` is provided, this
1363 should not be set.
1364 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1365 should be retried.
1366 timeout (float): The timeout for this request.
1367 metadata (Sequence[Tuple[str, str]]): Strings which should be
1368 sent along with the request as metadata.
1370 Returns:
1371 google.iam.v1.policy_pb2.Policy:
1372 An Identity and Access Management (IAM) policy, which specifies access
1373 controls for Google Cloud resources.
1375 A Policy is a collection of bindings. A binding binds
1376 one or more members, or principals, to a single role.
1377 Principals can be user accounts, service accounts,
1378 Google groups, and domains (such as G Suite). A role
1379 is a named list of permissions; each role can be an
1380 IAM predefined role or a user-created custom role.
1382 For some types of Google Cloud resources, a binding
1383 can also specify a condition, which is a logical
1384 expression that allows access to a resource only if
1385 the expression evaluates to true. A condition can add
1386 constraints based on attributes of the request, the
1387 resource, or both. To learn which resources support
1388 conditions in their IAM policies, see the [IAM
1389 documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies).
1391 **JSON example:**
1393 {
1394 "bindings": [
1395 {
1396 "role":
1397 "roles/resourcemanager.organizationAdmin",
1398 "members": [ "user:mike@example.com",
1399 "group:admins@example.com",
1400 "domain:google.com",
1401 "serviceAccount:my-project-id@appspot.gserviceaccount.com"
1402 ]
1404 }, { "role":
1405 "roles/resourcemanager.organizationViewer",
1406 "members": [ "user:eve@example.com" ],
1407 "condition": { "title": "expirable access",
1408 "description": "Does not grant access after
1409 Sep 2020", "expression": "request.time <
1410 timestamp('2020-10-01T00:00:00.000Z')", } }
1412 ], "etag": "BwWWja0YfJA=", "version": 3
1414 }
1416 **YAML example:**
1418 bindings: - members: - user:\ mike@example.com -
1419 group:\ admins@example.com - domain:google.com -
1420 serviceAccount:\ my-project-id@appspot.gserviceaccount.com
1421 role: roles/resourcemanager.organizationAdmin -
1422 members: - user:\ eve@example.com role:
1423 roles/resourcemanager.organizationViewer
1424 condition: title: expirable access description:
1425 Does not grant access after Sep 2020 expression:
1426 request.time <
1427 timestamp('2020-10-01T00:00:00.000Z') etag:
1428 BwWWja0YfJA= version: 3
1430 For a description of IAM and its features, see the
1431 [IAM
1432 documentation](\ https://cloud.google.com/iam/docs/).
1434 """
1435 # Create or coerce a protobuf request object.
1436 # Quick check: If we got a request object, we should *not* have
1437 # gotten any keyword arguments that map to the request.
1438 has_flattened_params = any([resource])
1439 if request is not None and has_flattened_params:
1440 raise ValueError(
1441 "If the `request` argument is set, then none of "
1442 "the individual field arguments should be set."
1443 )
1445 if isinstance(request, dict):
1446 # The request isn't a proto-plus wrapped type,
1447 # so it must be constructed via keyword expansion.
1448 request = iam_policy_pb2.SetIamPolicyRequest(**request)
1449 elif not request:
1450 # Null request, just make one.
1451 request = iam_policy_pb2.SetIamPolicyRequest()
1452 if resource is not None:
1453 request.resource = resource
1455 # Wrap the RPC method; this adds retry and timeout information,
1456 # and friendly error handling.
1457 rpc = self._transport._wrapped_methods[self._transport.set_iam_policy]
1459 # Certain fields should be provided within the metadata header;
1460 # add these here.
1461 metadata = tuple(metadata) + (
1462 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1463 )
1465 # Send the request.
1466 response = rpc(
1467 request,
1468 retry=retry,
1469 timeout=timeout,
1470 metadata=metadata,
1471 )
1473 # Done; return the response.
1474 return response
1476 def test_iam_permissions(
1477 self,
1478 request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None,
1479 *,
1480 resource: Optional[str] = None,
1481 permissions: Optional[MutableSequence[str]] = None,
1482 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1483 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1484 metadata: Sequence[Tuple[str, str]] = (),
1485 ) -> iam_policy_pb2.TestIamPermissionsResponse:
1486 r"""Returns permissions that a caller has on the specified TagValue.
1487 The ``resource`` field should be the TagValue's resource name.
1488 For example: ``tagValues/1234``.
1490 There are no permissions required for making this API call.
1492 .. code-block:: python
1494 # This snippet has been automatically generated and should be regarded as a
1495 # code template only.
1496 # It will require modifications to work:
1497 # - It may require correct/in-range values for request initialization.
1498 # - It may require specifying regional endpoints when creating the service
1499 # client as shown in:
1500 # https://googleapis.dev/python/google-api-core/latest/client_options.html
1501 from google.cloud import resourcemanager_v3
1502 from google.iam.v1 import iam_policy_pb2 # type: ignore
1504 def sample_test_iam_permissions():
1505 # Create a client
1506 client = resourcemanager_v3.TagValuesClient()
1508 # Initialize request argument(s)
1509 request = iam_policy_pb2.TestIamPermissionsRequest(
1510 resource="resource_value",
1511 permissions=['permissions_value1', 'permissions_value2'],
1512 )
1514 # Make the request
1515 response = client.test_iam_permissions(request=request)
1517 # Handle the response
1518 print(response)
1520 Args:
1521 request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]):
1522 The request object. Request message for ``TestIamPermissions`` method.
1523 resource (str):
1524 REQUIRED: The resource for which the
1525 policy detail is being requested. See
1526 the operation documentation for the
1527 appropriate value for this field.
1529 This corresponds to the ``resource`` field
1530 on the ``request`` instance; if ``request`` is provided, this
1531 should not be set.
1532 permissions (MutableSequence[str]):
1533 The set of permissions to check for the ``resource``.
1534 Permissions with wildcards (such as '*' or 'storage.*')
1535 are not allowed. For more information see `IAM
1536 Overview <https://cloud.google.com/iam/docs/overview#permissions>`__.
1538 This corresponds to the ``permissions`` field
1539 on the ``request`` instance; if ``request`` is provided, this
1540 should not be set.
1541 retry (google.api_core.retry.Retry): Designation of what errors, if any,
1542 should be retried.
1543 timeout (float): The timeout for this request.
1544 metadata (Sequence[Tuple[str, str]]): Strings which should be
1545 sent along with the request as metadata.
1547 Returns:
1548 google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse:
1549 Response message for TestIamPermissions method.
1550 """
1551 # Create or coerce a protobuf request object.
1552 # Quick check: If we got a request object, we should *not* have
1553 # gotten any keyword arguments that map to the request.
1554 has_flattened_params = any([resource, permissions])
1555 if request is not None and has_flattened_params:
1556 raise ValueError(
1557 "If the `request` argument is set, then none of "
1558 "the individual field arguments should be set."
1559 )
1561 if isinstance(request, dict):
1562 # The request isn't a proto-plus wrapped type,
1563 # so it must be constructed via keyword expansion.
1564 request = iam_policy_pb2.TestIamPermissionsRequest(**request)
1565 elif not request:
1566 # Null request, just make one.
1567 request = iam_policy_pb2.TestIamPermissionsRequest()
1568 if resource is not None:
1569 request.resource = resource
1570 if permissions:
1571 request.permissions.extend(permissions)
1573 # Wrap the RPC method; this adds retry and timeout information,
1574 # and friendly error handling.
1575 rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions]
1577 # Certain fields should be provided within the metadata header;
1578 # add these here.
1579 metadata = tuple(metadata) + (
1580 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
1581 )
1583 # Send the request.
1584 response = rpc(
1585 request,
1586 retry=retry,
1587 timeout=timeout,
1588 metadata=metadata,
1589 )
1591 # Done; return the response.
1592 return response
1594 def __enter__(self) -> "TagValuesClient":
1595 return self
1597 def __exit__(self, type, value, traceback):
1598 """Releases underlying transport's resources.
1600 .. warning::
1601 ONLY use as a context manager if the transport is NOT shared
1602 with other clients! Exiting the with block will CLOSE the transport
1603 and may cause errors in other clients!
1604 """
1605 self.transport.close()
1607 def get_operation(
1608 self,
1609 request: Optional[operations_pb2.GetOperationRequest] = None,
1610 *,
1611 retry: OptionalRetry = gapic_v1.method.DEFAULT,
1612 timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1613 metadata: Sequence[Tuple[str, str]] = (),
1614 ) -> operations_pb2.Operation:
1615 r"""Gets the latest state of a long-running operation.
1617 Args:
1618 request (:class:`~.operations_pb2.GetOperationRequest`):
1619 The request object. Request message for
1620 `GetOperation` method.
1621 retry (google.api_core.retry.Retry): Designation of what errors,
1622 if any, should be retried.
1623 timeout (float): The timeout for this request.
1624 metadata (Sequence[Tuple[str, str]]): Strings which should be
1625 sent along with the request as metadata.
1626 Returns:
1627 ~.operations_pb2.Operation:
1628 An ``Operation`` object.
1629 """
1630 # Create or coerce a protobuf request object.
1631 # The request isn't a proto-plus wrapped type,
1632 # so it must be constructed via keyword expansion.
1633 if isinstance(request, dict):
1634 request = operations_pb2.GetOperationRequest(**request)
1636 # Wrap the RPC method; this adds retry and timeout information,
1637 # and friendly error handling.
1638 rpc = gapic_v1.method.wrap_method(
1639 self._transport.get_operation,
1640 default_timeout=None,
1641 client_info=DEFAULT_CLIENT_INFO,
1642 )
1644 # Certain fields should be provided within the metadata header;
1645 # add these here.
1646 metadata = tuple(metadata) + (
1647 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1648 )
1650 # Send the request.
1651 response = rpc(
1652 request,
1653 retry=retry,
1654 timeout=timeout,
1655 metadata=metadata,
1656 )
1658 # Done; return the response.
1659 return response
1662DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1663 gapic_version=package_version.__version__
1664)
1667__all__ = ("TagValuesClient",)