diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/client.py b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/client.py index 378aa58f3ae9..9c92ba62207e 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/client.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/client.py @@ -539,6 +539,7 @@ def __init__( quota_project_id=client_options.quota_project_id, client_info=client_info, always_use_jwt_access=True, + api_audience=client_options.api_audience, ) def get_revision( @@ -623,11 +624,19 @@ def sample_get_revision(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_revision] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.name) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -726,11 +735,19 @@ def sample_list_revisions(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_revisions] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.parent) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -840,11 +857,19 @@ def sample_delete_revision(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_revision] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.name) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/base.py b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/base.py index af36691bda44..6ee1fcbc3e39 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/base.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/base.py @@ -56,6 +56,7 @@ def __init__( quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, **kwargs, ) -> None: """Instantiate the transport. @@ -83,11 +84,6 @@ def __init__( be used for service account credentials. """ - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ":" not in host: - host += ":443" - self._host = host - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. @@ -108,6 +104,11 @@ def __init__( credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience( + api_audience if api_audience else host + ) # If the credentials are service account credentials, then always try to use self signed JWT. if ( @@ -120,6 +121,11 @@ def __init__( # Save the credentials. self._credentials = credentials + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc.py b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc.py index 0755113b4d47..ee2217cf5a57 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc.py @@ -60,6 +60,7 @@ def __init__( quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, ) -> None: """Instantiate the transport. @@ -156,6 +157,7 @@ def __init__( quota_project_id=quota_project_id, client_info=client_info, always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, ) if not self._grpc_channel: diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc_asyncio.py b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc_asyncio.py index f7f633eaf41c..cafd1589f908 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc_asyncio.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/revisions/transports/grpc_asyncio.py @@ -105,6 +105,7 @@ def __init__( quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, ) -> None: """Instantiate the transport. @@ -201,6 +202,7 @@ def __init__( quota_project_id=quota_project_id, client_info=client_info, always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, ) if not self._grpc_channel: diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/services/async_client.py b/packages/google-cloud-run/google/cloud/run_v2/services/services/async_client.py index e2cccd8b9e1e..1a8c904c1a36 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/services/async_client.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/services/async_client.py @@ -43,7 +43,6 @@ from google.cloud.run_v2.types import vendor_settings from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ServicesTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import ServicesGrpcAsyncIOTransport @@ -592,7 +591,6 @@ async def update_service( request: Union[gcr_service.UpdateServiceRequest, dict] = None, *, service: gcr_service.Service = None, - update_mask: field_mask_pb2.FieldMask = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -630,11 +628,6 @@ async def sample_update_service(): This corresponds to the ``service`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - The list of fields to be updated. - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -657,7 +650,7 @@ async def sample_update_service(): # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([service, update_mask]) + has_flattened_params = any([service]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -670,8 +663,6 @@ async def sample_update_service(): # request, apply these. if service is not None: request.service = service - if update_mask is not None: - request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/services/client.py b/packages/google-cloud-run/google/cloud/run_v2/services/services/client.py index 8bce853c65dd..a2962fe0a219 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/services/client.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/services/client.py @@ -46,7 +46,6 @@ from google.cloud.run_v2.types import vendor_settings from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import ServicesTransport, DEFAULT_CLIENT_INFO from .transports.grpc import ServicesGrpcTransport @@ -543,6 +542,7 @@ def __init__( quota_project_id=client_options.quota_project_id, client_info=client_info, always_use_jwt_access=True, + api_audience=client_options.api_audience, ) def create_service( @@ -659,11 +659,19 @@ def sample_create_service(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.create_service] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)$" ) + regex_match = routing_param_regex.match(request.parent) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -770,11 +778,19 @@ def sample_get_service(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_service] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.name) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -872,11 +888,19 @@ def sample_list_services(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_services] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)$" ) + regex_match = routing_param_regex.match(request.parent) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -903,7 +927,6 @@ def update_service( request: Union[gcr_service.UpdateServiceRequest, dict] = None, *, service: gcr_service.Service = None, - update_mask: field_mask_pb2.FieldMask = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), @@ -941,11 +964,6 @@ def sample_update_service(): This corresponds to the ``service`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The list of fields to be updated. - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. @@ -968,7 +986,7 @@ def sample_update_service(): # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([service, update_mask]) + has_flattened_params = any([service]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -985,20 +1003,24 @@ def sample_update_service(): # request, apply these. if service is not None: request.service = service - if update_mask is not None: - request.update_mask = update_mask # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.update_service] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("service.name", request.service.name),) - ), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.service.name) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( @@ -1111,11 +1133,19 @@ def sample_delete_service(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_service] - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + header_params = {} + + routing_param_regex = re.compile( + "^projects/[^/]+/locations/(?P[^/]+)(?:/.*)?$" ) + regex_match = routing_param_regex.match(request.name) + if regex_match and regex_match.group("location"): + header_params["location"] = regex_match.group("location") + + if header_params: + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(header_params), + ) # Send the request. response = rpc( diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/base.py b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/base.py index 0dd32fc9f46c..6c0c1c6aae4d 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/base.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/base.py @@ -59,6 +59,7 @@ def __init__( quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, **kwargs, ) -> None: """Instantiate the transport. @@ -86,11 +87,6 @@ def __init__( be used for service account credentials. """ - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ":" not in host: - host += ":443" - self._host = host - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. @@ -111,6 +107,11 @@ def __init__( credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience( + api_audience if api_audience else host + ) # If the credentials are service account credentials, then always try to use self signed JWT. if ( @@ -123,6 +124,11 @@ def __init__( # Save the credentials. self._credentials = credentials + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc.py b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc.py index 0c0daf0e841c..622a46b36746 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc.py @@ -63,6 +63,7 @@ def __init__( quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, ) -> None: """Instantiate the transport. @@ -159,6 +160,7 @@ def __init__( quota_project_id=quota_project_id, client_info=client_info, always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, ) if not self._grpc_channel: diff --git a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc_asyncio.py b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc_asyncio.py index 5681b7c3474a..538fe94f9f50 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc_asyncio.py +++ b/packages/google-cloud-run/google/cloud/run_v2/services/services/transports/grpc_asyncio.py @@ -108,6 +108,7 @@ def __init__( quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, ) -> None: """Instantiate the transport. @@ -204,6 +205,7 @@ def __init__( quota_project_id=quota_project_id, client_info=client_info, always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, ) if not self._grpc_channel: diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/condition.py b/packages/google-cloud-run/google/cloud/run_v2/types/condition.py index 87b6d2217b28..9ded5b5adcb5 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/condition.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/condition.py @@ -59,14 +59,6 @@ class Condition(proto.Message): A common (service-level) reason for this condition. - This field is a member of `oneof`_ ``reasons``. - internal_reason (google.cloud.run_v2.types.Condition.InternalReason): - A reason for the internal condition. - - This field is a member of `oneof`_ ``reasons``. - domain_mapping_reason (google.cloud.run_v2.types.Condition.DomainMappingReason): - A reason for the domain mapping condition. - This field is a member of `oneof`_ ``reasons``. revision_reason (google.cloud.run_v2.types.Condition.RevisionReason): A reason for the revision condition. @@ -97,10 +89,8 @@ class CommonReason(proto.Enum): r"""Reasons common to all types of conditions.""" COMMON_REASON_UNDEFINED = 0 UNKNOWN = 1 - ROUTE_MISSING = 2 REVISION_FAILED = 3 PROGRESS_DEADLINE_EXCEEDED = 4 - BUILD_STEP_FAILED = 5 CONTAINER_MISSING = 6 CONTAINER_PERMISSION_DENIED = 7 CONTAINER_IMAGE_UNAUTHORIZED = 8 @@ -111,30 +101,7 @@ class CommonReason(proto.Enum): WAITING_FOR_OPERATION = 13 IMMEDIATE_RETRY = 14 POSTPONED_RETRY = 15 - - class InternalReason(proto.Enum): - r"""Reasons applicable to internal resources not exposed to - users. These will surface in Service.conditions, and could be - useful for further diagnosis. - """ - INTERNAL_REASON_UNDEFINED = 0 - CONFLICTING_REVISION_NAME = 1 - REVISION_MISSING = 2 - CONFIGURATION_MISSING = 3 - ASSIGNING_TRAFFIC = 4 - UPDATING_INGRESS_TRAFFIC_ALLOWED = 5 - REVISION_ORG_POLICY_VIOLATION = 6 - ENABLING_GCFV2_URI_SUPPORT = 7 - - class DomainMappingReason(proto.Enum): - r"""Reasons specific to DomainMapping resource.""" - DOMAIN_MAPPING_REASON_UNDEFINED = 0 - ROUTE_NOT_READY = 1 - PERMISSION_DENIED = 2 - CERTIFICATE_ALREADY_EXISTS = 3 - MAPPING_ALREADY_EXISTS = 4 - CERTIFICATE_PENDING = 5 - CERTIFICATE_FAILED = 6 + INTERNAL = 16 class RevisionReason(proto.Enum): r"""Reasons specific to Revision resource.""" @@ -186,18 +153,6 @@ class ExecutionReason(proto.Enum): oneof="reasons", enum=CommonReason, ) - internal_reason = proto.Field( - proto.ENUM, - number=7, - oneof="reasons", - enum=InternalReason, - ) - domain_mapping_reason = proto.Field( - proto.ENUM, - number=8, - oneof="reasons", - enum=DomainMappingReason, - ) revision_reason = proto.Field( proto.ENUM, number=9, diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/k8s_min.py b/packages/google-cloud-run/google/cloud/run_v2/types/k8s_min.py index e1be02075134..966361f861fb 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/k8s_min.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/k8s_min.py @@ -46,7 +46,8 @@ class Container(proto.Message): Name of the container specified as a DNS_LABEL. image (str): Required. URL of the Container image in - Google Container Registry or Docker More info: + Google Container Registry or Google Artifact + Registry. More info: https://kubernetes.io/docs/concepts/containers/images command (Sequence[str]): Entrypoint array. Not executed within a shell. The docker @@ -457,7 +458,7 @@ class CloudSqlInstance(proto.Message): r"""Represents a specific Cloud SQL instance. Attributes: - connections (Sequence[str]): + instances (Sequence[str]): The Cloud SQL instance connection names, as can be found in https://console.cloud.google.com/sql/instances. @@ -468,7 +469,7 @@ class CloudSqlInstance(proto.Message): {project}:{location}:{instance} """ - connections = proto.RepeatedField( + instances = proto.RepeatedField( proto.STRING, number=1, ) diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/revision.py b/packages/google-cloud-run/google/cloud/run_v2/types/revision.py index d0670ec4a8a7..e4ea93e90a8c 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/revision.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/revision.py @@ -212,7 +212,7 @@ class Revision(proto.Message): VPC Access configuration for this Revision. For more information, visit https://cloud.google.com/run/docs/configuring/connecting-vpc. - container_concurrency (int): + max_instance_request_concurrency (int): Sets the maximum number of requests that each serving instance can receive. timeout (google.protobuf.duration_pb2.Duration): @@ -230,9 +230,6 @@ class Revision(proto.Message): volumes (Sequence[google.cloud.run_v2.types.Volume]): A list of Volumes to make available to containers. - confidential (bool): - Indicates whether Confidential Cloud Run is - enabled in this Revision. execution_environment (google.cloud.run_v2.types.ExecutionEnvironment): The execution environment being used to host this Revision. @@ -326,9 +323,9 @@ class Revision(proto.Message): number=13, message=vendor_settings.VpcAccess, ) - container_concurrency = proto.Field( + max_instance_request_concurrency = proto.Field( proto.INT32, - number=14, + number=34, ) timeout = proto.Field( proto.MESSAGE, @@ -349,10 +346,6 @@ class Revision(proto.Message): number=18, message=k8s_min.Volume, ) - confidential = proto.Field( - proto.BOOL, - number=19, - ) execution_environment = proto.Field( proto.ENUM, number=20, diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/revision_template.py b/packages/google-cloud-run/google/cloud/run_v2/types/revision_template.py index a526b82f75f1..2245f8f8f0ac 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/revision_template.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/revision_template.py @@ -47,9 +47,6 @@ class RevisionTemplate(proto.Message): VPC Access configuration to use for this Revision. For more information, visit https://cloud.google.com/run/docs/configuring/connecting-vpc. - container_concurrency (int): - Sets the maximum number of requests that each - serving instance can receive. timeout (google.protobuf.duration_pb2.Duration): Max allowed time for an instance to respond to a request. @@ -67,9 +64,6 @@ class RevisionTemplate(proto.Message): volumes (Sequence[google.cloud.run_v2.types.Volume]): A list of Volumes to make available to containers. - confidential (bool): - Enables Confidential Cloud Run in Revisions - created using this template. execution_environment (google.cloud.run_v2.types.ExecutionEnvironment): The sandbox environment to host this Revision. @@ -78,6 +72,9 @@ class RevisionTemplate(proto.Message): key (CMEK) to use to encrypt this container image. For more information, go to https://cloud.google.com/run/docs/securing/using-cmek + max_instance_request_concurrency (int): + Sets the maximum number of requests that each + serving instance can receive. """ revision = proto.Field( @@ -104,10 +101,6 @@ class RevisionTemplate(proto.Message): number=6, message=vendor_settings.VpcAccess, ) - container_concurrency = proto.Field( - proto.INT32, - number=7, - ) timeout = proto.Field( proto.MESSAGE, number=8, @@ -127,10 +120,6 @@ class RevisionTemplate(proto.Message): number=11, message=k8s_min.Volume, ) - confidential = proto.Field( - proto.BOOL, - number=12, - ) execution_environment = proto.Field( proto.ENUM, number=13, @@ -140,6 +129,10 @@ class RevisionTemplate(proto.Message): proto.STRING, number=14, ) + max_instance_request_concurrency = proto.Field( + proto.INT32, + number=15, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/service.py b/packages/google-cloud-run/google/cloud/run_v2/types/service.py index 3a77ee48cd52..9c993fc3fb97 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/service.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/service.py @@ -20,7 +20,6 @@ from google.cloud.run_v2.types import revision_template from google.cloud.run_v2.types import traffic_target from google.cloud.run_v2.types import vendor_settings -from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -83,8 +82,6 @@ class UpdateServiceRequest(proto.Message): Attributes: service (google.cloud.run_v2.types.Service): Required. The Service to be updated. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - The list of fields to be updated. validate_only (bool): Indicates that the request should be validated and default values populated, without @@ -102,11 +99,6 @@ class UpdateServiceRequest(proto.Message): number=1, message="Service", ) - update_mask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) validate_only = proto.Field( proto.BOOL, number=3, @@ -255,9 +247,11 @@ class Service(proto.Message): string and guaranteed to remain unchanged until the resource is deleted. generation (int): - Output only. A number that monotonically - increases every time the user modifies the - desired state. + Output only. A number that monotonically increases every + time the user modifies the desired state. Please note that + unlike v1, this is an int64 value. As with most Google APIs, + its JSON representation will be a ``string`` instead of an + ``integer``. labels (Mapping[str, str]): Map of string keys and values that can be used to organize and categorize objects. @@ -327,7 +321,9 @@ class Service(proto.Message): Output only. The generation of this Service currently serving traffic. See comments in ``reconciling`` for additional information on reconciliation process in Cloud - Run. + Run. Please note that unlike v1, this is an int64 value. As + with most Google APIs, its JSON representation will be a + ``string`` instead of an ``integer``. terminal_condition (google.cloud.run_v2.types.Condition): Output only. The Condition of this Service, containing its readiness status, and detailed error information in case it diff --git a/packages/google-cloud-run/google/cloud/run_v2/types/vendor_settings.py b/packages/google-cloud-run/google/cloud/run_v2/types/vendor_settings.py index bc26b2be508a..51da1e924b4c 100644 --- a/packages/google-cloud-run/google/cloud/run_v2/types/vendor_settings.py +++ b/packages/google-cloud-run/google/cloud/run_v2/types/vendor_settings.py @@ -39,7 +39,7 @@ class IngressTraffic(proto.Enum): class ExecutionEnvironment(proto.Enum): r"""Alternatives for execution environments.""" EXECUTION_ENVIRONMENT_UNSPECIFIED = 0 - EXECUTION_ENVIRONMENT_DEFAULT = 1 + EXECUTION_ENVIRONMENT_GEN1 = 1 EXECUTION_ENVIRONMENT_GEN2 = 2 diff --git a/packages/google-cloud-run/samples/generated_samples/snippet_metadata_run_v2.json b/packages/google-cloud-run/samples/generated_samples/snippet_metadata_run_v2.json index 8b95cfc9e480..1435f0f356d0 100644 --- a/packages/google-cloud-run/samples/generated_samples/snippet_metadata_run_v2.json +++ b/packages/google-cloud-run/samples/generated_samples/snippet_metadata_run_v2.json @@ -1638,10 +1638,6 @@ "name": "service", "type": "google.cloud.run_v2.types.Service" }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, { "name": "retry", "type": "google.api_core.retry.Retry" @@ -1722,10 +1718,6 @@ "name": "service", "type": "google.cloud.run_v2.types.Service" }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, { "name": "retry", "type": "google.api_core.retry.Retry" diff --git a/packages/google-cloud-run/scripts/fixup_run_v2_keywords.py b/packages/google-cloud-run/scripts/fixup_run_v2_keywords.py index aef6ae6e6729..771b0bc31e76 100644 --- a/packages/google-cloud-run/scripts/fixup_run_v2_keywords.py +++ b/packages/google-cloud-run/scripts/fixup_run_v2_keywords.py @@ -49,7 +49,7 @@ class runCallTransformer(cst.CSTTransformer): 'list_services': ('parent', 'page_size', 'page_token', 'show_deleted', ), 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'test_iam_permissions': ('resource', 'permissions', ), - 'update_service': ('service', 'update_mask', 'validate_only', 'allow_missing', ), + 'update_service': ('service', 'validate_only', 'allow_missing', ), } def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: diff --git a/packages/google-cloud-run/setup.py b/packages/google-cloud-run/setup.py index ecdcb79f5555..6dd839ef587e 100644 --- a/packages/google-cloud-run/setup.py +++ b/packages/google-cloud-run/setup.py @@ -26,10 +26,7 @@ release_status = "Development Status :: 4 - Beta" url = "https://github.com/googleapis/python-run" dependencies = [ - # NOTE: Maintainers, please do not require google-api-core>=2.x.x - # Until this issue is closed - # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", + "google-api-core[grpc] >= 1.32.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*", "proto-plus >= 1.22.0, <2.0.0dev", "protobuf >= 3.19.0, <5.0.0dev", "googleapis-common-protos >= 1.56.1, <2.0.0dev", diff --git a/packages/google-cloud-run/testing/constraints-3.6.txt b/packages/google-cloud-run/testing/constraints-3.6.txt deleted file mode 100644 index 263195114d2a..000000000000 --- a/packages/google-cloud-run/testing/constraints-3.6.txt +++ /dev/null @@ -1,11 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.31.5 -proto-plus==1.15.0 -googleapis-common-protos==1.56.1 -grpc-google-iam-v1==0.12.4 -protobuf==3.19.0 diff --git a/packages/google-cloud-run/testing/constraints-3.7.txt b/packages/google-cloud-run/testing/constraints-3.7.txt index 1d399c6c4881..e8e8a2980306 100644 --- a/packages/google-cloud-run/testing/constraints-3.7.txt +++ b/packages/google-cloud-run/testing/constraints-3.7.txt @@ -4,7 +4,7 @@ # Pin the version to the lower bound. # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.31.5 +google-api-core==1.32.0 proto-plus==1.22.0 googleapis-common-protos==1.56.1 grpc-google-iam-v1==0.12.4 diff --git a/packages/google-cloud-run/tests/unit/gapic/run_v2/test_revisions.py b/packages/google-cloud-run/tests/unit/gapic/run_v2/test_revisions.py index 659cc58d9204..fb14b2b5866c 100644 --- a/packages/google-cloud-run/tests/unit/gapic/run_v2/test_revisions.py +++ b/packages/google-cloud-run/tests/unit/gapic/run_v2/test_revisions.py @@ -14,7 +14,13 @@ # limitations under the License. # import os -import mock + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -220,6 +226,7 @@ def test_revisions_client_client_options(client_class, transport_class, transpor quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -237,6 +244,7 @@ def test_revisions_client_client_options(client_class, transport_class, transpor quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -254,6 +262,7 @@ def test_revisions_client_client_options(client_class, transport_class, transpor quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -283,6 +292,25 @@ def test_revisions_client_client_options(client_class, transport_class, transpor quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions( + api_audience="https://language.googleapis.com" + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com", ) @@ -348,6 +376,7 @@ def test_revisions_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -382,6 +411,7 @@ def test_revisions_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -404,6 +434,7 @@ def test_revisions_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -514,6 +545,7 @@ def test_revisions_client_client_options_scopes( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -547,6 +579,7 @@ def test_revisions_client_client_options_credentials_file( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -565,6 +598,7 @@ def test_revisions_client_client_options_from_dict(): quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -598,6 +632,7 @@ def test_revisions_client_create_channel_credentials_file( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # test that the credentials from file are saved and used as the credentials. @@ -655,10 +690,9 @@ def test_get_revision(request_type, transport: str = "grpc"): generation=1068, launch_stage=launch_stage_pb2.LaunchStage.UNIMPLEMENTED, service="service_value", - container_concurrency=2253, + max_instance_request_concurrency=3436, service_account="service_account_value", - confidential=True, - execution_environment=vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_DEFAULT, + execution_environment=vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1, encryption_key="encryption_key_value", reconciling=True, observed_generation=2021, @@ -679,12 +713,11 @@ def test_get_revision(request_type, transport: str = "grpc"): assert response.generation == 1068 assert response.launch_stage == launch_stage_pb2.LaunchStage.UNIMPLEMENTED assert response.service == "service_value" - assert response.container_concurrency == 2253 + assert response.max_instance_request_concurrency == 3436 assert response.service_account == "service_account_value" - assert response.confidential is True assert ( response.execution_environment - == vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_DEFAULT + == vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1 ) assert response.encryption_key == "encryption_key_value" assert response.reconciling is True @@ -732,10 +765,9 @@ async def test_get_revision_async( generation=1068, launch_stage=launch_stage_pb2.LaunchStage.UNIMPLEMENTED, service="service_value", - container_concurrency=2253, + max_instance_request_concurrency=3436, service_account="service_account_value", - confidential=True, - execution_environment=vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_DEFAULT, + execution_environment=vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1, encryption_key="encryption_key_value", reconciling=True, observed_generation=2021, @@ -757,12 +789,11 @@ async def test_get_revision_async( assert response.generation == 1068 assert response.launch_stage == launch_stage_pb2.LaunchStage.UNIMPLEMENTED assert response.service == "service_value" - assert response.container_concurrency == 2253 + assert response.max_instance_request_concurrency == 3436 assert response.service_account == "service_account_value" - assert response.confidential is True assert ( response.execution_environment - == vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_DEFAULT + == vendor_settings.ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1 ) assert response.encryption_key == "encryption_key_value" assert response.reconciling is True @@ -776,16 +807,16 @@ async def test_get_revision_async_from_dict(): await test_get_revision_async(request_type=dict) -def test_get_revision_field_headers(): +def test_get_revision_routing_parameters(): client = RevisionsClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = revision.GetRevisionRequest() - - request.name = "name_value" + request = revision.GetRevisionRequest( + {"name": "projects/sample1/locations/sample2/sample3"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_revision), "__call__") as call: @@ -797,42 +828,9 @@ def test_get_revision_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_get_revision_field_headers_async(): - client = RevisionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = revision.GetRevisionRequest() - - request.name = "name_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_revision), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(revision.Revision()) - await client.get_revision(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_get_revision_flattened(): @@ -1004,16 +1002,16 @@ async def test_list_revisions_async_from_dict(): await test_list_revisions_async(request_type=dict) -def test_list_revisions_field_headers(): +def test_list_revisions_routing_parameters(): client = RevisionsClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = revision.ListRevisionsRequest() - - request.parent = "parent_value" + request = revision.ListRevisionsRequest( + {"parent": "projects/sample1/locations/sample2/sample3"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_revisions), "__call__") as call: @@ -1025,44 +1023,9 @@ def test_list_revisions_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_list_revisions_field_headers_async(): - client = RevisionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = revision.ListRevisionsRequest() - - request.parent = "parent_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_revisions), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - revision.ListRevisionsResponse() - ) - await client.list_revisions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_list_revisions_flattened(): @@ -1185,9 +1148,6 @@ def test_list_revisions_pager(transport_name: str = "grpc"): ) metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) pager = client.list_revisions(request={}) assert pager._metadata == metadata @@ -1418,16 +1378,16 @@ async def test_delete_revision_async_from_dict(): await test_delete_revision_async(request_type=dict) -def test_delete_revision_field_headers(): +def test_delete_revision_routing_parameters(): client = RevisionsClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = revision.DeleteRevisionRequest() - - request.name = "name_value" + request = revision.DeleteRevisionRequest( + {"name": "projects/sample1/locations/sample2/sample3"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_revision), "__call__") as call: @@ -1439,44 +1399,9 @@ def test_delete_revision_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_delete_revision_field_headers_async(): - client = RevisionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = revision.DeleteRevisionRequest() - - request.name = "name_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_revision), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.delete_revision(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_delete_revision_flattened(): @@ -1787,6 +1712,28 @@ def test_revisions_transport_auth_adc(transport_class): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.RevisionsGrpcTransport, + transports.RevisionsGrpcAsyncIOTransport, + ], +) +def test_revisions_transport_auth_gdch_credentials(transport_class): + host = "https://language.com" + api_audience_tests = [None, "https://language2.com"] + api_audience_expect = [host, "https://language2.com"] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, "default", autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock( + return_value=gdch_mock + ) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with(e) + + @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2409,4 +2356,5 @@ def test_api_key_credentials(client_class, transport_class): quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) diff --git a/packages/google-cloud-run/tests/unit/gapic/run_v2/test_services.py b/packages/google-cloud-run/tests/unit/gapic/run_v2/test_services.py index 80d7445bd1cb..9b11aa46da8e 100644 --- a/packages/google-cloud-run/tests/unit/gapic/run_v2/test_services.py +++ b/packages/google-cloud-run/tests/unit/gapic/run_v2/test_services.py @@ -14,7 +14,13 @@ # limitations under the License. # import os -import mock + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -224,6 +230,7 @@ def test_services_client_client_options(client_class, transport_class, transport quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -241,6 +248,7 @@ def test_services_client_client_options(client_class, transport_class, transport quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -258,6 +266,7 @@ def test_services_client_client_options(client_class, transport_class, transport quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -287,6 +296,25 @@ def test_services_client_client_options(client_class, transport_class, transport quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions( + api_audience="https://language.googleapis.com" + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com", ) @@ -352,6 +380,7 @@ def test_services_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -386,6 +415,7 @@ def test_services_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -408,6 +438,7 @@ def test_services_client_mtls_env_auto( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -514,6 +545,7 @@ def test_services_client_client_options_scopes( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -547,6 +579,7 @@ def test_services_client_client_options_credentials_file( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -565,6 +598,7 @@ def test_services_client_client_options_from_dict(): quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) @@ -598,6 +632,7 @@ def test_services_client_create_channel_credentials_file( quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, ) # test that the credentials from file are saved and used as the credentials. @@ -712,16 +747,16 @@ async def test_create_service_async_from_dict(): await test_create_service_async(request_type=dict) -def test_create_service_field_headers(): +def test_create_service_routing_parameters(): client = ServicesClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = gcr_service.CreateServiceRequest() - - request.parent = "parent_value" + request = gcr_service.CreateServiceRequest( + {"parent": "projects/sample1/locations/sample2"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_service), "__call__") as call: @@ -733,44 +768,9 @@ def test_create_service_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_create_service_field_headers_async(): - client = ServicesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gcr_service.CreateServiceRequest() - - request.parent = "parent_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_service), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.create_service(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_create_service_flattened(): @@ -1024,16 +1024,16 @@ async def test_get_service_async_from_dict(): await test_get_service_async(request_type=dict) -def test_get_service_field_headers(): +def test_get_service_routing_parameters(): client = ServicesClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = service.GetServiceRequest() - - request.name = "name_value" + request = service.GetServiceRequest( + {"name": "projects/sample1/locations/sample2/sample3"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_service), "__call__") as call: @@ -1045,42 +1045,9 @@ def test_get_service_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_get_service_field_headers_async(): - client = ServicesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = service.GetServiceRequest() - - request.name = "name_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_service), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(service.Service()) - await client.get_service(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_get_service_flattened(): @@ -1252,16 +1219,16 @@ async def test_list_services_async_from_dict(): await test_list_services_async(request_type=dict) -def test_list_services_field_headers(): +def test_list_services_routing_parameters(): client = ServicesClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = service.ListServicesRequest() - - request.parent = "parent_value" + request = service.ListServicesRequest( + {"parent": "projects/sample1/locations/sample2"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -1273,44 +1240,9 @@ def test_list_services_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_list_services_field_headers_async(): - client = ServicesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = service.ListServicesRequest() - - request.parent = "parent_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_services), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - service.ListServicesResponse() - ) - await client.list_services(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "parent=parent_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_list_services_flattened(): @@ -1433,9 +1365,6 @@ def test_list_services_pager(transport_name: str = "grpc"): ) metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) pager = client.list_services(request={}) assert pager._metadata == metadata @@ -1666,16 +1595,16 @@ async def test_update_service_async_from_dict(): await test_update_service_async(request_type=dict) -def test_update_service_field_headers(): +def test_update_service_routing_parameters(): client = ServicesClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = gcr_service.UpdateServiceRequest() - - request.service.name = "name_value" + request = gcr_service.UpdateServiceRequest( + {"service": {"name": "projects/sample1/locations/sample2/sample3"}} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_service), "__call__") as call: @@ -1687,44 +1616,9 @@ def test_update_service_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "service.name=name_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_update_service_field_headers_async(): - client = ServicesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gcr_service.UpdateServiceRequest() - - request.service.name = "name_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_service), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.update_service(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "service.name=name_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_update_service_flattened(): @@ -1740,7 +1634,6 @@ def test_update_service_flattened(): # using the keyword arguments to the method. client.update_service( service=gcr_service.Service(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected @@ -1750,9 +1643,6 @@ def test_update_service_flattened(): arg = args[0].service mock_val = gcr_service.Service(name="name_value") assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) - assert arg == mock_val def test_update_service_flattened_error(): @@ -1766,7 +1656,6 @@ def test_update_service_flattened_error(): client.update_service( gcr_service.UpdateServiceRequest(), service=gcr_service.Service(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1788,7 +1677,6 @@ async def test_update_service_flattened_async(): # using the keyword arguments to the method. response = await client.update_service( service=gcr_service.Service(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected @@ -1798,9 +1686,6 @@ async def test_update_service_flattened_async(): arg = args[0].service mock_val = gcr_service.Service(name="name_value") assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) - assert arg == mock_val @pytest.mark.asyncio @@ -1815,7 +1700,6 @@ async def test_update_service_flattened_error_async(): await client.update_service( gcr_service.UpdateServiceRequest(), service=gcr_service.Service(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1902,16 +1786,16 @@ async def test_delete_service_async_from_dict(): await test_delete_service_async(request_type=dict) -def test_delete_service_field_headers(): +def test_delete_service_routing_parameters(): client = ServicesClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = service.DeleteServiceRequest() - - request.name = "name_value" + request = service.DeleteServiceRequest( + {"name": "projects/sample1/locations/sample2/sample3"} + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_service), "__call__") as call: @@ -1923,44 +1807,9 @@ def test_delete_service_field_headers(): _, args, _ = call.mock_calls[0] assert args[0] == request - # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] - - -@pytest.mark.asyncio -async def test_delete_service_field_headers_async(): - client = ServicesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = service.DeleteServiceRequest() - - request.name = "name_value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_service), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.delete_service(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - "x-goog-request-params", - "name=name_value", - ) in kw["metadata"] + # This test doesn't assert anything useful. + assert kw["metadata"] def test_delete_service_flattened(): @@ -2795,6 +2644,28 @@ def test_services_transport_auth_adc(transport_class): ) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ServicesGrpcTransport, + transports.ServicesGrpcAsyncIOTransport, + ], +) +def test_services_transport_auth_gdch_credentials(transport_class): + host = "https://language.com" + api_audience_tests = [None, "https://language2.com"] + api_audience_expect = [host, "https://language2.com"] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, "default", autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock( + return_value=gdch_mock + ) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with(e) + + @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -3417,4 +3288,5 @@ def test_api_key_credentials(client_class, transport_class): quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, + api_audience=None, )