diff --git a/google/cloud/compute_v1/services/accelerator_types/transports/base.py b/google/cloud/compute_v1/services/accelerator_types/transports/base.py index f5d37dd1a..08226272e 100644 --- a/google/cloud/compute_v1/services/accelerator_types/transports/base.py +++ b/google/cloud/compute_v1/services/accelerator_types/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/accelerator_types/transports/rest.py b/google/cloud/compute_v1/services/accelerator_types/transports/rest.py index 627780859..65478651d 100644 --- a/google/cloud/compute_v1/services/accelerator_types/transports/rest.py +++ b/google/cloud/compute_v1/services/accelerator_types/transports/rest.py @@ -53,6 +53,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -86,7 +87,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -142,16 +146,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -206,16 +204,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -269,16 +261,10 @@ def list( if compute.ListAcceleratorTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/addresses/transports/base.py b/google/cloud/compute_v1/services/addresses/transports/base.py index c14ad63c8..5cdfc8801 100644 --- a/google/cloud/compute_v1/services/addresses/transports/base.py +++ b/google/cloud/compute_v1/services/addresses/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/addresses/transports/rest.py b/google/cloud/compute_v1/services/addresses/transports/rest.py index 53b950908..f059a5498 100644 --- a/google/cloud/compute_v1/services/addresses/transports/rest.py +++ b/google/cloud/compute_v1/services/addresses/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListAddressesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteAddressRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -305,16 +297,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -393,16 +379,12 @@ def insert( if compute.InsertAddressRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -453,16 +435,10 @@ def list( if compute.ListAddressesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/autoscalers/transports/base.py b/google/cloud/compute_v1/services/autoscalers/transports/base.py index 109e91eb5..d9fed1df4 100644 --- a/google/cloud/compute_v1/services/autoscalers/transports/base.py +++ b/google/cloud/compute_v1/services/autoscalers/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/autoscalers/transports/rest.py b/google/cloud/compute_v1/services/autoscalers/transports/rest.py index f1541cb79..2e6d2a61e 100644 --- a/google/cloud/compute_v1/services/autoscalers/transports/rest.py +++ b/google/cloud/compute_v1/services/autoscalers/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListAutoscalersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -298,16 +290,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -388,16 +374,12 @@ def insert( if compute.InsertAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -451,16 +433,10 @@ def list( if compute.ListAutoscalersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -543,16 +519,12 @@ def patch( if compute.PatchAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -633,16 +605,12 @@ def update( if compute.UpdateAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/backend_buckets/transports/base.py b/google/cloud/compute_v1/services/backend_buckets/transports/base.py index 4526d6929..9ea956822 100644 --- a/google/cloud/compute_v1/services/backend_buckets/transports/base.py +++ b/google/cloud/compute_v1/services/backend_buckets/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/backend_buckets/transports/rest.py b/google/cloud/compute_v1/services/backend_buckets/transports/rest.py index ee9bc6b8e..0c4cc8179 100644 --- a/google/cloud/compute_v1/services/backend_buckets/transports/rest.py +++ b/google/cloud/compute_v1/services/backend_buckets/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -165,16 +169,12 @@ def add_signed_url_key( if compute.AddSignedUrlKeyBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -248,16 +248,10 @@ def delete( if compute.DeleteBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -328,21 +322,14 @@ def delete_signed_url_key( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.key_name: - query_params["keyName"] = request.key_name + query_params["keyName"] = request.key_name if compute.DeleteSignedUrlKeyBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -392,16 +379,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -482,16 +463,12 @@ def insert( if compute.InsertBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -545,16 +522,10 @@ def list( if compute.ListBackendBucketsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -637,16 +608,12 @@ def patch( if compute.PatchBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -727,16 +694,12 @@ def update( if compute.UpdateBackendBucketRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/backend_services/transports/base.py b/google/cloud/compute_v1/services/backend_services/transports/base.py index 47392e6d4..ad5073c95 100644 --- a/google/cloud/compute_v1/services/backend_services/transports/base.py +++ b/google/cloud/compute_v1/services/backend_services/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/backend_services/transports/rest.py b/google/cloud/compute_v1/services/backend_services/transports/rest.py index 86fc6473f..842d610aa 100644 --- a/google/cloud/compute_v1/services/backend_services/transports/rest.py +++ b/google/cloud/compute_v1/services/backend_services/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -165,16 +169,12 @@ def add_signed_url_key( if compute.AddSignedUrlKeyBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -233,16 +233,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -318,16 +312,10 @@ def delete( if compute.DeleteBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -398,21 +386,14 @@ def delete_signed_url_key( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.key_name: - query_params["keyName"] = request.key_name + query_params["keyName"] = request.key_name if compute.DeleteSignedUrlKeyBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -478,16 +459,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -540,16 +515,12 @@ def get_health( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -630,16 +601,12 @@ def insert( if compute.InsertBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -693,16 +660,10 @@ def list( if compute.ListBackendServicesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -785,16 +746,12 @@ def patch( if compute.PatchBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -875,16 +832,12 @@ def set_security_policy( if compute.SetSecurityPolicyBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -965,16 +918,12 @@ def update( if compute.UpdateBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/disk_types/transports/base.py b/google/cloud/compute_v1/services/disk_types/transports/base.py index c44914d3c..435a8f2a6 100644 --- a/google/cloud/compute_v1/services/disk_types/transports/base.py +++ b/google/cloud/compute_v1/services/disk_types/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/disk_types/transports/rest.py b/google/cloud/compute_v1/services/disk_types/transports/rest.py index 18e4260d0..5a874146a 100644 --- a/google/cloud/compute_v1/services/disk_types/transports/rest.py +++ b/google/cloud/compute_v1/services/disk_types/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListDiskTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -213,16 +211,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -273,16 +265,10 @@ def list( if compute.ListDiskTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/disks/transports/base.py b/google/cloud/compute_v1/services/disks/transports/base.py index 1d6b21eeb..f089ac23e 100644 --- a/google/cloud/compute_v1/services/disks/transports/base.py +++ b/google/cloud/compute_v1/services/disks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/disks/transports/rest.py b/google/cloud/compute_v1/services/disks/transports/rest.py index 77dfec062..36145f2f7 100644 --- a/google/cloud/compute_v1/services/disks/transports/rest.py +++ b/google/cloud/compute_v1/services/disks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def add_resource_policies( if compute.AddResourcePoliciesDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -229,16 +229,10 @@ def aggregated_list( if compute.AggregatedListDisksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -324,16 +318,12 @@ def create_snapshot( if compute.CreateSnapshotDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -407,16 +397,10 @@ def delete( if compute.DeleteDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -480,16 +464,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -588,16 +566,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -677,16 +649,12 @@ def insert( if compute.InsertDiskRequest.source_image in request: query_params["sourceImage"] = request.source_image - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -737,16 +705,10 @@ def list( if compute.ListDisksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -828,16 +790,12 @@ def remove_resource_policies( if compute.RemoveResourcePoliciesDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -918,16 +876,12 @@ def resize( if compute.ResizeDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1029,16 +983,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1120,16 +1070,12 @@ def set_labels( if compute.SetLabelsDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1181,16 +1127,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py b/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py index f0a2d8d64..b7b5e8a61 100644 --- a/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py +++ b/google/cloud/compute_v1/services/external_vpn_gateways/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py b/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py index 989d8fb0c..c7465948b 100644 --- a/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py +++ b/google/cloud/compute_v1/services/external_vpn_gateways/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteExternalVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -226,16 +224,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -316,16 +308,12 @@ def insert( if compute.InsertExternalVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -379,16 +367,10 @@ def list( if compute.ListExternalVpnGatewaysRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -467,16 +449,12 @@ def set_labels( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -525,16 +503,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/firewall_policies/transports/base.py b/google/cloud/compute_v1/services/firewall_policies/transports/base.py index 6893c06e7..44b407fc5 100644 --- a/google/cloud/compute_v1/services/firewall_policies/transports/base.py +++ b/google/cloud/compute_v1/services/firewall_policies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/firewall_policies/transports/rest.py b/google/cloud/compute_v1/services/firewall_policies/transports/rest.py index b543ca504..54c6d9230 100644 --- a/google/cloud/compute_v1/services/firewall_policies/transports/rest.py +++ b/google/cloud/compute_v1/services/firewall_policies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -170,16 +174,12 @@ def add_association( if compute.AddAssociationFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -258,16 +258,12 @@ def add_rule( if compute.AddRuleFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -341,16 +337,10 @@ def clone_rules( if compute.CloneRulesFirewallPolicyRequest.source_firewall_policy in request: query_params["sourceFirewallPolicy"] = request.source_firewall_policy - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -422,16 +412,10 @@ def delete( if compute.DeleteFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -475,16 +459,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -530,16 +508,10 @@ def get_association( if compute.GetAssociationFirewallPolicyRequest.name in request: query_params["name"] = request.name - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -640,16 +612,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -697,16 +663,10 @@ def get_rule( if compute.GetRuleFirewallPolicyRequest.priority in request: query_params["priority"] = request.priority - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -789,16 +749,12 @@ def insert( if compute.InsertFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -852,16 +808,10 @@ def list( if compute.ListFirewallPoliciesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -907,16 +857,10 @@ def list_associations( if compute.ListAssociationsFirewallPolicyRequest.target_resource in request: query_params["targetResource"] = request.target_resource - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -992,16 +936,10 @@ def move( if compute.MoveFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1080,16 +1018,12 @@ def patch( if compute.PatchFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1170,16 +1104,12 @@ def patch_rule( if compute.PatchRuleFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1253,16 +1183,10 @@ def remove_association( if compute.RemoveAssociationFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1336,16 +1260,10 @@ def remove_rule( if compute.RemoveRuleFirewallPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1444,16 +1362,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1502,16 +1416,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/firewalls/transports/base.py b/google/cloud/compute_v1/services/firewalls/transports/base.py index 49f7a4f84..b57a2648b 100644 --- a/google/cloud/compute_v1/services/firewalls/transports/base.py +++ b/google/cloud/compute_v1/services/firewalls/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/firewalls/transports/rest.py b/google/cloud/compute_v1/services/firewalls/transports/rest.py index fed614c14..f751902f3 100644 --- a/google/cloud/compute_v1/services/firewalls/transports/rest.py +++ b/google/cloud/compute_v1/services/firewalls/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def delete( if compute.DeleteFirewallRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -211,16 +209,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -299,16 +291,12 @@ def insert( if compute.InsertFirewallRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -359,16 +347,10 @@ def list( if compute.ListFirewallsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -449,16 +431,12 @@ def patch( if compute.PatchFirewallRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -537,16 +515,12 @@ def update( if compute.UpdateFirewallRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/forwarding_rules/transports/base.py b/google/cloud/compute_v1/services/forwarding_rules/transports/base.py index 54a77e731..f8af0c13a 100644 --- a/google/cloud/compute_v1/services/forwarding_rules/transports/base.py +++ b/google/cloud/compute_v1/services/forwarding_rules/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py b/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py index 73881b20d..61938b0e9 100644 --- a/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py +++ b/google/cloud/compute_v1/services/forwarding_rules/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -227,16 +225,10 @@ def delete( if compute.DeleteForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -303,16 +295,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -393,16 +379,12 @@ def insert( if compute.InsertForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -456,16 +438,10 @@ def list( if compute.ListForwardingRulesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -549,16 +525,12 @@ def patch( if compute.PatchForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -640,16 +612,12 @@ def set_labels( if compute.SetLabelsForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -731,16 +699,12 @@ def set_target( if compute.SetTargetForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_addresses/transports/base.py b/google/cloud/compute_v1/services/global_addresses/transports/base.py index 59d3eedaf..d380c32be 100644 --- a/google/cloud/compute_v1/services/global_addresses/transports/base.py +++ b/google/cloud/compute_v1/services/global_addresses/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_addresses/transports/rest.py b/google/cloud/compute_v1/services/global_addresses/transports/rest.py index faa556af4..c1e9e2748 100644 --- a/google/cloud/compute_v1/services/global_addresses/transports/rest.py +++ b/google/cloud/compute_v1/services/global_addresses/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def delete( if compute.DeleteGlobalAddressRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -235,16 +233,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -323,16 +315,12 @@ def insert( if compute.InsertGlobalAddressRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -384,16 +372,10 @@ def list( if compute.ListGlobalAddressesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py b/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py index 5bb754614..e61272413 100644 --- a/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py +++ b/google/cloud/compute_v1/services/global_forwarding_rules/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py b/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py index ffe0c27b1..ad44a5280 100644 --- a/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py +++ b/google/cloud/compute_v1/services/global_forwarding_rules/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteGlobalForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -233,16 +231,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -323,16 +315,12 @@ def insert( if compute.InsertGlobalForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -386,16 +374,10 @@ def list( if compute.ListGlobalForwardingRulesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -478,16 +460,12 @@ def patch( if compute.PatchGlobalForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -564,16 +542,12 @@ def set_labels( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -654,16 +628,12 @@ def set_target( if compute.SetTargetGlobalForwardingRuleRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py b/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py index 64c3f6d8f..70115faff 100644 --- a/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py +++ b/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py b/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py index 9a311b2b6..37a923eb1 100644 --- a/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/global_network_endpoint_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -168,16 +172,12 @@ def attach_network_endpoints( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -251,16 +251,10 @@ def delete( if compute.DeleteGlobalNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -344,16 +338,12 @@ def detach_network_endpoints( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -410,16 +400,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -500,16 +484,12 @@ def insert( if compute.InsertGlobalNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -564,16 +544,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -644,16 +618,10 @@ def list_network_endpoints( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_operations/transports/base.py b/google/cloud/compute_v1/services/global_operations/transports/base.py index 739ea7228..ad8a387a5 100644 --- a/google/cloud/compute_v1/services/global_operations/transports/base.py +++ b/google/cloud/compute_v1/services/global_operations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_operations/transports/rest.py b/google/cloud/compute_v1/services/global_operations/transports/rest.py index 07c85796a..48656cd0d 100644 --- a/google/cloud/compute_v1/services/global_operations/transports/rest.py +++ b/google/cloud/compute_v1/services/global_operations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -197,16 +195,10 @@ def delete( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -278,16 +270,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -341,16 +327,10 @@ def list( if compute.ListGlobalOperationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -422,16 +402,10 @@ def wait( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_organization_operations/transports/base.py b/google/cloud/compute_v1/services/global_organization_operations/transports/base.py index bc05e03b7..761c77b4b 100644 --- a/google/cloud/compute_v1/services/global_organization_operations/transports/base.py +++ b/google/cloud/compute_v1/services/global_organization_operations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py b/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py index 6c8b90dcb..7c9719206 100644 --- a/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py +++ b/google/cloud/compute_v1/services/global_organization_operations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -131,16 +135,10 @@ def delete( if compute.DeleteGlobalOrganizationOperationRequest.parent_id in request: query_params["parentId"] = request.parent_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -214,16 +212,10 @@ def get( if compute.GetGlobalOrganizationOperationRequest.parent_id in request: query_params["parentId"] = request.parent_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -282,16 +274,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py b/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py index 38fd07454..254740127 100644 --- a/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py +++ b/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py b/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py index 577054bca..c82370155 100644 --- a/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py +++ b/google/cloud/compute_v1/services/global_public_delegated_prefixes/transports/rest.py @@ -54,6 +54,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -87,7 +88,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -160,16 +164,10 @@ def delete( if compute.DeleteGlobalPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -222,16 +220,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -312,16 +304,12 @@ def insert( if compute.InsertGlobalPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -376,16 +364,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -468,16 +450,12 @@ def patch( if compute.PatchGlobalPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/health_checks/transports/base.py b/google/cloud/compute_v1/services/health_checks/transports/base.py index c4088ac14..d6806e2b1 100644 --- a/google/cloud/compute_v1/services/health_checks/transports/base.py +++ b/google/cloud/compute_v1/services/health_checks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/health_checks/transports/rest.py b/google/cloud/compute_v1/services/health_checks/transports/rest.py index e1271e5cf..63fa8e598 100644 --- a/google/cloud/compute_v1/services/health_checks/transports/rest.py +++ b/google/cloud/compute_v1/services/health_checks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListHealthChecksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -221,16 +219,10 @@ def delete( if compute.DeleteHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -300,16 +292,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -390,16 +376,12 @@ def insert( if compute.InsertHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -453,16 +435,10 @@ def list( if compute.ListHealthChecksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -543,16 +519,12 @@ def patch( if compute.PatchHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -631,16 +603,12 @@ def update( if compute.UpdateHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/images/transports/base.py b/google/cloud/compute_v1/services/images/transports/base.py index 96cd7abcf..eeb769956 100644 --- a/google/cloud/compute_v1/services/images/transports/base.py +++ b/google/cloud/compute_v1/services/images/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/images/transports/rest.py b/google/cloud/compute_v1/services/images/transports/rest.py index 9ee104adb..0995dd0a7 100644 --- a/google/cloud/compute_v1/services/images/transports/rest.py +++ b/google/cloud/compute_v1/services/images/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -155,16 +159,10 @@ def delete( if compute.DeleteImageRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -243,16 +241,12 @@ def deprecate( if compute.DeprecateImageRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -298,16 +292,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -354,16 +342,10 @@ def get_from_family( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -459,16 +441,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -548,16 +524,12 @@ def insert( if compute.InsertImageRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -608,16 +580,10 @@ def list( if compute.ListImagesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -695,16 +661,12 @@ def patch( if compute.PatchImageRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -803,16 +765,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -889,16 +847,12 @@ def set_labels( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -947,16 +901,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/instance_group_managers/transports/base.py b/google/cloud/compute_v1/services/instance_group_managers/transports/base.py index 624aabce5..d2868d78e 100644 --- a/google/cloud/compute_v1/services/instance_group_managers/transports/base.py +++ b/google/cloud/compute_v1/services/instance_group_managers/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py b/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py index e23838ca8..723448416 100644 --- a/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py +++ b/google/cloud/compute_v1/services/instance_group_managers/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def abandon_instances( if compute.AbandonInstancesInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -235,16 +235,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -327,16 +321,12 @@ def apply_updates_to_instances( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -418,16 +408,12 @@ def create_instances( if compute.CreateInstancesInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -502,16 +488,10 @@ def delete( if compute.DeleteInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -593,16 +573,12 @@ def delete_instances( if compute.DeleteInstancesInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -683,16 +659,12 @@ def delete_per_instance_configs( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -751,16 +723,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -841,16 +807,12 @@ def insert( if compute.InsertInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -902,16 +864,10 @@ def list( if compute.ListInstanceGroupManagersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -971,16 +927,10 @@ def list_errors( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1046,16 +996,10 @@ def list_managed_instances( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1124,16 +1068,10 @@ def list_per_instance_configs( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1217,16 +1155,12 @@ def patch( if compute.PatchInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1312,16 +1246,12 @@ def patch_per_instance_configs( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1403,16 +1333,12 @@ def recreate_instances( if compute.RecreateInstancesInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1486,19 +1412,12 @@ def resize( query_params = {} if compute.ResizeInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - if request.size: - query_params["size"] = request.size - - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") + query_params["size"] = request.size # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1580,16 +1499,12 @@ def set_instance_template( if compute.SetInstanceTemplateInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1671,16 +1586,12 @@ def set_target_pools( if compute.SetTargetPoolsInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1766,16 +1677,12 @@ def update_per_instance_configs( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/instance_groups/transports/base.py b/google/cloud/compute_v1/services/instance_groups/transports/base.py index 4fa60b1d2..3a7c9f07d 100644 --- a/google/cloud/compute_v1/services/instance_groups/transports/base.py +++ b/google/cloud/compute_v1/services/instance_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/instance_groups/transports/rest.py b/google/cloud/compute_v1/services/instance_groups/transports/rest.py index 3cace55f6..2eb6550e6 100644 --- a/google/cloud/compute_v1/services/instance_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/instance_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def add_instances( if compute.AddInstancesInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -232,16 +232,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -318,16 +312,10 @@ def delete( if compute.DeleteInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -392,16 +380,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -482,16 +464,12 @@ def insert( if compute.InsertInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -543,16 +521,10 @@ def list( if compute.ListInstanceGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -616,16 +588,12 @@ def list_instances( if compute.ListInstancesInstanceGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -709,16 +677,12 @@ def remove_instances( if compute.RemoveInstancesInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -800,16 +764,12 @@ def set_named_ports( if compute.SetNamedPortsInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/instance_templates/transports/base.py b/google/cloud/compute_v1/services/instance_templates/transports/base.py index 2fae32fff..243a5e981 100644 --- a/google/cloud/compute_v1/services/instance_templates/transports/base.py +++ b/google/cloud/compute_v1/services/instance_templates/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/instance_templates/transports/rest.py b/google/cloud/compute_v1/services/instance_templates/transports/rest.py index b76edeb0f..494c31c75 100644 --- a/google/cloud/compute_v1/services/instance_templates/transports/rest.py +++ b/google/cloud/compute_v1/services/instance_templates/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteInstanceTemplateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -217,16 +215,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -327,16 +319,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -415,16 +401,12 @@ def insert( if compute.InsertInstanceTemplateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -476,16 +458,10 @@ def list( if compute.ListInstanceTemplatesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -586,16 +562,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -644,16 +616,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/instances/transports/base.py b/google/cloud/compute_v1/services/instances/transports/base.py index 729435037..d5158fc8a 100644 --- a/google/cloud/compute_v1/services/instances/transports/base.py +++ b/google/cloud/compute_v1/services/instances/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/instances/transports/rest.py b/google/cloud/compute_v1/services/instances/transports/rest.py index e4adb2932..af8df32fd 100644 --- a/google/cloud/compute_v1/services/instances/transports/rest.py +++ b/google/cloud/compute_v1/services/instances/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -163,21 +167,16 @@ def add_access_config( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.network_interface: - query_params["networkInterface"] = request.network_interface + query_params["networkInterface"] = request.network_interface if compute.AddAccessConfigInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -259,16 +258,12 @@ def add_resource_policies( if compute.AddResourcePoliciesInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -322,16 +317,10 @@ def aggregated_list( if compute.AggregatedListInstancesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -417,16 +406,12 @@ def attach_disk( if compute.AttachDiskInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -505,16 +490,12 @@ def bulk_insert( if compute.BulkInsertInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -589,16 +570,10 @@ def delete( if compute.DeleteInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -670,23 +645,15 @@ def delete_access_config( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.access_config: - query_params["accessConfig"] = request.access_config - if request.network_interface: - query_params["networkInterface"] = request.network_interface + query_params["accessConfig"] = request.access_config + query_params["networkInterface"] = request.network_interface if compute.DeleteAccessConfigInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -758,21 +725,14 @@ def detach_disk( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.device_name: - query_params["deviceName"] = request.device_name + query_params["deviceName"] = request.device_name if compute.DetachDiskInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -822,16 +782,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -875,19 +829,12 @@ def get_effective_firewalls( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.network_interface: - query_params["networkInterface"] = request.network_interface - - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") + query_params["networkInterface"] = request.network_interface # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -938,16 +885,10 @@ def get_guest_attributes( if compute.GetGuestAttributesInstanceRequest.variable_key in request: query_params["variableKey"] = request.variable_key - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1051,16 +992,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1105,16 +1040,10 @@ def get_screenshot( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1165,16 +1094,10 @@ def get_serial_port_output( if compute.GetSerialPortOutputInstanceRequest.start in request: query_params["start"] = request.start - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1222,16 +1145,10 @@ def get_shielded_instance_identity( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1314,16 +1231,12 @@ def insert( if compute.InsertInstanceRequest.source_instance_template in request: query_params["sourceInstanceTemplate"] = request.source_instance_template - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1374,16 +1287,10 @@ def list( if compute.ListInstancesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1442,16 +1349,10 @@ def list_referrers( if compute.ListReferrersInstancesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1535,16 +1436,12 @@ def remove_resource_policies( if compute.RemoveResourcePoliciesInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1619,16 +1516,10 @@ def reset( if compute.ResetInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1705,16 +1596,10 @@ def set_deletion_protection( if compute.SetDeletionProtectionInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1786,23 +1671,15 @@ def set_disk_auto_delete( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.auto_delete: - query_params["autoDelete"] = request.auto_delete - if request.device_name: - query_params["deviceName"] = request.device_name + query_params["autoDelete"] = request.auto_delete + query_params["deviceName"] = request.device_name if compute.SetDiskAutoDeleteInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1904,16 +1781,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1995,16 +1868,12 @@ def set_labels( if compute.SetLabelsInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2086,16 +1955,12 @@ def set_machine_resources( if compute.SetMachineResourcesInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2177,16 +2042,12 @@ def set_machine_type( if compute.SetMachineTypeInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2268,16 +2129,12 @@ def set_metadata( if compute.SetMetadataInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2359,16 +2216,12 @@ def set_min_cpu_platform( if compute.SetMinCpuPlatformInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2450,16 +2303,12 @@ def set_scheduling( if compute.SetSchedulingInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2541,16 +2390,12 @@ def set_service_account( if compute.SetServiceAccountInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2636,16 +2481,12 @@ def set_shielded_instance_integrity_policy( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2727,16 +2568,12 @@ def set_tags( if compute.SetTagsInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2810,16 +2647,10 @@ def simulate_maintenance_event( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2894,16 +2725,10 @@ def start( if compute.StartInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -2985,16 +2810,12 @@ def start_with_encryption_key( if compute.StartWithEncryptionKeyInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3068,16 +2889,10 @@ def stop( if compute.StopInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3129,16 +2944,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3228,16 +3039,12 @@ def update( if compute.UpdateInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3316,21 +3123,16 @@ def update_access_config( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.network_interface: - query_params["networkInterface"] = request.network_interface + query_params["networkInterface"] = request.network_interface if compute.UpdateAccessConfigInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3412,16 +3214,12 @@ def update_display_device( if compute.UpdateDisplayDeviceInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3500,21 +3298,16 @@ def update_network_interface( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.network_interface: - query_params["networkInterface"] = request.network_interface + query_params["networkInterface"] = request.network_interface if compute.UpdateNetworkInterfaceInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -3597,16 +3390,12 @@ def update_shielded_instance_config( if compute.UpdateShieldedInstanceConfigInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py b/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py index 23091650b..baae3e9ad 100644 --- a/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py +++ b/google/cloud/compute_v1/services/interconnect_attachments/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py b/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py index bed80622b..7ad833014 100644 --- a/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py +++ b/google/cloud/compute_v1/services/interconnect_attachments/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -144,16 +148,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -230,16 +228,10 @@ def delete( if compute.DeleteInterconnectAttachmentRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -291,16 +283,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -383,16 +369,12 @@ def insert( if compute.InsertInterconnectAttachmentRequest.validate_only in request: query_params["validateOnly"] = request.validate_only - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -447,16 +429,10 @@ def list( if compute.ListInterconnectAttachmentsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -540,16 +516,12 @@ def patch( if compute.PatchInterconnectAttachmentRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/interconnect_locations/transports/base.py b/google/cloud/compute_v1/services/interconnect_locations/transports/base.py index 1fe9646b0..16f563fae 100644 --- a/google/cloud/compute_v1/services/interconnect_locations/transports/base.py +++ b/google/cloud/compute_v1/services/interconnect_locations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py b/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py index c85766d96..2a0a9ba60 100644 --- a/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py +++ b/google/cloud/compute_v1/services/interconnect_locations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -135,16 +139,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -201,16 +199,10 @@ def list( if compute.ListInterconnectLocationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/interconnects/transports/base.py b/google/cloud/compute_v1/services/interconnects/transports/base.py index 5592165ad..3cafc0f82 100644 --- a/google/cloud/compute_v1/services/interconnects/transports/base.py +++ b/google/cloud/compute_v1/services/interconnects/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/interconnects/transports/rest.py b/google/cloud/compute_v1/services/interconnects/transports/rest.py index 56a3cd00c..36167e41a 100644 --- a/google/cloud/compute_v1/services/interconnects/transports/rest.py +++ b/google/cloud/compute_v1/services/interconnects/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def delete( if compute.DeleteInterconnectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -214,16 +212,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -269,16 +261,10 @@ def get_diagnostics( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -359,16 +345,12 @@ def insert( if compute.InsertInterconnectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -422,16 +404,10 @@ def list( if compute.ListInterconnectsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -512,16 +488,12 @@ def patch( if compute.PatchInterconnectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/license_codes/transports/base.py b/google/cloud/compute_v1/services/license_codes/transports/base.py index 02063d777..1a5800749 100644 --- a/google/cloud/compute_v1/services/license_codes/transports/base.py +++ b/google/cloud/compute_v1/services/license_codes/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/license_codes/transports/rest.py b/google/cloud/compute_v1/services/license_codes/transports/rest.py index 3e5e11f7c..c62ef553e 100644 --- a/google/cloud/compute_v1/services/license_codes/transports/rest.py +++ b/google/cloud/compute_v1/services/license_codes/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -133,16 +137,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -193,16 +191,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/licenses/transports/base.py b/google/cloud/compute_v1/services/licenses/transports/base.py index d3ff14836..e0c15a542 100644 --- a/google/cloud/compute_v1/services/licenses/transports/base.py +++ b/google/cloud/compute_v1/services/licenses/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/licenses/transports/rest.py b/google/cloud/compute_v1/services/licenses/transports/rest.py index 2077ae269..c35bbf587 100644 --- a/google/cloud/compute_v1/services/licenses/transports/rest.py +++ b/google/cloud/compute_v1/services/licenses/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -153,21 +157,14 @@ def delete( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.license_: - query_params["license"] = request.license_ + query_params["license"] = request.license_ if compute.DeleteLicenseRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -214,19 +211,12 @@ def get( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.license_: - query_params["license"] = request.license_ - - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") + query_params["license"] = request.license_ # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -325,16 +315,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -413,16 +397,12 @@ def insert( if compute.InsertLicenseRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -473,16 +453,10 @@ def list( if compute.ListLicensesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -583,16 +557,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -641,16 +611,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/machine_types/transports/base.py b/google/cloud/compute_v1/services/machine_types/transports/base.py index 587a0521f..af7b3f966 100644 --- a/google/cloud/compute_v1/services/machine_types/transports/base.py +++ b/google/cloud/compute_v1/services/machine_types/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/machine_types/transports/rest.py b/google/cloud/compute_v1/services/machine_types/transports/rest.py index 7ccc4c533..ad377ff30 100644 --- a/google/cloud/compute_v1/services/machine_types/transports/rest.py +++ b/google/cloud/compute_v1/services/machine_types/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListMachineTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -200,16 +198,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -263,16 +255,10 @@ def list( if compute.ListMachineTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py b/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py index 4072d4189..30d8036b0 100644 --- a/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py +++ b/google/cloud/compute_v1/services/network_endpoint_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py b/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py index 379877dff..2e485ef0c 100644 --- a/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/network_endpoint_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -144,16 +148,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -240,16 +238,12 @@ def attach_network_endpoints( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -324,16 +318,10 @@ def delete( if compute.DeleteNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -418,16 +406,12 @@ def detach_network_endpoints( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -485,16 +469,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -575,16 +553,12 @@ def insert( if compute.InsertNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -636,16 +610,10 @@ def list( if compute.ListNetworkEndpointGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -718,16 +686,12 @@ def list_network_endpoints( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -781,16 +745,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/networks/transports/base.py b/google/cloud/compute_v1/services/networks/transports/base.py index b2c5fae29..e10e936be 100644 --- a/google/cloud/compute_v1/services/networks/transports/base.py +++ b/google/cloud/compute_v1/services/networks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/networks/transports/rest.py b/google/cloud/compute_v1/services/networks/transports/rest.py index 49cf5043c..b843ea546 100644 --- a/google/cloud/compute_v1/services/networks/transports/rest.py +++ b/google/cloud/compute_v1/services/networks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -163,16 +167,12 @@ def add_peering( if compute.AddPeeringNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -244,16 +244,10 @@ def delete( if compute.DeleteNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -300,16 +294,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -351,16 +339,10 @@ def get_effective_firewalls( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -441,16 +423,12 @@ def insert( if compute.InsertNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -501,16 +479,10 @@ def list( if compute.ListNetworksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -570,16 +542,10 @@ def list_peering_routes( if compute.ListPeeringRoutesNetworksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -659,16 +625,12 @@ def patch( if compute.PatchNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -747,16 +709,12 @@ def remove_peering( if compute.RemovePeeringNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -828,16 +786,10 @@ def switch_to_custom_mode( if compute.SwitchToCustomModeNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -916,16 +868,12 @@ def update_peering( if compute.UpdatePeeringNetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/node_groups/transports/base.py b/google/cloud/compute_v1/services/node_groups/transports/base.py index 8137c560c..eedf04e8b 100644 --- a/google/cloud/compute_v1/services/node_groups/transports/base.py +++ b/google/cloud/compute_v1/services/node_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/node_groups/transports/rest.py b/google/cloud/compute_v1/services/node_groups/transports/rest.py index f8d959868..eff7a170a 100644 --- a/google/cloud/compute_v1/services/node_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/node_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def add_nodes( if compute.AddNodesNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -229,16 +229,10 @@ def aggregated_list( if compute.AggregatedListNodeGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -315,16 +309,10 @@ def delete( if compute.DeleteNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -406,16 +394,12 @@ def delete_nodes( if compute.DeleteNodesNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -468,16 +452,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -579,16 +557,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -664,21 +636,16 @@ def insert( # TODO(yon-mg): handle nested fields corerctly rather than using only top level fields # not required for GCE query_params = {} - if request.initial_node_count: - query_params["initialNodeCount"] = request.initial_node_count + query_params["initialNodeCount"] = request.initial_node_count if compute.InsertNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -730,16 +697,10 @@ def list( if compute.ListNodeGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -796,16 +757,10 @@ def list_nodes( if compute.ListNodesNodeGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -889,16 +844,12 @@ def patch( if compute.PatchNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1000,16 +951,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1091,16 +1038,12 @@ def set_node_template( if compute.SetNodeTemplateNodeGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1152,16 +1095,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/node_templates/transports/base.py b/google/cloud/compute_v1/services/node_templates/transports/base.py index 6d1b2d36a..b53218c1d 100644 --- a/google/cloud/compute_v1/services/node_templates/transports/base.py +++ b/google/cloud/compute_v1/services/node_templates/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/node_templates/transports/rest.py b/google/cloud/compute_v1/services/node_templates/transports/rest.py index ebc7d23d1..a0e261096 100644 --- a/google/cloud/compute_v1/services/node_templates/transports/rest.py +++ b/google/cloud/compute_v1/services/node_templates/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListNodeTemplatesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteNodeTemplateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -284,16 +276,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -397,16 +383,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -485,16 +465,12 @@ def insert( if compute.InsertNodeTemplateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -546,16 +522,10 @@ def list( if compute.ListNodeTemplatesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -659,16 +629,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -720,16 +686,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/node_types/transports/base.py b/google/cloud/compute_v1/services/node_types/transports/base.py index dc7874707..f82cea712 100644 --- a/google/cloud/compute_v1/services/node_types/transports/base.py +++ b/google/cloud/compute_v1/services/node_types/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/node_types/transports/rest.py b/google/cloud/compute_v1/services/node_types/transports/rest.py index 021b92189..c37f08a39 100644 --- a/google/cloud/compute_v1/services/node_types/transports/rest.py +++ b/google/cloud/compute_v1/services/node_types/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListNodeTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -202,16 +200,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -262,16 +254,10 @@ def list( if compute.ListNodeTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py b/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py index db05b3792..c4534cede 100644 --- a/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py +++ b/google/cloud/compute_v1/services/packet_mirrorings/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py b/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py index a16718654..93e9c68be 100644 --- a/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py +++ b/google/cloud/compute_v1/services/packet_mirrorings/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -227,16 +225,10 @@ def delete( if compute.DeletePacketMirroringRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -290,16 +282,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -380,16 +366,12 @@ def insert( if compute.InsertPacketMirroringRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -443,16 +425,10 @@ def list( if compute.ListPacketMirroringsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -536,16 +512,12 @@ def patch( if compute.PatchPacketMirroringRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -597,16 +569,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/projects/transports/base.py b/google/cloud/compute_v1/services/projects/transports/base.py index 8b8d63f3d..e3960b084 100644 --- a/google/cloud/compute_v1/services/projects/transports/base.py +++ b/google/cloud/compute_v1/services/projects/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/projects/transports/rest.py b/google/cloud/compute_v1/services/projects/transports/rest.py index b47df2c13..6c1510d6c 100644 --- a/google/cloud/compute_v1/services/projects/transports/rest.py +++ b/google/cloud/compute_v1/services/projects/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def disable_xpn_host( if compute.DisableXpnHostProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -244,16 +242,12 @@ def disable_xpn_resource( if compute.DisableXpnResourceProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -325,16 +319,10 @@ def enable_xpn_host( if compute.EnableXpnHostProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -413,16 +401,12 @@ def enable_xpn_resource( if compute.EnableXpnResourceProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -469,16 +453,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -526,16 +504,10 @@ def get_xpn_host( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -587,16 +559,10 @@ def get_xpn_resources( if compute.GetXpnResourcesProjectsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -657,16 +623,12 @@ def list_xpn_hosts( if compute.ListXpnHostsProjectsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -747,16 +709,12 @@ def move_disk( if compute.MoveDiskProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -835,16 +793,12 @@ def move_instance( if compute.MoveInstanceProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -924,16 +878,12 @@ def set_common_instance_metadata( if compute.SetCommonInstanceMetadataProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1012,16 +962,12 @@ def set_default_network_tier( if compute.SetDefaultNetworkTierProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1100,16 +1046,12 @@ def set_usage_export_bucket( if compute.SetUsageExportBucketProjectRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py b/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py index 4bd53f7c3..69ff5553d 100644 --- a/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py +++ b/google/cloud/compute_v1/services/public_advertised_prefixes/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py b/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py index f08dbd5eb..7e73748dc 100644 --- a/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py +++ b/google/cloud/compute_v1/services/public_advertised_prefixes/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeletePublicAdvertisedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -217,16 +215,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -307,16 +299,12 @@ def insert( if compute.InsertPublicAdvertisedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -371,16 +359,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -463,16 +445,12 @@ def patch( if compute.PatchPublicAdvertisedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py b/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py index 564ce9f44..df0d122fc 100644 --- a/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py +++ b/google/cloud/compute_v1/services/public_delegated_prefixes/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py b/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py index b4f3b5d04..6c22d7efe 100644 --- a/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py +++ b/google/cloud/compute_v1/services/public_delegated_prefixes/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -144,16 +148,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -230,16 +228,10 @@ def delete( if compute.DeletePublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -293,16 +285,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -383,16 +369,12 @@ def insert( if compute.InsertPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -444,16 +426,10 @@ def list( if compute.ListPublicDelegatedPrefixesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -537,16 +513,12 @@ def patch( if compute.PatchPublicDelegatedPrefixeRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_autoscalers/transports/base.py b/google/cloud/compute_v1/services/region_autoscalers/transports/base.py index a5db46286..b5ff9e4b5 100644 --- a/google/cloud/compute_v1/services/region_autoscalers/transports/base.py +++ b/google/cloud/compute_v1/services/region_autoscalers/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py b/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py index 6fec05122..5758cfa92 100644 --- a/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py +++ b/google/cloud/compute_v1/services/region_autoscalers/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -233,16 +231,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -323,16 +315,12 @@ def insert( if compute.InsertRegionAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -384,16 +372,10 @@ def list( if compute.ListRegionAutoscalersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -476,16 +458,12 @@ def patch( if compute.PatchRegionAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -566,16 +544,12 @@ def update( if compute.UpdateRegionAutoscalerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_backend_services/transports/base.py b/google/cloud/compute_v1/services/region_backend_services/transports/base.py index e6938dbc3..654d4530e 100644 --- a/google/cloud/compute_v1/services/region_backend_services/transports/base.py +++ b/google/cloud/compute_v1/services/region_backend_services/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_backend_services/transports/rest.py b/google/cloud/compute_v1/services/region_backend_services/transports/rest.py index 689be35a9..e0f80a578 100644 --- a/google/cloud/compute_v1/services/region_backend_services/transports/rest.py +++ b/google/cloud/compute_v1/services/region_backend_services/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -235,16 +233,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -298,16 +290,12 @@ def get_health( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -388,16 +376,12 @@ def insert( if compute.InsertRegionBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -451,16 +435,10 @@ def list( if compute.ListRegionBackendServicesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -544,16 +522,12 @@ def patch( if compute.PatchRegionBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -635,16 +609,12 @@ def update( if compute.UpdateRegionBackendServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_commitments/transports/base.py b/google/cloud/compute_v1/services/region_commitments/transports/base.py index 3ff989995..33cf045d1 100644 --- a/google/cloud/compute_v1/services/region_commitments/transports/base.py +++ b/google/cloud/compute_v1/services/region_commitments/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_commitments/transports/rest.py b/google/cloud/compute_v1/services/region_commitments/transports/rest.py index 7f09ed704..91db4d797 100644 --- a/google/cloud/compute_v1/services/region_commitments/transports/rest.py +++ b/google/cloud/compute_v1/services/region_commitments/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -206,16 +204,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -296,16 +288,12 @@ def insert( if compute.InsertRegionCommitmentRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -359,16 +347,10 @@ def list( if compute.ListRegionCommitmentsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_disk_types/transports/base.py b/google/cloud/compute_v1/services/region_disk_types/transports/base.py index d1eba1378..c34ec1dd7 100644 --- a/google/cloud/compute_v1/services/region_disk_types/transports/base.py +++ b/google/cloud/compute_v1/services/region_disk_types/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_disk_types/transports/rest.py b/google/cloud/compute_v1/services/region_disk_types/transports/rest.py index b30cf3f3f..084869510 100644 --- a/google/cloud/compute_v1/services/region_disk_types/transports/rest.py +++ b/google/cloud/compute_v1/services/region_disk_types/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -149,16 +153,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -210,16 +208,10 @@ def list( if compute.ListRegionDiskTypesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_disks/transports/base.py b/google/cloud/compute_v1/services/region_disks/transports/base.py index 4c6b45b9a..a9776d689 100644 --- a/google/cloud/compute_v1/services/region_disks/transports/base.py +++ b/google/cloud/compute_v1/services/region_disks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_disks/transports/rest.py b/google/cloud/compute_v1/services/region_disks/transports/rest.py index 8aa9d1e9f..8a3e9fdc1 100644 --- a/google/cloud/compute_v1/services/region_disks/transports/rest.py +++ b/google/cloud/compute_v1/services/region_disks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def add_resource_policies( if compute.AddResourcePoliciesRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -257,16 +257,12 @@ def create_snapshot( if compute.CreateSnapshotRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -341,16 +337,10 @@ def delete( if compute.DeleteRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -415,16 +405,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -526,16 +510,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -616,16 +594,12 @@ def insert( if compute.InsertRegionDiskRequest.source_image in request: query_params["sourceImage"] = request.source_image - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -677,16 +651,10 @@ def list( if compute.ListRegionDisksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -768,16 +736,12 @@ def remove_resource_policies( if compute.RemoveResourcePoliciesRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -859,16 +823,12 @@ def resize( if compute.ResizeRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -970,16 +930,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1061,16 +1017,12 @@ def set_labels( if compute.SetLabelsRegionDiskRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1122,16 +1074,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_health_check_services/transports/base.py b/google/cloud/compute_v1/services/region_health_check_services/transports/base.py index 73603b9ab..1217f3ece 100644 --- a/google/cloud/compute_v1/services/region_health_check_services/transports/base.py +++ b/google/cloud/compute_v1/services/region_health_check_services/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py b/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py index 162ac4fc8..afd42000e 100644 --- a/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py +++ b/google/cloud/compute_v1/services/region_health_check_services/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionHealthCheckServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -217,16 +215,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -307,16 +299,12 @@ def insert( if compute.InsertRegionHealthCheckServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -371,16 +359,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -464,16 +446,12 @@ def patch( if compute.PatchRegionHealthCheckServiceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_health_checks/transports/base.py b/google/cloud/compute_v1/services/region_health_checks/transports/base.py index 718974545..08473df47 100644 --- a/google/cloud/compute_v1/services/region_health_checks/transports/base.py +++ b/google/cloud/compute_v1/services/region_health_checks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_health_checks/transports/rest.py b/google/cloud/compute_v1/services/region_health_checks/transports/rest.py index 2f1892136..ecf62c3f4 100644 --- a/google/cloud/compute_v1/services/region_health_checks/transports/rest.py +++ b/google/cloud/compute_v1/services/region_health_checks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -241,16 +239,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -331,16 +323,12 @@ def insert( if compute.InsertRegionHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -394,16 +382,10 @@ def list( if compute.ListRegionHealthChecksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -487,16 +469,12 @@ def patch( if compute.PatchRegionHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -578,16 +556,12 @@ def update( if compute.UpdateRegionHealthCheckRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py b/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py index 445228e5b..46ec6826c 100644 --- a/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py +++ b/google/cloud/compute_v1/services/region_instance_group_managers/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py b/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py index 5fbb3771f..f3ffd371c 100644 --- a/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py +++ b/google/cloud/compute_v1/services/region_instance_group_managers/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -169,16 +173,12 @@ def abandon_instances( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -259,16 +259,12 @@ def apply_updates_to_instances( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -353,16 +349,12 @@ def create_instances( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -437,16 +429,10 @@ def delete( if compute.DeleteRegionInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -531,16 +517,12 @@ def delete_instances( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -621,16 +603,12 @@ def delete_per_instance_configs( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -689,16 +667,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -779,16 +751,12 @@ def insert( if compute.InsertRegionInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -845,16 +813,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -914,16 +876,10 @@ def list_errors( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -995,16 +951,10 @@ def list_managed_instances( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1076,16 +1026,10 @@ def list_per_instance_configs( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1169,16 +1113,12 @@ def patch( if compute.PatchRegionInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1264,16 +1204,12 @@ def patch_per_instance_configs( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1358,16 +1294,12 @@ def recreate_instances( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1441,19 +1373,12 @@ def resize( query_params = {} if compute.ResizeRegionInstanceGroupManagerRequest.request_id in request: query_params["requestId"] = request.request_id - if request.size: - query_params["size"] = request.size - - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") + query_params["size"] = request.size # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1538,16 +1463,12 @@ def set_instance_template( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1632,16 +1553,12 @@ def set_target_pools( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1727,16 +1644,12 @@ def update_per_instance_configs( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_instance_groups/transports/base.py b/google/cloud/compute_v1/services/region_instance_groups/transports/base.py index e99b410c4..0b146950e 100644 --- a/google/cloud/compute_v1/services/region_instance_groups/transports/base.py +++ b/google/cloud/compute_v1/services/region_instance_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py b/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py index ef84b6dac..d292688b1 100644 --- a/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/region_instance_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -149,16 +153,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -214,16 +212,10 @@ def list( if compute.ListRegionInstanceGroupsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -290,16 +282,12 @@ def list_instances( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -383,16 +371,12 @@ def set_named_ports( if compute.SetNamedPortsRegionInstanceGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_instances/transports/base.py b/google/cloud/compute_v1/services/region_instances/transports/base.py index 1891660e9..3cb020b59 100644 --- a/google/cloud/compute_v1/services/region_instances/transports/base.py +++ b/google/cloud/compute_v1/services/region_instances/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_instances/transports/rest.py b/google/cloud/compute_v1/services/region_instances/transports/rest.py index 2231e5fd6..eecc61e45 100644 --- a/google/cloud/compute_v1/services/region_instances/transports/rest.py +++ b/google/cloud/compute_v1/services/region_instances/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -163,16 +167,12 @@ def bulk_insert( if compute.BulkInsertRegionInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py b/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py index 39098f4f5..29e5bef3d 100644 --- a/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py +++ b/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py b/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py index 9ae255c0d..368138aec 100644 --- a/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py +++ b/google/cloud/compute_v1/services/region_network_endpoint_groups/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -226,16 +224,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -316,16 +308,12 @@ def insert( if compute.InsertRegionNetworkEndpointGroupRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -380,16 +368,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py b/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py index ec605dee9..20f7be9fc 100644 --- a/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py +++ b/google/cloud/compute_v1/services/region_notification_endpoints/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py b/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py index 8d82c8a7a..19604f40b 100644 --- a/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py +++ b/google/cloud/compute_v1/services/region_notification_endpoints/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionNotificationEndpointRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -223,16 +221,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -313,16 +305,12 @@ def insert( if compute.InsertRegionNotificationEndpointRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -377,16 +365,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_operations/transports/base.py b/google/cloud/compute_v1/services/region_operations/transports/base.py index 1e86fe9be..494a3bc85 100644 --- a/google/cloud/compute_v1/services/region_operations/transports/base.py +++ b/google/cloud/compute_v1/services/region_operations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_operations/transports/rest.py b/google/cloud/compute_v1/services/region_operations/transports/rest.py index a6ad11cb6..9a98a8e72 100644 --- a/google/cloud/compute_v1/services/region_operations/transports/rest.py +++ b/google/cloud/compute_v1/services/region_operations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -132,16 +136,10 @@ def delete( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -216,16 +214,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -279,16 +271,10 @@ def list( if compute.ListRegionOperationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -363,16 +349,10 @@ def wait( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py b/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py index 9366e3a41..83d627233 100644 --- a/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py +++ b/google/cloud/compute_v1/services/region_ssl_certificates/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py b/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py index a7a8e1667..23813cc42 100644 --- a/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py +++ b/google/cloud/compute_v1/services/region_ssl_certificates/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionSslCertificateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -239,16 +237,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -329,16 +321,12 @@ def insert( if compute.InsertRegionSslCertificateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -392,16 +380,10 @@ def list( if compute.ListRegionSslCertificatesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py b/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py index a86add99d..0509d04f7 100644 --- a/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/region_target_http_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py b/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py index 77fe37895..6168212e0 100644 --- a/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/region_target_http_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -236,16 +234,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -326,16 +318,12 @@ def insert( if compute.InsertRegionTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -387,16 +375,10 @@ def list( if compute.ListRegionTargetHttpProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -480,16 +462,12 @@ def set_url_map( if compute.SetUrlMapRegionTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py b/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py index 06ee8b06d..02124d004 100644 --- a/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/region_target_https_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py b/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py index 693ef242d..c80d2b733 100644 --- a/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/region_target_https_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -235,16 +233,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -325,16 +317,12 @@ def insert( if compute.InsertRegionTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -391,16 +379,10 @@ def list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -487,16 +469,12 @@ def set_ssl_certificates( ): query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -578,16 +556,12 @@ def set_url_map( if compute.SetUrlMapRegionTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/region_url_maps/transports/base.py b/google/cloud/compute_v1/services/region_url_maps/transports/base.py index 55db53c6a..d6236858b 100644 --- a/google/cloud/compute_v1/services/region_url_maps/transports/base.py +++ b/google/cloud/compute_v1/services/region_url_maps/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/region_url_maps/transports/rest.py b/google/cloud/compute_v1/services/region_url_maps/transports/rest.py index 9ed6579b1..850f767ba 100644 --- a/google/cloud/compute_v1/services/region_url_maps/transports/rest.py +++ b/google/cloud/compute_v1/services/region_url_maps/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -159,16 +163,10 @@ def delete( if compute.DeleteRegionUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -245,16 +243,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -333,16 +325,12 @@ def insert( if compute.InsertRegionUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -394,16 +382,10 @@ def list( if compute.ListRegionUrlMapsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -487,16 +469,12 @@ def patch( if compute.PatchRegionUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -578,16 +556,12 @@ def update( if compute.UpdateRegionUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -639,16 +613,12 @@ def validate( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/regions/transports/base.py b/google/cloud/compute_v1/services/regions/transports/base.py index 37ff0b0a4..c02266c47 100644 --- a/google/cloud/compute_v1/services/regions/transports/base.py +++ b/google/cloud/compute_v1/services/regions/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/regions/transports/rest.py b/google/cloud/compute_v1/services/regions/transports/rest.py index abbaaecf3..b2b35f0ed 100644 --- a/google/cloud/compute_v1/services/regions/transports/rest.py +++ b/google/cloud/compute_v1/services/regions/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -130,16 +134,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -190,16 +188,10 @@ def list( if compute.ListRegionsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/reservations/transports/base.py b/google/cloud/compute_v1/services/reservations/transports/base.py index c56cccc8b..83b8f4136 100644 --- a/google/cloud/compute_v1/services/reservations/transports/base.py +++ b/google/cloud/compute_v1/services/reservations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/reservations/transports/rest.py b/google/cloud/compute_v1/services/reservations/transports/rest.py index fc1e58093..2da132494 100644 --- a/google/cloud/compute_v1/services/reservations/transports/rest.py +++ b/google/cloud/compute_v1/services/reservations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListReservationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteReservationRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -283,16 +275,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -396,16 +382,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -484,16 +464,12 @@ def insert( if compute.InsertReservationRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -545,16 +521,10 @@ def list( if compute.ListReservationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -638,16 +608,12 @@ def resize( if compute.ResizeReservationRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -749,16 +715,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -810,16 +772,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/resource_policies/transports/base.py b/google/cloud/compute_v1/services/resource_policies/transports/base.py index 46617a036..b4846ad70 100644 --- a/google/cloud/compute_v1/services/resource_policies/transports/base.py +++ b/google/cloud/compute_v1/services/resource_policies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/resource_policies/transports/rest.py b/google/cloud/compute_v1/services/resource_policies/transports/rest.py index 3160a86ac..70ddd8d50 100644 --- a/google/cloud/compute_v1/services/resource_policies/transports/rest.py +++ b/google/cloud/compute_v1/services/resource_policies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -227,16 +225,10 @@ def delete( if compute.DeleteResourcePolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -287,16 +279,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -400,16 +386,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -488,16 +468,12 @@ def insert( if compute.InsertResourcePolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -549,16 +525,10 @@ def list( if compute.ListResourcePoliciesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -662,16 +632,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -723,16 +689,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/routers/transports/base.py b/google/cloud/compute_v1/services/routers/transports/base.py index 11c81a8a7..6d22db5e7 100644 --- a/google/cloud/compute_v1/services/routers/transports/base.py +++ b/google/cloud/compute_v1/services/routers/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/routers/transports/rest.py b/google/cloud/compute_v1/services/routers/transports/rest.py index f8adad2b4..c99d8d566 100644 --- a/google/cloud/compute_v1/services/routers/transports/rest.py +++ b/google/cloud/compute_v1/services/routers/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListRoutersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -223,16 +221,10 @@ def delete( if compute.DeleteRouterRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -279,16 +271,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -345,16 +331,10 @@ def get_nat_mapping_info( if compute.GetNatMappingInfoRoutersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -401,16 +381,10 @@ def get_router_status( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -490,16 +464,12 @@ def insert( if compute.InsertRouterRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -550,16 +520,10 @@ def list( if compute.ListRoutersRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -642,16 +606,12 @@ def patch( if compute.PatchRouterRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -703,16 +663,12 @@ def preview( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -795,16 +751,12 @@ def update( if compute.UpdateRouterRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/routes/transports/base.py b/google/cloud/compute_v1/services/routes/transports/base.py index 521530b01..846a9396e 100644 --- a/google/cloud/compute_v1/services/routes/transports/base.py +++ b/google/cloud/compute_v1/services/routes/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/routes/transports/rest.py b/google/cloud/compute_v1/services/routes/transports/rest.py index 71d37948d..5cab754e7 100644 --- a/google/cloud/compute_v1/services/routes/transports/rest.py +++ b/google/cloud/compute_v1/services/routes/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -155,16 +159,10 @@ def delete( if compute.DeleteRouteRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -212,16 +210,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -299,16 +291,12 @@ def insert( if compute.InsertRouteRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -359,16 +347,10 @@ def list( if compute.ListRoutesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/security_policies/transports/base.py b/google/cloud/compute_v1/services/security_policies/transports/base.py index 4b4a7d916..2e6042ab3 100644 --- a/google/cloud/compute_v1/services/security_policies/transports/base.py +++ b/google/cloud/compute_v1/services/security_policies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/security_policies/transports/rest.py b/google/cloud/compute_v1/services/security_policies/transports/rest.py index 6daf2952b..a760203ad 100644 --- a/google/cloud/compute_v1/services/security_policies/transports/rest.py +++ b/google/cloud/compute_v1/services/security_policies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -163,16 +167,12 @@ def add_rule( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -246,16 +246,10 @@ def delete( if compute.DeleteSecurityPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -306,16 +300,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -367,16 +355,10 @@ def get_rule( if compute.GetRuleSecurityPolicyRequest.priority in request: query_params["priority"] = request.priority - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -457,16 +439,12 @@ def insert( if compute.InsertSecurityPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -518,16 +496,10 @@ def list( if compute.ListSecurityPoliciesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -597,16 +569,10 @@ def list_preconfigured_expression_sets( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -689,16 +655,12 @@ def patch( if compute.PatchSecurityPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -779,16 +741,12 @@ def patch_rule( if compute.PatchRuleSecurityPolicyRequest.priority in request: query_params["priority"] = request.priority - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -862,16 +820,10 @@ def remove_rule( if compute.RemoveRuleSecurityPolicyRequest.priority in request: query_params["priority"] = request.priority - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/snapshots/transports/base.py b/google/cloud/compute_v1/services/snapshots/transports/base.py index d3981daf1..e34d66a84 100644 --- a/google/cloud/compute_v1/services/snapshots/transports/base.py +++ b/google/cloud/compute_v1/services/snapshots/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/snapshots/transports/rest.py b/google/cloud/compute_v1/services/snapshots/transports/rest.py index 5262e7b57..b31df569e 100644 --- a/google/cloud/compute_v1/services/snapshots/transports/rest.py +++ b/google/cloud/compute_v1/services/snapshots/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def delete( if compute.DeleteSnapshotRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -212,16 +210,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -320,16 +312,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -382,16 +368,10 @@ def list( if compute.ListSnapshotsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -492,16 +472,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -578,16 +554,12 @@ def set_labels( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -636,16 +608,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/ssl_certificates/transports/base.py b/google/cloud/compute_v1/services/ssl_certificates/transports/base.py index 9012f2be6..0b9d8a4ea 100644 --- a/google/cloud/compute_v1/services/ssl_certificates/transports/base.py +++ b/google/cloud/compute_v1/services/ssl_certificates/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py b/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py index 05641956a..b97e2857f 100644 --- a/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py +++ b/google/cloud/compute_v1/services/ssl_certificates/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -226,16 +224,10 @@ def delete( if compute.DeleteSslCertificateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -305,16 +297,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -395,16 +381,12 @@ def insert( if compute.InsertSslCertificateRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -458,16 +440,10 @@ def list( if compute.ListSslCertificatesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/ssl_policies/transports/base.py b/google/cloud/compute_v1/services/ssl_policies/transports/base.py index d50542c46..bb586a325 100644 --- a/google/cloud/compute_v1/services/ssl_policies/transports/base.py +++ b/google/cloud/compute_v1/services/ssl_policies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/ssl_policies/transports/rest.py b/google/cloud/compute_v1/services/ssl_policies/transports/rest.py index 879c1e41d..7d2a941e6 100644 --- a/google/cloud/compute_v1/services/ssl_policies/transports/rest.py +++ b/google/cloud/compute_v1/services/ssl_policies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -156,16 +160,10 @@ def delete( if compute.DeleteSslPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -214,16 +212,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -302,16 +294,12 @@ def insert( if compute.InsertSslPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -363,16 +351,10 @@ def list( if compute.ListSslPoliciesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -429,16 +411,10 @@ def list_available_features( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -519,16 +495,12 @@ def patch( if compute.PatchSslPolicyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/subnetworks/transports/base.py b/google/cloud/compute_v1/services/subnetworks/transports/base.py index 62c836563..ff3498abe 100644 --- a/google/cloud/compute_v1/services/subnetworks/transports/base.py +++ b/google/cloud/compute_v1/services/subnetworks/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/subnetworks/transports/rest.py b/google/cloud/compute_v1/services/subnetworks/transports/rest.py index da10ad4bd..937372058 100644 --- a/google/cloud/compute_v1/services/subnetworks/transports/rest.py +++ b/google/cloud/compute_v1/services/subnetworks/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListSubnetworksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteSubnetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -315,16 +307,12 @@ def expand_ip_cidr_range( if compute.ExpandIpCidrRangeSubnetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -376,16 +364,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -489,16 +471,10 @@ def get_iam_policy( "optionsRequestedPolicyVersion" ] = request.options_requested_policy_version - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -577,16 +553,12 @@ def insert( if compute.InsertSubnetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -640,16 +612,10 @@ def list( if compute.ListSubnetworksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -703,16 +669,10 @@ def list_usable( if compute.ListUsableSubnetworksRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -798,16 +758,12 @@ def patch( if compute.PatchSubnetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -909,16 +865,12 @@ def set_iam_policy( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1001,16 +953,12 @@ def set_private_ip_google_access( if compute.SetPrivateIpGoogleAccessSubnetworkRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -1062,16 +1010,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py b/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py index 215c7f87f..575168607 100644 --- a/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/target_grpc_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py b/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py index 8080fea93..a28d8cc55 100644 --- a/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/target_grpc_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteTargetGrpcProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -221,16 +219,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -311,16 +303,12 @@ def insert( if compute.InsertTargetGrpcProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -372,16 +360,10 @@ def list( if compute.ListTargetGrpcProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -464,16 +446,12 @@ def patch( if compute.PatchTargetGrpcProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_http_proxies/transports/base.py b/google/cloud/compute_v1/services/target_http_proxies/transports/base.py index dd4c72f5c..efb28747b 100644 --- a/google/cloud/compute_v1/services/target_http_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/target_http_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py b/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py index e25f2db5b..3926b166a 100644 --- a/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/target_http_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -226,16 +224,10 @@ def delete( if compute.DeleteTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -302,16 +294,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -392,16 +378,12 @@ def insert( if compute.InsertTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -453,16 +435,10 @@ def list( if compute.ListTargetHttpProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -545,16 +521,12 @@ def patch( if compute.PatchTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -635,16 +607,12 @@ def set_url_map( if compute.SetUrlMapTargetHttpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_https_proxies/transports/base.py b/google/cloud/compute_v1/services/target_https_proxies/transports/base.py index b61aa7ea7..efe301a6a 100644 --- a/google/cloud/compute_v1/services/target_https_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/target_https_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py b/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py index 78323edfc..d247a2884 100644 --- a/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/target_https_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -144,16 +148,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -229,16 +227,10 @@ def delete( if compute.DeleteTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -304,16 +296,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -394,16 +380,12 @@ def insert( if compute.InsertTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -457,16 +439,10 @@ def list( if compute.ListTargetHttpsProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -549,16 +525,12 @@ def patch( if compute.PatchTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -639,16 +611,12 @@ def set_quic_override( if compute.SetQuicOverrideTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -729,16 +697,12 @@ def set_ssl_certificates( if compute.SetSslCertificatesTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -819,16 +783,12 @@ def set_ssl_policy( if compute.SetSslPolicyTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -909,16 +869,12 @@ def set_url_map( if compute.SetUrlMapTargetHttpsProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_instances/transports/base.py b/google/cloud/compute_v1/services/target_instances/transports/base.py index f8ac05a91..3f6318c9e 100644 --- a/google/cloud/compute_v1/services/target_instances/transports/base.py +++ b/google/cloud/compute_v1/services/target_instances/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_instances/transports/rest.py b/google/cloud/compute_v1/services/target_instances/transports/rest.py index fa1ce2cfa..8268725ce 100644 --- a/google/cloud/compute_v1/services/target_instances/transports/rest.py +++ b/google/cloud/compute_v1/services/target_instances/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -227,16 +225,10 @@ def delete( if compute.DeleteTargetInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -289,16 +281,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -379,16 +365,12 @@ def insert( if compute.InsertTargetInstanceRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -442,16 +424,10 @@ def list( if compute.ListTargetInstancesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_pools/transports/base.py b/google/cloud/compute_v1/services/target_pools/transports/base.py index b52bab2b2..04f55ad82 100644 --- a/google/cloud/compute_v1/services/target_pools/transports/base.py +++ b/google/cloud/compute_v1/services/target_pools/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_pools/transports/rest.py b/google/cloud/compute_v1/services/target_pools/transports/rest.py index a3c4b8576..3aa89f507 100644 --- a/google/cloud/compute_v1/services/target_pools/transports/rest.py +++ b/google/cloud/compute_v1/services/target_pools/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -166,16 +170,12 @@ def add_health_check( if compute.AddHealthCheckTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -257,16 +257,12 @@ def add_instance( if compute.AddInstanceTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -320,16 +316,10 @@ def aggregated_list( if compute.AggregatedListTargetPoolsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -406,16 +396,10 @@ def delete( if compute.DeleteTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -468,16 +452,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -531,16 +509,12 @@ def get_health( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -621,16 +595,12 @@ def insert( if compute.InsertTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -684,16 +654,10 @@ def list( if compute.ListTargetPoolsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -777,16 +741,12 @@ def remove_health_check( if compute.RemoveHealthCheckTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -868,16 +828,12 @@ def remove_instance( if compute.RemoveInstanceTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -961,16 +917,12 @@ def set_backup( if compute.SetBackupTargetPoolRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py b/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py index 915977f48..7ab3639a9 100644 --- a/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/target_ssl_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py b/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py index 0353da0ab..8cbd9875a 100644 --- a/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/target_ssl_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -219,16 +217,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -309,16 +301,12 @@ def insert( if compute.InsertTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -372,16 +360,10 @@ def list( if compute.ListTargetSslProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -464,16 +446,12 @@ def set_backend_service( if compute.SetBackendServiceTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -554,16 +532,12 @@ def set_proxy_header( if compute.SetProxyHeaderTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -644,16 +618,12 @@ def set_ssl_certificates( if compute.SetSslCertificatesTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -734,16 +704,12 @@ def set_ssl_policy( if compute.SetSslPolicyTargetSslProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py b/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py index fd2e5de69..2ac783c3a 100644 --- a/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py +++ b/google/cloud/compute_v1/services/target_tcp_proxies/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py b/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py index 6691e2e35..8476f9448 100644 --- a/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py +++ b/google/cloud/compute_v1/services/target_tcp_proxies/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -158,16 +162,10 @@ def delete( if compute.DeleteTargetTcpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -219,16 +217,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -309,16 +301,12 @@ def insert( if compute.InsertTargetTcpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -372,16 +360,10 @@ def list( if compute.ListTargetTcpProxiesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -464,16 +446,12 @@ def set_backend_service( if compute.SetBackendServiceTargetTcpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -554,16 +532,12 @@ def set_proxy_header( if compute.SetProxyHeaderTargetTcpProxyRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py b/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py index 0891f62b6..7b33ee556 100644 --- a/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py +++ b/google/cloud/compute_v1/services/target_vpn_gateways/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py b/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py index a7258cb1b..498677658 100644 --- a/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py +++ b/google/cloud/compute_v1/services/target_vpn_gateways/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -141,16 +145,10 @@ def aggregated_list( ): query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -227,16 +225,10 @@ def delete( if compute.DeleteTargetVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -287,16 +279,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -377,16 +363,12 @@ def insert( if compute.InsertTargetVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -440,16 +422,10 @@ def list( if compute.ListTargetVpnGatewaysRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/url_maps/transports/base.py b/google/cloud/compute_v1/services/url_maps/transports/base.py index 7bc812c6a..c7d9f1373 100644 --- a/google/cloud/compute_v1/services/url_maps/transports/base.py +++ b/google/cloud/compute_v1/services/url_maps/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/url_maps/transports/rest.py b/google/cloud/compute_v1/services/url_maps/transports/rest.py index 4b0da7c2e..a186a0105 100644 --- a/google/cloud/compute_v1/services/url_maps/transports/rest.py +++ b/google/cloud/compute_v1/services/url_maps/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListUrlMapsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -220,16 +218,10 @@ def delete( if compute.DeleteUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -302,16 +294,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -389,16 +375,12 @@ def insert( if compute.InsertUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -477,16 +459,12 @@ def invalidate_cache( if compute.InvalidateCacheUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -537,16 +515,10 @@ def list( if compute.ListUrlMapsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -626,16 +598,12 @@ def patch( if compute.PatchUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.patch(url, headers=headers, data=body,) + response = self._session.patch( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -713,16 +681,12 @@ def update( if compute.UpdateUrlMapRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.put(url, headers=headers, data=body,) + response = self._session.put( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -771,16 +735,12 @@ def validate( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/vpn_gateways/transports/base.py b/google/cloud/compute_v1/services/vpn_gateways/transports/base.py index 0c5df8dc6..5e4c8d357 100644 --- a/google/cloud/compute_v1/services/vpn_gateways/transports/base.py +++ b/google/cloud/compute_v1/services/vpn_gateways/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py b/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py index a2c2367d2..bd80ef898 100644 --- a/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py +++ b/google/cloud/compute_v1/services/vpn_gateways/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListVpnGatewaysRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -287,16 +279,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -343,16 +329,10 @@ def get_status( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -433,16 +413,12 @@ def insert( if compute.InsertVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -496,16 +472,10 @@ def list( if compute.ListVpnGatewaysRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -589,16 +559,12 @@ def set_labels( if compute.SetLabelsVpnGatewayRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -650,16 +616,12 @@ def test_iam_permissions( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py b/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py index b741537d4..117cf5efe 100644 --- a/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py +++ b/google/cloud/compute_v1/services/vpn_tunnels/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py b/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py index ae8cde683..a37cdabe0 100644 --- a/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py +++ b/google/cloud/compute_v1/services/vpn_tunnels/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -138,16 +142,10 @@ def aggregated_list( if compute.AggregatedListVpnTunnelsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -224,16 +222,10 @@ def delete( if compute.DeleteVpnTunnelRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -281,16 +273,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -369,16 +355,12 @@ def insert( if compute.InsertVpnTunnelRequest.request_id in request: query_params["requestId"] = request.request_id - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers, data=body,) + response = self._session.post( + url, headers=headers, params=query_params, data=body, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -432,16 +414,10 @@ def list( if compute.ListVpnTunnelsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/zone_operations/transports/base.py b/google/cloud/compute_v1/services/zone_operations/transports/base.py index 2cadcbf5a..9122556e4 100644 --- a/google/cloud/compute_v1/services/zone_operations/transports/base.py +++ b/google/cloud/compute_v1/services/zone_operations/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -66,6 +67,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,6 +91,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -98,7 +102,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -117,6 +121,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/zone_operations/transports/rest.py b/google/cloud/compute_v1/services/zone_operations/transports/rest.py index d156bf23b..fd18f16ab 100644 --- a/google/cloud/compute_v1/services/zone_operations/transports/rest.py +++ b/google/cloud/compute_v1/services/zone_operations/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -132,16 +136,10 @@ def delete( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.delete(url, headers=headers,) + response = self._session.delete(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -216,16 +214,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -279,16 +271,10 @@ def list( if compute.ListZoneOperationsRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -363,16 +349,10 @@ def wait( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.post(url, headers=headers,) + response = self._session.post(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/services/zones/transports/base.py b/google/cloud/compute_v1/services/zones/transports/base.py index e9a50e5f1..3beec763a 100644 --- a/google/cloud/compute_v1/services/zones/transports/base.py +++ b/google/cloud/compute_v1/services/zones/transports/base.py @@ -25,6 +25,7 @@ from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.compute_v1.types import compute @@ -67,6 +68,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,6 +92,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: @@ -99,7 +103,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,6 +122,14 @@ def __init__( **scopes_kwargs, quota_project_id=quota_project_id ) + # If the credentials is service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + # Save the credentials. self._credentials = credentials diff --git a/google/cloud/compute_v1/services/zones/transports/rest.py b/google/cloud/compute_v1/services/zones/transports/rest.py index 955c583f0..c3ad59ff5 100644 --- a/google/cloud/compute_v1/services/zones/transports/rest.py +++ b/google/cloud/compute_v1/services/zones/transports/rest.py @@ -52,6 +52,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,7 +86,10 @@ def __init__( # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the # credentials object super().__init__( - host=host, credentials=credentials, client_info=client_info, + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) self._session = AuthorizedSession( self._credentials, default_host=self.DEFAULT_HOST @@ -132,16 +136,10 @@ def get( # not required for GCE query_params = {} - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -192,16 +190,10 @@ def list( if compute.ListZonesRequest.return_partial_success in request: query_params["returnPartialSuccess"] = request.return_partial_success - # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here - # discards default values - # TODO(yon-mg): add test for proper url encoded strings - query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()] - url += "?{}".format("&".join(query_params)).replace(" ", "+") - # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" - response = self._session.get(url, headers=headers,) + response = self._session.get(url, headers=headers, params=query_params,) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. diff --git a/google/cloud/compute_v1/types/compute.py b/google/cloud/compute_v1/types/compute.py index 182ce63ae..1729ee0a6 100644 --- a/google/cloud/compute_v1/types/compute.py +++ b/google/cloud/compute_v1/types/compute.py @@ -1257,7 +1257,7 @@ class AcceleratorType(proto.Message): description (str): [Output Only] An optional textual description of the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -1283,7 +1283,7 @@ class AcceleratorType(proto.Message): proto.MESSAGE, number=515138995, optional=True, message="DeprecationStatus", ) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) maximum_cards_per_instance = proto.Field( proto.INT32, number=263814482, optional=True, @@ -1590,7 +1590,7 @@ class Address(proto.Message): description (str): An optional description of this resource. Provide this field when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. ip_version (google.cloud.compute_v1.types.Address.IpVersion): @@ -1748,7 +1748,7 @@ class Status(proto.Enum): ) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ip_version = proto.Field( proto.ENUM, number=294959552, optional=True, enum=IpVersion, ) @@ -1921,7 +1921,7 @@ class AllocationSpecificSKUAllocationAllocatedInstancePropertiesReservedDisk( ): r""" Attributes: - disk_size_gb (str): + disk_size_gb (int): Specifies the size of the disk in base-2 GB. interface (google.cloud.compute_v1.types.AllocationSpecificSKUAllocationAllocatedInstancePropertiesReservedDisk.Interface): Specifies the disk interface to use for @@ -1941,7 +1941,7 @@ class Interface(proto.Enum): NVME = 2408800 SCSI = 2539686 - disk_size_gb = proto.Field(proto.STRING, number=316263735, optional=True,) + disk_size_gb = proto.Field(proto.INT64, number=316263735, optional=True,) interface = proto.Field( proto.ENUM, number=502623545, optional=True, enum=Interface, ) @@ -1987,17 +1987,17 @@ class AllocationSpecificSKUReservation(proto.Message): instance configuration. Attributes: - count (str): + count (int): Specifies the number of resources that are allocated. - in_use_count (str): + in_use_count (int): [Output Only] Indicates how many instances are in use. instance_properties (google.cloud.compute_v1.types.AllocationSpecificSKUAllocationReservedInstanceProperties): The instance properties for the reservation. """ - count = proto.Field(proto.STRING, number=94851343, optional=True,) - in_use_count = proto.Field(proto.STRING, number=493458877, optional=True,) + count = proto.Field(proto.INT64, number=94851343, optional=True,) + in_use_count = proto.Field(proto.INT64, number=493458877, optional=True,) instance_properties = proto.Field( proto.MESSAGE, number=215355165, @@ -2080,7 +2080,7 @@ class AttachedDiskInitializeParams(proto.Message): the given region, the existing disk is attached to the new instance and the new disk is not created. - disk_size_gb (str): + disk_size_gb (int): Specifies the size of the disk in base-2 GB. The size must be at least 10 GB. If you specify a sourceImage, which is required for boot disks, @@ -2113,7 +2113,7 @@ class AttachedDiskInitializeParams(proto.Message): Specifies which action to take on instance update with this disk. Default is to use the existing disk. - provisioned_iops (str): + provisioned_iops (int): Indicates how many IOPS must be provisioned for the disk. resource_policies (Sequence[str]): @@ -2186,13 +2186,13 @@ class OnUpdateAction(proto.Enum): description = proto.Field(proto.STRING, number=422937596, optional=True,) disk_name = proto.Field(proto.STRING, number=92807149, optional=True,) - disk_size_gb = proto.Field(proto.STRING, number=316263735, optional=True,) + disk_size_gb = proto.Field(proto.INT64, number=316263735, optional=True,) disk_type = proto.Field(proto.STRING, number=93009052, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) on_update_action = proto.Field( proto.ENUM, number=202451980, optional=True, enum=OnUpdateAction, ) - provisioned_iops = proto.Field(proto.STRING, number=186769108, optional=True,) + provisioned_iops = proto.Field(proto.INT64, number=186769108, optional=True,) resource_policies = proto.RepeatedField(proto.STRING, number=22220385,) source_image = proto.Field(proto.STRING, number=50443319, optional=True,) source_image_encryption_key = proto.Field( @@ -2277,7 +2277,7 @@ class AttachedDisk(proto.Message): supplied encryption keys, so you cannot use your own keys to encrypt disks in a managed instance group. - disk_size_gb (str): + disk_size_gb (int): The size of the disk in GB. guest_os_features (Sequence[google.cloud.compute_v1.types.GuestOsFeature]): A list of features to enable on the guest @@ -2370,7 +2370,7 @@ class Type(proto.Enum): disk_encryption_key = proto.Field( proto.MESSAGE, number=271660677, optional=True, message="CustomerEncryptionKey", ) - disk_size_gb = proto.Field(proto.STRING, number=316263735, optional=True,) + disk_size_gb = proto.Field(proto.INT64, number=316263735, optional=True,) guest_os_features = proto.RepeatedField( proto.MESSAGE, number=79294545, message="GuestOsFeature", ) @@ -2789,7 +2789,7 @@ class Autoscaler(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -2870,7 +2870,7 @@ class Status(proto.Enum): ) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) recommended_size = proto.Field(proto.INT32, number=257915749, optional=True,) @@ -3502,7 +3502,7 @@ class BackendBucketCdnPolicy(proto.Message): cached response. The maximum allowed value is 604800 (1 week). Set this to zero (0) to disable serve-while-stale. - signed_url_cache_max_age_sec (str): + signed_url_cache_max_age_sec (int): Maximum number of seconds the response to a signed URL request will be considered fresh. After this time period, the response will be revalidated before being served. @@ -3563,7 +3563,7 @@ class CacheMode(proto.Enum): request_coalescing = proto.Field(proto.BOOL, number=532808276, optional=True,) serve_while_stale = proto.Field(proto.INT32, number=236682203, optional=True,) signed_url_cache_max_age_sec = proto.Field( - proto.STRING, number=269374534, optional=True, + proto.INT64, number=269374534, optional=True, ) signed_url_key_names = proto.RepeatedField(proto.STRING, number=371848885,) @@ -3591,7 +3591,7 @@ class BackendBucket(proto.Message): enable_cdn (bool): If true, enable Cloud CDN for this BackendBucket. - id (str): + id (int): [Output Only] Unique identifier for the resource; defined by the server. kind (str): @@ -3620,7 +3620,7 @@ class BackendBucket(proto.Message): custom_response_headers = proto.RepeatedField(proto.STRING, number=387539094,) description = proto.Field(proto.STRING, number=422937596, optional=True,) enable_cdn = proto.Field(proto.BOOL, number=282942321, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) self_link = proto.Field(proto.STRING, number=456214797, optional=True,) @@ -3817,7 +3817,7 @@ class BackendServiceCdnPolicy(proto.Message): cached response. The maximum allowed value is 604800 (1 week). Set this to zero (0) to disable serve-while-stale. - signed_url_cache_max_age_sec (str): + signed_url_cache_max_age_sec (int): Maximum number of seconds the response to a signed URL request will be considered fresh. After this time period, the response will be revalidated before being served. @@ -3881,7 +3881,7 @@ class CacheMode(proto.Enum): request_coalescing = proto.Field(proto.BOOL, number=532808276, optional=True,) serve_while_stale = proto.Field(proto.INT32, number=236682203, optional=True,) signed_url_cache_max_age_sec = proto.Field( - proto.STRING, number=269374534, optional=True, + proto.INT64, number=269374534, optional=True, ) signed_url_key_names = proto.RepeatedField(proto.STRING, number=371848885,) @@ -3953,7 +3953,7 @@ class ConsistentHashLoadBalancerSettings(proto.Message): The hash based on the value of the specified header field. This field is applicable if the sessionAffinity is set to HEADER_FIELD. - minimum_ring_size (str): + minimum_ring_size (int): The minimum number of virtual nodes to use for the hash ring. Defaults to 1024. Larger ring sizes result in more granular load @@ -3970,7 +3970,7 @@ class ConsistentHashLoadBalancerSettings(proto.Message): message="ConsistentHashLoadBalancerSettingsHttpCookie", ) http_header_name = proto.Field(proto.STRING, number=234798022, optional=True,) - minimum_ring_size = proto.Field(proto.STRING, number=234380735, optional=True,) + minimum_ring_size = proto.Field(proto.INT64, number=234380735, optional=True,) class BackendServiceFailoverPolicy(proto.Message): @@ -4082,7 +4082,7 @@ class Duration(proto.Message): resolution. Durations less than one second are represented with a 0 ``seconds`` field and a positive ``nanos`` field. Must be from 0 to 999,999,999 inclusive. - seconds (str): + seconds (int): Span of time at a resolution of a second. Must be from 0 to 315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min \* 60 min/hr \* 24 hr/day \* 365.25 @@ -4090,7 +4090,7 @@ class Duration(proto.Message): """ nanos = proto.Field(proto.INT32, number=104586303, optional=True,) - seconds = proto.Field(proto.STRING, number=359484031, optional=True,) + seconds = proto.Field(proto.INT64, number=359484031, optional=True,) class OutlierDetection(proto.Message): @@ -4364,7 +4364,7 @@ class BackendService(proto.Message): on this resource. Not available for Internal TCP/UDP Load Balancing and Network Load Balancing. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -4695,7 +4695,7 @@ class SessionAffinity(proto.Enum): iap = proto.Field( proto.MESSAGE, number=104024, optional=True, message="BackendServiceIAP", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) load_balancing_scheme = proto.Field( proto.ENUM, number=363890244, optional=True, enum=LoadBalancingScheme, @@ -5318,7 +5318,7 @@ class BulkInsertInstanceResourcePerInstanceProperties(proto.Message): class BulkInsertInstanceResource(proto.Message): r""" Attributes: - count (str): + count (int): The maximum number of instances to create. instance_properties (google.cloud.compute_v1.types.InstanceProperties): The instance properties defining the VM @@ -5326,7 +5326,7 @@ class BulkInsertInstanceResource(proto.Message): sourceInstanceTemplate is not provided. location_policy (google.cloud.compute_v1.types.LocationPolicy): Policy for chosing target zone. - min_count (str): + min_count (int): The minimum number of instances to create. If no min_count is specified then count is used as the default value. If min_count instances cannot be created, then no instances @@ -5369,14 +5369,14 @@ class BulkInsertInstanceResource(proto.Message): This field is optional. """ - count = proto.Field(proto.STRING, number=94851343, optional=True,) + count = proto.Field(proto.INT64, number=94851343, optional=True,) instance_properties = proto.Field( proto.MESSAGE, number=215355165, optional=True, message="InstanceProperties", ) location_policy = proto.Field( proto.MESSAGE, number=465689852, optional=True, message="LocationPolicy", ) - min_count = proto.Field(proto.STRING, number=523228386, optional=True,) + min_count = proto.Field(proto.INT64, number=523228386, optional=True,) name_pattern = proto.Field(proto.STRING, number=413815260, optional=True,) per_instance_properties = proto.MapField( proto.STRING, @@ -5407,7 +5407,7 @@ class CacheInvalidationRule(proto.Message): class LicenseResourceCommitment(proto.Message): r"""Commitment for a particular license resource. Attributes: - amount (str): + amount (int): The number of licenses purchased. cores_per_license (str): Specifies the core range of the instance for @@ -5416,7 +5416,7 @@ class LicenseResourceCommitment(proto.Message): Any applicable license URI. """ - amount = proto.Field(proto.STRING, number=196759640, optional=True,) + amount = proto.Field(proto.INT64, number=196759640, optional=True,) cores_per_license = proto.Field(proto.STRING, number=32482324, optional=True,) license_ = proto.Field(proto.STRING, number=166757441, optional=True,) @@ -5438,7 +5438,7 @@ class Reservation(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -5487,7 +5487,7 @@ class Status(proto.Enum): commitment = proto.Field(proto.STRING, number=482134805, optional=True,) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) satisfies_pzs = proto.Field(proto.BOOL, number=480964267, optional=True,) @@ -5513,7 +5513,7 @@ class ResourceCommitment(proto.Message): accelerator_type (str): Name of the accelerator type resource. Applicable only when the type is ACCELERATOR. - amount (str): + amount (int): The amount of the resource purchased (in a type-dependent unit, such as bytes). For vCPUs, this can just be an integer. For memory, this @@ -5537,7 +5537,7 @@ class Type(proto.Enum): VCPU = 2628978 accelerator_type = proto.Field(proto.STRING, number=138031246, optional=True,) - amount = proto.Field(proto.STRING, number=196759640, optional=True,) + amount = proto.Field(proto.INT64, number=196759640, optional=True,) type_ = proto.Field(proto.ENUM, number=3575610, optional=True, enum=Type,) @@ -5568,7 +5568,7 @@ class Commitment(proto.Message): resource. end_timestamp (str): [Output Only] Commitment end time in RFC3339 text format. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -5651,7 +5651,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) end_timestamp = proto.Field(proto.STRING, number=468096690, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) license_resource = proto.Field( proto.MESSAGE, @@ -5951,7 +5951,7 @@ class Disk(proto.Message): operating system. Applicable only for bootable images. Read Enabling guest operating system features to see a list of available options. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -5976,7 +5976,7 @@ class Disk(proto.Message): [Output Only] Last attach timestamp in RFC3339 text format. last_detach_timestamp (str): [Output Only] Last detach timestamp in RFC3339 text format. - license_codes (Sequence[str]): + license_codes (Sequence[int]): Integer license codes indicating which licenses are attached to this disk. licenses (Sequence[str]): @@ -5997,7 +5997,7 @@ class Disk(proto.Message): except the last character, which cannot be a dash. options (str): Internal use only. - physical_block_size_bytes (str): + physical_block_size_bytes (int): Physical block size of the persistent disk, in bytes. If not present in a request, a default value is used. The currently supported size is @@ -6005,7 +6005,7 @@ class Disk(proto.Message): an unsupported value is requested, the error message will list the supported values for the caller's project. - provisioned_iops (str): + provisioned_iops (int): Indicates how many IOPS must be provisioned for the disk. region (str): @@ -6025,7 +6025,7 @@ class Disk(proto.Message): self_link (str): [Output Only] Server-defined fully-qualified URL for this resource. - size_gb (str): + size_gb (int): Size, in GB, of the persistent disk. You can specify this field when creating a persistent disk using the sourceImage, sourceSnapshot, or @@ -6169,27 +6169,27 @@ class Status(proto.Enum): guest_os_features = proto.RepeatedField( proto.MESSAGE, number=79294545, message="GuestOsFeature", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) label_fingerprint = proto.Field(proto.STRING, number=178124825, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) last_attach_timestamp = proto.Field(proto.STRING, number=42159653, optional=True,) last_detach_timestamp = proto.Field(proto.STRING, number=56471027, optional=True,) - license_codes = proto.RepeatedField(proto.STRING, number=45482664,) + license_codes = proto.RepeatedField(proto.INT64, number=45482664,) licenses = proto.RepeatedField(proto.STRING, number=337642578,) location_hint = proto.Field(proto.STRING, number=350519505, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) options = proto.Field(proto.STRING, number=361137822, optional=True,) physical_block_size_bytes = proto.Field( - proto.STRING, number=420007943, optional=True, + proto.INT64, number=420007943, optional=True, ) - provisioned_iops = proto.Field(proto.STRING, number=186769108, optional=True,) + provisioned_iops = proto.Field(proto.INT64, number=186769108, optional=True,) region = proto.Field(proto.STRING, number=138946292, optional=True,) replica_zones = proto.RepeatedField(proto.STRING, number=48438272,) resource_policies = proto.RepeatedField(proto.STRING, number=22220385,) satisfies_pzs = proto.Field(proto.BOOL, number=480964267, optional=True,) self_link = proto.Field(proto.STRING, number=456214797, optional=True,) - size_gb = proto.Field(proto.STRING, number=494929369, optional=True,) + size_gb = proto.Field(proto.INT64, number=494929369, optional=True,) source_disk = proto.Field(proto.STRING, number=451753793, optional=True,) source_disk_id = proto.Field(proto.STRING, number=454190809, optional=True,) source_image = proto.Field(proto.STRING, number=50443319, optional=True,) @@ -6423,14 +6423,14 @@ class DiskType(proto.Message): Attributes: creation_timestamp (str): [Output Only] Creation timestamp in RFC3339 text format. - default_disk_size_gb (str): + default_disk_size_gb (int): [Output Only] Server-defined default disk size in GB. deprecated (google.cloud.compute_v1.types.DeprecationStatus): [Output Only] The deprecation status associated with this disk type. description (str): [Output Only] An optional description of this resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -6455,12 +6455,12 @@ class DiskType(proto.Message): """ creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) - default_disk_size_gb = proto.Field(proto.STRING, number=270619253, optional=True,) + default_disk_size_gb = proto.Field(proto.INT64, number=270619253, optional=True,) deprecated = proto.Field( proto.MESSAGE, number=515138995, optional=True, message="DeprecationStatus", ) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) region = proto.Field(proto.STRING, number=138946292, optional=True,) @@ -6593,12 +6593,12 @@ class DisksRemoveResourcePoliciesRequest(proto.Message): class DisksResizeRequest(proto.Message): r""" Attributes: - size_gb (str): + size_gb (int): The new size of the persistent disk, which is specified in GB. """ - size_gb = proto.Field(proto.STRING, number=494929369, optional=True,) + size_gb = proto.Field(proto.INT64, number=494929369, optional=True,) class DisplayDevice(proto.Message): @@ -6776,7 +6776,7 @@ class ExternalVpnGateway(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. interfaces (Sequence[google.cloud.compute_v1.types.ExternalVpnGatewayInterface]): @@ -6830,7 +6830,7 @@ class RedundancyType(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) interfaces = proto.RepeatedField( proto.MESSAGE, number=12073562, message="ExternalVpnGatewayInterface", ) @@ -7026,7 +7026,7 @@ class Firewall(proto.Message): not enforced and the network behaves as if it did not exist. If this is unspecified, the firewall rule will be enabled. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -7156,7 +7156,7 @@ class Direction(proto.Enum): proto.ENUM, number=111150975, optional=True, enum=Direction, ) disabled = proto.Field(proto.BOOL, number=270940796, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) log_config = proto.Field( proto.MESSAGE, number=351299741, optional=True, message="FirewallLogConfig", @@ -7371,7 +7371,7 @@ class FirewallPolicy(proto.Message): fail with error 412 conditionNotMet. To see the latest fingerprint, make get() request to the firewall policy. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -7417,7 +7417,7 @@ class FirewallPolicy(proto.Message): description = proto.Field(proto.STRING, number=422937596, optional=True,) display_name = proto.Field(proto.STRING, number=4473832, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) parent = proto.Field(proto.STRING, number=78317738, optional=True,) @@ -7713,7 +7713,7 @@ class ForwardingRule(proto.Message): from another concurrent request. To see the latest fingerprint, make a get() request to retrieve a ForwardingRule. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. ip_version (google.cloud.compute_v1.types.ForwardingRule.IpVersion): @@ -7858,7 +7858,7 @@ class ForwardingRule(proto.Message): For more information, see `Port specifications `__. - psc_connection_id (str): + psc_connection_id (int): [Output Only] The PSC connection id of the PSC Forwarding Rule. region (str): @@ -7995,7 +7995,7 @@ class NetworkTier(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ip_version = proto.Field( proto.ENUM, number=294959552, optional=True, enum=IpVersion, ) @@ -8016,7 +8016,7 @@ class NetworkTier(proto.Enum): ) port_range = proto.Field(proto.STRING, number=217518079, optional=True,) ports = proto.RepeatedField(proto.STRING, number=106854418,) - psc_connection_id = proto.Field(proto.STRING, number=292082397, optional=True,) + psc_connection_id = proto.Field(proto.UINT64, number=292082397, optional=True,) region = proto.Field(proto.STRING, number=138946292, optional=True,) self_link = proto.Field(proto.STRING, number=456214797, optional=True,) service_directory_registrations = proto.RepeatedField( @@ -8990,7 +8990,7 @@ class HealthCheck(proto.Message): https_health_check (google.cloud.compute_v1.types.HTTPSHealthCheck): - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -9064,7 +9064,7 @@ class Type(proto.Enum): https_health_check = proto.Field( proto.MESSAGE, number=436046905, optional=True, message="HTTPSHealthCheck", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) log_config = proto.Field( proto.MESSAGE, number=351299741, optional=True, message="HealthCheckLogConfig", @@ -9181,7 +9181,7 @@ class HealthCheckService(proto.Message): then UNHEALTHY is the HealthState of the entire health check service. If all backend's are healthy, the HealthState of the health check service is HEALTHY. . - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -9242,7 +9242,7 @@ class HealthStatusAggregationPolicy(proto.Enum): health_status_aggregation_policy = proto.Field( proto.ENUM, number=253163129, optional=True, enum=HealthStatusAggregationPolicy, ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) network_endpoint_groups = proto.RepeatedField(proto.STRING, number=29346733,) @@ -9586,16 +9586,16 @@ class Int64RangeMatch(proto.Message): within the specified integer range. Attributes: - range_end (str): + range_end (int): The end of the range (exclusive) in signed long integer format. - range_start (str): + range_start (int): The start of the range (inclusive) in signed long integer format. """ - range_end = proto.Field(proto.STRING, number=322439897, optional=True,) - range_start = proto.Field(proto.STRING, number=103333600, optional=True,) + range_end = proto.Field(proto.INT64, number=322439897, optional=True,) + range_start = proto.Field(proto.INT64, number=103333600, optional=True,) class HttpHeaderMatch(proto.Message): @@ -10280,7 +10280,7 @@ class Image(proto.Message): {$api_version}.images ==) Attributes: - archive_size_bytes (str): + archive_size_bytes (int): Size of the image tar.gz archive stored in Google Cloud Storage (in bytes). creation_timestamp (str): @@ -10292,7 +10292,7 @@ class Image(proto.Message): An optional description of this resource. Provide this property when you create the resource. - disk_size_gb (str): + disk_size_gb (int): Size of the image when restored onto a persistent disk (in GB). family (str): @@ -10307,7 +10307,7 @@ class Image(proto.Message): operating system. Applicable only for bootable images. Read Enabling guest operating system features to see a list of available options. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. image_encryption_key (google.cloud.compute_v1.types.CustomerEncryptionKey): @@ -10342,7 +10342,7 @@ class Image(proto.Message): labels (Sequence[google.cloud.compute_v1.types.Image.LabelsEntry]): Labels to apply to this image. These can be later modified by the setLabels method. - license_codes (Sequence[str]): + license_codes (Sequence[int]): Integer license codes indicating which licenses are attached to this image. licenses (Sequence[str]): @@ -10454,25 +10454,25 @@ class Status(proto.Enum): PENDING = 35394935 READY = 77848963 - archive_size_bytes = proto.Field(proto.STRING, number=381093450, optional=True,) + archive_size_bytes = proto.Field(proto.INT64, number=381093450, optional=True,) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) deprecated = proto.Field( proto.MESSAGE, number=515138995, optional=True, message="DeprecationStatus", ) description = proto.Field(proto.STRING, number=422937596, optional=True,) - disk_size_gb = proto.Field(proto.STRING, number=316263735, optional=True,) + disk_size_gb = proto.Field(proto.INT64, number=316263735, optional=True,) family = proto.Field(proto.STRING, number=328751972, optional=True,) guest_os_features = proto.RepeatedField( proto.MESSAGE, number=79294545, message="GuestOsFeature", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) image_encryption_key = proto.Field( proto.MESSAGE, number=379512583, optional=True, message="CustomerEncryptionKey", ) kind = proto.Field(proto.STRING, number=3292052, optional=True,) label_fingerprint = proto.Field(proto.STRING, number=178124825, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) - license_codes = proto.RepeatedField(proto.STRING, number=45482664,) + license_codes = proto.RepeatedField(proto.INT64, number=45482664,) licenses = proto.RepeatedField(proto.STRING, number=337642578,) name = proto.Field(proto.STRING, number=3373707, optional=True,) raw_disk = proto.Field( @@ -10892,7 +10892,7 @@ class Instance(proto.Message): global DNS, and [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal when using zonal DNS. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -11072,7 +11072,7 @@ class Status(proto.Enum): proto.MESSAGE, number=463595119, message="AcceleratorConfig", ) hostname = proto.Field(proto.STRING, number=237067315, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) label_fingerprint = proto.Field(proto.STRING, number=178124825, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) @@ -11231,7 +11231,7 @@ class InstanceGroup(proto.Message): [Output Only] The fingerprint of the named ports. The system uses this fingerprint to detect conflicts when multiple users change the named ports concurrently. - id (str): + id (int): [Output Only] A unique identifier for this instance group, generated by the server. kind (str): @@ -11280,7 +11280,7 @@ class InstanceGroup(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) named_ports = proto.RepeatedField( @@ -11719,7 +11719,7 @@ class InstanceGroupManager(proto.Message): conditionNotMet. To see the latest fingerprint, make a get() request to retrieve an InstanceGroupManager. - id (str): + id (int): [Output Only] A unique identifier for this resource type. The server generates this identifier. instance_group (str): @@ -11805,7 +11805,7 @@ class InstanceGroupManager(proto.Message): proto.MESSAGE, number=534558541, optional=True, message="DistributionPolicy", ) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) instance_group = proto.Field(proto.STRING, number=81095253, optional=True,) instance_template = proto.Field(proto.STRING, number=309248228, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) @@ -12228,7 +12228,7 @@ class ManagedInstance(proto.Message): list for an instance without stopping that instance. - VERIFYING The managed instance group has created the instance and it is in the process of being verified. - id (str): + id (int): [Output only] The unique identifier for this resource. This field is empty when instance does not exist. instance (str): @@ -12310,7 +12310,7 @@ class InstanceStatus(proto.Enum): current_action = proto.Field( proto.ENUM, number=178475964, optional=True, enum=CurrentAction, ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) instance = proto.Field(proto.STRING, number=18257045, optional=True,) instance_health = proto.RepeatedField( proto.MESSAGE, number=382667078, message="ManagedInstanceInstanceHealth", @@ -12866,7 +12866,7 @@ class InstanceTemplate(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] A unique identifier for this instance template. The server defines this identifier. kind (str): @@ -12901,7 +12901,7 @@ class InstanceTemplate(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) properties = proto.Field( @@ -13144,7 +13144,7 @@ class InterconnectOutageNotification(proto.Message): description (str): A description about the purpose of the outage. - end_time (str): + end_time (int): Scheduled end time for the outage (milliseconds since Unix epoch). issue_type (google.cloud.compute_v1.types.InterconnectOutageNotification.IssueType): @@ -13167,7 +13167,7 @@ class InterconnectOutageNotification(proto.Message): - GOOGLE: this notification as generated by Google. Note that the value of NSRC_GOOGLE has been deprecated in favor of GOOGLE. - start_time (str): + start_time (int): Scheduled start time for the outage (milliseconds since Unix epoch). state (google.cloud.compute_v1.types.InterconnectOutageNotification.State): @@ -13232,13 +13232,13 @@ class State(proto.Enum): affected_circuits = proto.RepeatedField(proto.STRING, number=177717013,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - end_time = proto.Field(proto.STRING, number=114938801, optional=True,) + end_time = proto.Field(proto.INT64, number=114938801, optional=True,) issue_type = proto.Field( proto.ENUM, number=369639136, optional=True, enum=IssueType, ) name = proto.Field(proto.STRING, number=3373707, optional=True,) source = proto.Field(proto.ENUM, number=177235995, optional=True, enum=Source,) - start_time = proto.Field(proto.STRING, number=37467274, optional=True,) + start_time = proto.Field(proto.INT64, number=37467274, optional=True,) state = proto.Field(proto.ENUM, number=109757585, optional=True, enum=State,) @@ -13281,7 +13281,7 @@ class Interconnect(proto.Message): [Output Only] Google reference ID to be used when raising support tickets with Google or otherwise to debug backend connectivity issues. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. interconnect_attachments (Sequence[str]): @@ -13437,7 +13437,7 @@ class State(proto.Enum): ) google_ip_address = proto.Field(proto.STRING, number=443105954, optional=True,) google_reference_id = proto.Field(proto.STRING, number=534944469, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) interconnect_attachments = proto.RepeatedField(proto.STRING, number=425388415,) interconnect_type = proto.Field( proto.ENUM, number=515165259, optional=True, enum=InterconnectType, @@ -13593,7 +13593,7 @@ class InterconnectAttachment(proto.Message): [Output Only] Google reference ID, to be used when raising support tickets with Google or otherwise to debug backend connectivity issues. [Deprecated] This field is not used. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. interconnect (str): @@ -13654,7 +13654,7 @@ class InterconnectAttachment(proto.Message): identifier of an PARTNER attachment used to initiate provisioning with a selected partner. Of the form "XXXXX/region/domain". - partner_asn (str): + partner_asn (int): Optional BGP ASN for the router supplied by a Layer 3 Partner if they configured BGP on behalf of the customer. Output only for PARTNER type, input only for @@ -13873,7 +13873,7 @@ class Type(proto.Enum): proto.ENUM, number=97980291, optional=True, enum=Encryption, ) google_reference_id = proto.Field(proto.STRING, number=534944469, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) interconnect = proto.Field(proto.STRING, number=224601230, optional=True,) ipsec_internal_addresses = proto.RepeatedField(proto.STRING, number=407648565,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) @@ -13883,7 +13883,7 @@ class Type(proto.Enum): proto.ENUM, number=201070847, optional=True, enum=OperationalStatus, ) pairing_key = proto.Field(proto.STRING, number=439695464, optional=True,) - partner_asn = proto.Field(proto.STRING, number=438166149, optional=True,) + partner_asn = proto.Field(proto.INT64, number=438166149, optional=True,) partner_metadata = proto.Field( proto.MESSAGE, number=65908934, @@ -14239,7 +14239,7 @@ class InterconnectLocationRegionInfo(proto.Message): a specific Cloud Region. Attributes: - expected_rtt_ms (str): + expected_rtt_ms (int): Expected round-trip time in milliseconds, from this InterconnectLocation to a VM in this region. @@ -14258,7 +14258,7 @@ class LocationPresence(proto.Enum): LP_GLOBAL = 429584062 LP_LOCAL_REGION = 488598851 - expected_rtt_ms = proto.Field(proto.STRING, number=422543866, optional=True,) + expected_rtt_ms = proto.Field(proto.INT64, number=422543866, optional=True,) location_presence = proto.Field( proto.ENUM, number=101517893, optional=True, enum=LocationPresence, ) @@ -14305,7 +14305,7 @@ class InterconnectLocation(proto.Message): facility_provider_facility_id (str): [Output Only] A provider-assigned Identifier for this facility (e.g., Ashburn-DC1). - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -14380,7 +14380,7 @@ class Status(proto.Enum): facility_provider_facility_id = proto.Field( proto.STRING, number=87269125, optional=True, ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) peeringdb_facility_id = proto.Field(proto.STRING, number=536567094, optional=True,) @@ -14484,13 +14484,13 @@ class License(proto.Message): An optional textual description of the resource; provided by the client when the resource is created. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): [Output Only] Type of resource. Always compute#license for licenses. - license_code (str): + license_code (int): [Output Only] The unique code used to attach this license to images, snapshots, and disks. name (str): @@ -14510,9 +14510,9 @@ class License(proto.Message): charges_use_fee = proto.Field(proto.BOOL, number=372412622, optional=True,) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) - license_code = proto.Field(proto.STRING, number=1467179, optional=True,) + license_code = proto.Field(proto.UINT64, number=1467179, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) resource_requirements = proto.Field( proto.MESSAGE, @@ -14551,7 +14551,7 @@ class LicenseCode(proto.Message): [Output Only] Creation timestamp in RFC3339 text format. description (str): [Output Only] Description of this License Code. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -14584,7 +14584,7 @@ class State(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) license_alias = proto.RepeatedField( proto.MESSAGE, number=43550930, message="LicenseCodeLicenseAlias", @@ -14849,7 +14849,7 @@ class MachineType(proto.Message): guest_cpus (int): [Output Only] The number of virtual CPUs that are available to the instance. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. image_space_gb (int): @@ -14863,7 +14863,7 @@ class MachineType(proto.Message): compute#machineType for machine types. maximum_persistent_disks (int): [Output Only] Maximum persistent disks allowed. - maximum_persistent_disks_size_gb (str): + maximum_persistent_disks_size_gb (int): [Output Only] Maximum total persistent disks size (GB) allowed. memory_mb (int): @@ -14890,7 +14890,7 @@ class MachineType(proto.Message): ) description = proto.Field(proto.STRING, number=422937596, optional=True,) guest_cpus = proto.Field(proto.INT32, number=393356754, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) image_space_gb = proto.Field(proto.INT32, number=75331864, optional=True,) is_shared_cpu = proto.Field(proto.BOOL, number=521399555, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) @@ -14898,7 +14898,7 @@ class MachineType(proto.Message): proto.INT32, number=496220941, optional=True, ) maximum_persistent_disks_size_gb = proto.Field( - proto.STRING, number=154274471, optional=True, + proto.INT64, number=154274471, optional=True, ) memory_mb = proto.Field(proto.INT32, number=116001171, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -15290,7 +15290,7 @@ class Network(proto.Message): gateway_i_pv4 (str): [Output Only] The gateway address for default routing out of the network, selected by GCP. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -15329,7 +15329,7 @@ class Network(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) gateway_i_pv4 = proto.Field(proto.STRING, number=178678877, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) mtu = proto.Field(proto.INT32, number=108462, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -15487,7 +15487,7 @@ class NetworkEndpointGroup(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -15561,7 +15561,7 @@ class NetworkEndpointType(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) default_port = proto.Field(proto.INT32, number=423377855, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) network = proto.Field(proto.STRING, number=232872494, optional=True,) @@ -16013,7 +16013,7 @@ class NodeGroup(proto.Message): resource. fingerprint (str): - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -16085,7 +16085,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) location_hint = proto.Field(proto.STRING, number=350519505, optional=True,) maintenance_policy = proto.Field( @@ -16390,7 +16390,7 @@ class NodeTemplate(proto.Message): resource. disks (Sequence[google.cloud.compute_v1.types.LocalDisk]): - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -16468,7 +16468,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) disks = proto.RepeatedField(proto.MESSAGE, number=95594102, message="LocalDisk",) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) node_affinity_labels = proto.MapField(proto.STRING, proto.STRING, number=339007161,) @@ -16618,7 +16618,7 @@ class NodeType(proto.Message): guest_cpus (int): [Output Only] The number of virtual CPUs that are available to the node type. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -16646,7 +16646,7 @@ class NodeType(proto.Message): ) description = proto.Field(proto.STRING, number=422937596, optional=True,) guest_cpus = proto.Field(proto.INT32, number=393356754, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) local_ssd_gb = proto.Field(proto.INT32, number=329237578, optional=True,) memory_mb = proto.Field(proto.INT32, number=116001171, optional=True,) @@ -16817,7 +16817,7 @@ class NotificationEndpoint(proto.Message): Settings of the gRPC notification endpoint including the endpoint URL and the retry duration. - id (str): + id (int): [Output Only] A unique identifier for this resource type. The server generates this identifier. kind (str): @@ -16850,7 +16850,7 @@ class NotificationEndpoint(proto.Message): optional=True, message="NotificationEndpointGrpcSettings", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) region = proto.Field(proto.STRING, number=138946292, optional=True,) @@ -17011,7 +17011,7 @@ class Operation(proto.Message): [Output Only] If the operation fails, this field contains the HTTP error status code that was returned. For example, a ``404`` means the resource was not found. - id (str): + id (int): [Output Only] The unique identifier for the operation. This identifier is defined by the server. insert_time (str): @@ -17051,7 +17051,7 @@ class Operation(proto.Message): status_message (str): [Output Only] An optional textual description of the current status of the operation. - target_id (str): + target_id (int): [Output Only] The unique target ID, which identifies a specific incarnation of the target resource. target_link (str): @@ -17087,7 +17087,7 @@ class Status(proto.Enum): error = proto.Field(proto.MESSAGE, number=96784904, optional=True, message="Error",) http_error_message = proto.Field(proto.STRING, number=202521945, optional=True,) http_error_status_code = proto.Field(proto.INT32, number=312345196, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) insert_time = proto.Field(proto.STRING, number=433722515, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -17099,7 +17099,7 @@ class Status(proto.Enum): start_time = proto.Field(proto.STRING, number=37467274, optional=True,) status = proto.Field(proto.ENUM, number=181260274, optional=True, enum=Status,) status_message = proto.Field(proto.STRING, number=297428154, optional=True,) - target_id = proto.Field(proto.STRING, number=258165385, optional=True,) + target_id = proto.Field(proto.UINT64, number=258165385, optional=True,) target_link = proto.Field(proto.STRING, number=62671336, optional=True,) user = proto.Field(proto.STRING, number=3599307, optional=True,) warnings = proto.RepeatedField(proto.MESSAGE, number=498091095, message="Warnings",) @@ -17343,7 +17343,7 @@ class PacketMirroring(proto.Message): filter (google.cloud.compute_v1.types.PacketMirroringFilter): Filter for mirrored traffic. If unspecified, all traffic is mirrored. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -17406,7 +17406,7 @@ class Enable(proto.Enum): filter = proto.Field( proto.MESSAGE, number=336120696, optional=True, message="PacketMirroringFilter", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) mirrored_resources = proto.Field( proto.MESSAGE, @@ -18059,7 +18059,7 @@ class Project(proto.Message): enabled_features (Sequence[str]): Restricted features enabled for use on this project. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. This is not the project ID, and is just a unique ID used by Compute Engine to @@ -18116,7 +18116,7 @@ class XpnProjectStatus(proto.Enum): ) description = proto.Field(proto.STRING, number=422937596, optional=True,) enabled_features = proto.RepeatedField(proto.STRING, number=469017467,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) quotas = proto.RepeatedField(proto.MESSAGE, number=125341947, message="Quota",) @@ -18296,7 +18296,7 @@ class PublicAdvertisedPrefix(proto.Message): conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a PublicAdvertisedPrefix. - id (str): + id (int): [Output Only] The unique identifier for the resource type. The server generates this identifier. ip_cidr_range (str): @@ -18342,7 +18342,7 @@ class Status(proto.Enum): description = proto.Field(proto.STRING, number=422937596, optional=True,) dns_verification_ip = proto.Field(proto.STRING, number=241011381, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ip_cidr_range = proto.Field(proto.STRING, number=98117322, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -18463,7 +18463,7 @@ class PublicDelegatedPrefix(proto.Message): will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a PublicDelegatedPrefix. - id (str): + id (int): [Output Only] The unique identifier for the resource type. The server generates this identifier. ip_cidr_range (str): @@ -18511,7 +18511,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ip_cidr_range = proto.Field(proto.STRING, number=98117322, optional=True,) is_live_migration = proto.Field(proto.BOOL, number=511823856, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) @@ -18650,7 +18650,7 @@ class Region(proto.Message): region. description (str): [Output Only] Textual description of the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -18682,7 +18682,7 @@ class Status(proto.Enum): proto.MESSAGE, number=515138995, optional=True, message="DeprecationStatus", ) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) quotas = proto.RepeatedField(proto.MESSAGE, number=125341947, message="Quota",) @@ -18791,12 +18791,12 @@ class RegionDisksRemoveResourcePoliciesRequest(proto.Message): class RegionDisksResizeRequest(proto.Message): r""" Attributes: - size_gb (str): + size_gb (int): The new size of the regional persistent disk, which is specified in GB. """ - size_gb = proto.Field(proto.STRING, number=494929369, optional=True,) + size_gb = proto.Field(proto.INT64, number=494929369, optional=True,) class RegionInstanceGroupList(proto.Message): @@ -19409,7 +19409,7 @@ class UrlMap(proto.Message): validateForProxyless field set to true. host_rules (Sequence[google.cloud.compute_v1.types.HostRule]): The list of HostRules to use against the URL. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -19459,7 +19459,7 @@ class UrlMap(proto.Message): host_rules = proto.RepeatedField( proto.MESSAGE, number=311804832, message="HostRule", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) path_matchers = proto.RepeatedField( @@ -19584,12 +19584,12 @@ def raw_page(self): class ReservationsResizeRequest(proto.Message): r""" Attributes: - specific_sku_count (str): + specific_sku_count (int): Number of allocated resources can be resized with minimum = 1 and maximum = 1000. """ - specific_sku_count = proto.Field(proto.STRING, number=13890720, optional=True,) + specific_sku_count = proto.Field(proto.INT64, number=13890720, optional=True,) class ResourceGroupReference(proto.Message): @@ -19619,7 +19619,7 @@ class ResourcePolicy(proto.Message): group_placement_policy (google.cloud.compute_v1.types.ResourcePolicyGroupPlacementPolicy): Resource policy for instances for placement configuration. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. instance_schedule_policy (google.cloud.compute_v1.types.ResourcePolicyInstanceSchedulePolicy): @@ -19668,7 +19668,7 @@ class Status(proto.Enum): optional=True, message="ResourcePolicyGroupPlacementPolicy", ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) instance_schedule_policy = proto.Field( proto.MESSAGE, number=344877104, @@ -20160,7 +20160,7 @@ class Route(proto.Message): The destination range of outgoing packets that this route applies to. Both IPv4 and IPv6 are supported. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -20233,7 +20233,7 @@ class Route(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) dest_range = proto.Field(proto.STRING, number=381327712, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) network = proto.Field(proto.STRING, number=232872494, optional=True,) @@ -20696,7 +20696,7 @@ class Router(proto.Message): (IPsec-encrypted Cloud Interconnect feature). Not currently available in all Interconnect locations. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. interfaces (Sequence[google.cloud.compute_v1.types.RouterInterface]): @@ -20739,7 +20739,7 @@ class Router(proto.Message): encrypted_interconnect_router = proto.Field( proto.BOOL, number=297996575, optional=True, ) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) interfaces = proto.RepeatedField( proto.MESSAGE, number=12073562, message="RouterInterface", ) @@ -21232,7 +21232,7 @@ class SecurityPolicy(proto.Message): fail with error 412 conditionNotMet. To see the latest fingerprint, make get() request to the security policy. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -21260,7 +21260,7 @@ class SecurityPolicy(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) rules = proto.RepeatedField( @@ -21378,14 +21378,14 @@ class SerialPortOutput(proto.Message): kind (str): [Output Only] Type of the resource. Always compute#serialPortOutput for serial port output. - next_ (str): + next_ (int): [Output Only] The position of the next byte of content, regardless of whether the content exists, following the output returned in the ``contents`` property. Use this value in the next request as the start parameter. self_link (str): [Output Only] Server-defined URL for this resource. - start (str): + start (int): The starting byte position of the output that was returned. This should match the start parameter sent with the request. If the serial console output exceeds the size of the buffer @@ -21397,9 +21397,9 @@ class SerialPortOutput(proto.Message): contents = proto.Field(proto.STRING, number=506419994, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) - next_ = proto.Field(proto.STRING, number=3377907, optional=True,) + next_ = proto.Field(proto.INT64, number=3377907, optional=True,) self_link = proto.Field(proto.STRING, number=456214797, optional=True,) - start = proto.Field(proto.STRING, number=109757538, optional=True,) + start = proto.Field(proto.INT64, number=109757538, optional=True,) class ShieldedInstanceIdentityEntry(proto.Message): @@ -21498,12 +21498,12 @@ class Snapshot(proto.Message): An optional description of this resource. Provide this property when you create the resource. - disk_size_gb (str): + disk_size_gb (int): [Output Only] Size of the source disk, specified in GB. - download_bytes (str): + download_bytes (int): [Output Only] Number of bytes downloaded to restore a snapshot to a disk. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -21525,7 +21525,7 @@ class Snapshot(proto.Message): Labels to apply to this snapshot. These can be later modified by the setLabels method. Label values may be empty. - license_codes (Sequence[str]): + license_codes (Sequence[int]): [Output Only] Integer license codes indicating which licenses are attached to this snapshot. licenses (Sequence[str]): @@ -21580,7 +21580,7 @@ class Snapshot(proto.Message): status (google.cloud.compute_v1.types.Snapshot.Status): [Output Only] The status of the snapshot. This can be CREATING, DELETING, FAILED, READY, or UPLOADING. - storage_bytes (str): + storage_bytes (int): [Output Only] A size of the storage used by the snapshot. As snapshots share storage, this number is expected to change with snapshot creation/deletion. @@ -21621,13 +21621,13 @@ class StorageBytesStatus(proto.Enum): chain_name = proto.Field(proto.STRING, number=68644169, optional=True,) creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - disk_size_gb = proto.Field(proto.STRING, number=316263735, optional=True,) - download_bytes = proto.Field(proto.STRING, number=435054068, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + disk_size_gb = proto.Field(proto.INT64, number=316263735, optional=True,) + download_bytes = proto.Field(proto.INT64, number=435054068, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) label_fingerprint = proto.Field(proto.STRING, number=178124825, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) - license_codes = proto.RepeatedField(proto.STRING, number=45482664,) + license_codes = proto.RepeatedField(proto.INT64, number=45482664,) licenses = proto.RepeatedField(proto.STRING, number=337642578,) location_hint = proto.Field(proto.STRING, number=350519505, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -21642,7 +21642,7 @@ class StorageBytesStatus(proto.Enum): ) source_disk_id = proto.Field(proto.STRING, number=454190809, optional=True,) status = proto.Field(proto.ENUM, number=181260274, optional=True, enum=Status,) - storage_bytes = proto.Field(proto.STRING, number=424631719, optional=True,) + storage_bytes = proto.Field(proto.INT64, number=424631719, optional=True,) storage_bytes_status = proto.Field( proto.ENUM, number=490739082, optional=True, enum=StorageBytesStatus, ) @@ -21773,7 +21773,7 @@ class SslCertificate(proto.Message): resource. expire_time (str): [Output Only] Expire time of the certificate. RFC3339 - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -21829,7 +21829,7 @@ class Type(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) expire_time = proto.Field(proto.STRING, number=440691181, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) managed = proto.Field( proto.MESSAGE, @@ -21991,7 +21991,7 @@ class SslPolicy(proto.Message): fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve an SslPolicy. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -22052,7 +22052,7 @@ class Profile(proto.Enum): description = proto.Field(proto.STRING, number=422937596, optional=True,) enabled_features = proto.RepeatedField(proto.STRING, number=469017467,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) min_tls_version = proto.Field( proto.ENUM, number=8155943, optional=True, enum=MinTlsVersion, @@ -22300,7 +22300,7 @@ class Subnetwork(proto.Message): gateway_address (str): [Output Only] The gateway address for default routes to reach destination addresses outside this subnetwork. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. ip_cidr_range (str): @@ -22449,7 +22449,7 @@ class State(proto.Enum): enable_flow_logs = proto.Field(proto.BOOL, number=151544420, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) gateway_address = proto.Field(proto.STRING, number=459867385, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ip_cidr_range = proto.Field(proto.STRING, number=98117322, optional=True,) ipv6_cidr_range = proto.Field(proto.STRING, number=273141258, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) @@ -22627,7 +22627,7 @@ class TargetGrpcProxy(proto.Message): conditionNotMet. To see the latest fingerprint, make a get() request to retrieve the TargetGrpcProxy. - id (str): + id (int): [Output Only] The unique identifier for the resource type. The server generates this identifier. kind (str): @@ -22670,7 +22670,7 @@ class TargetGrpcProxy(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) self_link = proto.Field(proto.STRING, number=456214797, optional=True,) @@ -22758,7 +22758,7 @@ class TargetHttpProxy(proto.Message): conditionNotMet. To see the latest fingerprint, make a get() request to retrieve the TargetHttpProxy. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -22801,7 +22801,7 @@ class TargetHttpProxy(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) proxy_bind = proto.Field(proto.BOOL, number=286025582, optional=True,) @@ -22962,7 +22962,7 @@ class TargetHttpsProxy(proto.Message): conditionNotMet. To see the latest fingerprint, make a get() request to retrieve the TargetHttpsProxy. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -23059,7 +23059,7 @@ class QuicOverride(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) fingerprint = proto.Field(proto.STRING, number=234678500, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) proxy_bind = proto.Field(proto.BOOL, number=286025582, optional=True,) @@ -23231,7 +23231,7 @@ class TargetInstance(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. instance (str): @@ -23277,7 +23277,7 @@ class NatPolicy(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) instance = proto.Field(proto.STRING, number=18257045, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -23449,7 +23449,7 @@ class TargetPool(proto.Message): healthy if and only if the health checks pass. Only legacy HttpHealthChecks are supported. Only one health check may be specified. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. instances (Sequence[str]): @@ -23509,7 +23509,7 @@ class SessionAffinity(proto.Enum): description = proto.Field(proto.STRING, number=422937596, optional=True,) failover_ratio = proto.Field(proto.FLOAT, number=212667006, optional=True,) health_checks = proto.RepeatedField(proto.STRING, number=448370606,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) instances = proto.RepeatedField(proto.STRING, number=29097598,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) @@ -23772,7 +23772,7 @@ class TargetSslProxy(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -23818,7 +23818,7 @@ class ProxyHeader(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) proxy_header = proto.Field( @@ -23917,7 +23917,7 @@ class TargetTcpProxy(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -23966,7 +23966,7 @@ class ProxyHeader(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) proxy_bind = proto.Field(proto.BOOL, number=286025582, optional=True,) @@ -24035,7 +24035,7 @@ class TargetVpnGateway(proto.Message): resources. ForwardingRules are created using compute.forwardingRules.insert and associated with a VPN gateway. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -24083,7 +24083,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) forwarding_rules = proto.RepeatedField(proto.STRING, number=315821365,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) network = proto.Field(proto.STRING, number=232872494, optional=True,) @@ -24727,7 +24727,7 @@ class VpnGateway(proto.Message): An optional description of this resource. Provide this property when you create the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -24774,7 +24774,7 @@ class VpnGateway(proto.Message): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) label_fingerprint = proto.Field(proto.STRING, number=178124825, optional=True,) labels = proto.MapField(proto.STRING, proto.STRING, number=500195327,) @@ -25020,7 +25020,7 @@ class VpnTunnel(proto.Message): resource. detailed_status (str): [Output Only] Detailed status message for the VPN tunnel. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. ike_version (int): @@ -25190,7 +25190,7 @@ class Status(proto.Enum): creation_timestamp = proto.Field(proto.STRING, number=30525366, optional=True,) description = proto.Field(proto.STRING, number=422937596, optional=True,) detailed_status = proto.Field(proto.STRING, number=333501025, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) ike_version = proto.Field(proto.INT32, number=218376220, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) local_traffic_selector = proto.RepeatedField(proto.STRING, number=317314613,) @@ -25387,7 +25387,7 @@ class Zone(proto.Message): zone. description (str): [Output Only] Textual description of the resource. - id (str): + id (int): [Output Only] The unique identifier for the resource. This identifier is defined by the server. kind (str): @@ -25418,7 +25418,7 @@ class Status(proto.Enum): proto.MESSAGE, number=515138995, optional=True, message="DeprecationStatus", ) description = proto.Field(proto.STRING, number=422937596, optional=True,) - id = proto.Field(proto.STRING, number=3355, optional=True,) + id = proto.Field(proto.UINT64, number=3355, optional=True,) kind = proto.Field(proto.STRING, number=3292052, optional=True,) name = proto.Field(proto.STRING, number=3373707, optional=True,) region = proto.Field(proto.STRING, number=138946292, optional=True,) @@ -33046,7 +33046,7 @@ class GetSerialPortOutputInstanceRequest(proto.Message): retrieve data from. project (str): Project ID for this request. - start (str): + start (int): Specifies the starting byte position of the output to return. To start with the first byte of output to the specified port, omit this field or set it to ``0``. @@ -33071,7 +33071,7 @@ class GetSerialPortOutputInstanceRequest(proto.Message): instance = proto.Field(proto.STRING, number=18257045,) port = proto.Field(proto.INT32, number=3446913, optional=True,) project = proto.Field(proto.STRING, number=227560217,) - start = proto.Field(proto.STRING, number=109757538, optional=True,) + start = proto.Field(proto.INT64, number=109757538, optional=True,) zone = proto.Field(proto.STRING, number=3744684,) diff --git a/samples/snippets/quickstart.py b/samples/snippets/quickstart.py index fb67bfab0..341217e62 100644 --- a/samples/snippets/quickstart.py +++ b/samples/snippets/quickstart.py @@ -123,7 +123,7 @@ def create_instance( initialize_params.source_image = ( source_image # "projects/debian-cloud/global/images/family/debian-10" ) - initialize_params.disk_size_gb = "10" + initialize_params.disk_size_gb = 10 disk.initialize_params = initialize_params disk.auto_delete = True disk.boot = True diff --git a/samples/snippets/test_sample_start_stop.py b/samples/snippets/test_sample_start_stop.py index ea28bfa3f..ba01dd9ee 100644 --- a/samples/snippets/test_sample_start_stop.py +++ b/samples/snippets/test_sample_start_stop.py @@ -38,7 +38,7 @@ def _make_disk(raw_key: bytes = None): initialize_params.source_image = ( "projects/debian-cloud/global/images/family/debian-10" ) - initialize_params.disk_size_gb = "10" + initialize_params.disk_size_gb = 10 disk.initialize_params = initialize_params disk.auto_delete = True disk.boot = True diff --git a/synth.metadata b/synth.metadata index 06ab16328..df26c6680 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,14 +4,14 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-compute.git", - "sha": "40afb333a963717853f70410a7a08eda5492418c" + "sha": "fbc1a2869932883d0e7e8e498e16d2273fb25048" } }, { "git": { "name": "googleapis-discovery", "remote": "https://github.com/googleapis/googleapis-discovery.git", - "sha": "6b01eb5607e6ba0b3b931905bd779b28dc89b933" + "sha": "ac663f7f0afb13e3a8cfd04160d1677655c5c613" } } ], diff --git a/tests/unit/gapic/compute_v1/test_accelerator_types.py b/tests/unit/gapic/compute_v1/test_accelerator_types.py index ac74df7e8..c9ac506a0 100644 --- a/tests/unit/gapic/compute_v1/test_accelerator_types.py +++ b/tests/unit/gapic/compute_v1/test_accelerator_types.py @@ -118,6 +118,28 @@ def test_accelerator_types_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.AcceleratorTypesRestTransport, "rest"),], +) +def test_accelerator_types_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [AcceleratorTypesClient,]) def test_accelerator_types_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -490,7 +512,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -588,7 +611,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - id="id_value", + id=205, kind="kind_value", maximum_cards_per_instance=2756, name="name_value", @@ -609,7 +632,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.maximum_cards_per_instance == 2756 assert response.name == "name_value" @@ -649,9 +672,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "accelerator_type_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "accelerator_type_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -743,8 +767,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_addresses.py b/tests/unit/gapic/compute_v1/test_addresses.py index cefe5c688..1f067fa88 100644 --- a/tests/unit/gapic/compute_v1/test_addresses.py +++ b/tests/unit/gapic/compute_v1/test_addresses.py @@ -112,6 +112,27 @@ def test_addresses_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.AddressesRestTransport, "rest"),] +) +def test_addresses_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [AddressesClient,]) def test_addresses_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -462,7 +483,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -558,7 +580,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -570,7 +592,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -594,7 +616,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -606,7 +628,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -645,9 +667,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "address_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "address_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -681,7 +704,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetAddressReques address_type=compute.Address.AddressType.EXTERNAL, creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, ip_version=compute.Address.IpVersion.IPV4, kind="kind_value", name="name_value", @@ -710,7 +733,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetAddressReques assert response.address_type == compute.Address.AddressType.EXTERNAL assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_version == compute.Address.IpVersion.IPV4 assert response.kind == "kind_value" assert response.name == "name_value" @@ -755,9 +778,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "address_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "address_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -796,7 +820,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -808,7 +832,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -832,7 +856,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -844,7 +868,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -886,13 +910,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Address.to_json( address_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -978,8 +1003,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_autoscalers.py b/tests/unit/gapic/compute_v1/test_autoscalers.py index 736d95d15..ec7777b4f 100644 --- a/tests/unit/gapic/compute_v1/test_autoscalers.py +++ b/tests/unit/gapic/compute_v1/test_autoscalers.py @@ -114,6 +114,27 @@ def test_autoscalers_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.AutoscalersRestTransport, "rest"),] +) +def test_autoscalers_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [AutoscalersClient,]) def test_autoscalers_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -478,7 +499,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -577,7 +599,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -589,7 +611,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -613,7 +635,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -625,7 +647,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -664,9 +686,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "autoscaler_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "autoscaler_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -699,7 +722,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetAutoscalerReq autoscaling_policy=compute.AutoscalingPolicy(cool_down_period_sec=2112), creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", recommended_size=1693, @@ -731,7 +754,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetAutoscalerReq ) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.recommended_size == 1693 @@ -780,9 +803,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "autoscaler_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "autoscaler_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -821,7 +845,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -833,7 +857,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -857,7 +881,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -869,7 +893,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -913,13 +937,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1019,8 +1044,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1106,7 +1132,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1118,7 +1144,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1142,7 +1168,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1154,7 +1180,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1198,13 +1224,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1245,7 +1272,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1257,7 +1284,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1281,7 +1308,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1293,7 +1320,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1337,13 +1364,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_backend_buckets.py b/tests/unit/gapic/compute_v1/test_backend_buckets.py index 986f8da5b..520af50d5 100644 --- a/tests/unit/gapic/compute_v1/test_backend_buckets.py +++ b/tests/unit/gapic/compute_v1/test_backend_buckets.py @@ -117,6 +117,28 @@ def test_backend_buckets_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.BackendBucketsRestTransport, "rest"),], +) +def test_backend_buckets_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [BackendBucketsClient,]) def test_backend_buckets_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -416,7 +438,7 @@ def test_add_signed_url_key_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -428,7 +450,7 @@ def test_add_signed_url_key_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -452,7 +474,7 @@ def test_add_signed_url_key_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -464,7 +486,7 @@ def test_add_signed_url_key_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -506,13 +528,14 @@ def test_add_signed_url_key_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) assert compute.SignedUrlKey.to_json( signed_url_key_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_signed_url_key_rest_flattened_error(): @@ -551,7 +574,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -563,7 +586,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -587,7 +610,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -599,7 +622,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -638,8 +661,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -677,7 +701,7 @@ def test_delete_signed_url_key_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -689,7 +713,7 @@ def test_delete_signed_url_key_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -713,7 +737,7 @@ def test_delete_signed_url_key_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -725,7 +749,7 @@ def test_delete_signed_url_key_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -766,9 +790,10 @@ def test_delete_signed_url_key_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) - assert "key_name_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) + assert "key_name_value" in http_call[1] + str(body) + str(params) def test_delete_signed_url_key_rest_flattened_error(): @@ -812,7 +837,7 @@ def test_get_rest( custom_response_headers=["custom_response_headers_value"], description="description_value", enable_cdn=True, - id="id_value", + id=205, kind="kind_value", name="name_value", self_link="self_link_value", @@ -840,7 +865,7 @@ def test_get_rest( assert response.custom_response_headers == ["custom_response_headers_value"] assert response.description == "description_value" assert response.enable_cdn is True - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.self_link == "self_link_value" @@ -876,8 +901,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -915,7 +941,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -927,7 +953,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -951,7 +977,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -963,7 +989,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1003,12 +1029,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.BackendBucket.to_json( backend_bucket_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1095,7 +1122,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1179,7 +1207,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1191,7 +1219,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1215,7 +1243,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1227,7 +1255,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1269,13 +1297,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) assert compute.BackendBucket.to_json( backend_bucket_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1316,7 +1345,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1328,7 +1357,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1352,7 +1381,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1364,7 +1393,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1406,13 +1435,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_bucket_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_bucket_value" in http_call[1] + str(body) + str(params) assert compute.BackendBucket.to_json( backend_bucket_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_backend_services.py b/tests/unit/gapic/compute_v1/test_backend_services.py index 991770dd5..8e840ddc6 100644 --- a/tests/unit/gapic/compute_v1/test_backend_services.py +++ b/tests/unit/gapic/compute_v1/test_backend_services.py @@ -117,6 +117,28 @@ def test_backend_services_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.BackendServicesRestTransport, "rest"),], +) +def test_backend_services_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [BackendServicesClient,]) def test_backend_services_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -426,7 +448,7 @@ def test_add_signed_url_key_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -438,7 +460,7 @@ def test_add_signed_url_key_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -462,7 +484,7 @@ def test_add_signed_url_key_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -474,7 +496,7 @@ def test_add_signed_url_key_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -516,13 +538,14 @@ def test_add_signed_url_key_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.SignedUrlKey.to_json( signed_url_key_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_signed_url_key_rest_flattened_error(): @@ -620,7 +643,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -722,7 +746,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -734,7 +758,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -758,7 +782,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -770,7 +794,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -809,8 +833,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -849,7 +874,7 @@ def test_delete_signed_url_key_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -861,7 +886,7 @@ def test_delete_signed_url_key_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -885,7 +910,7 @@ def test_delete_signed_url_key_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -897,7 +922,7 @@ def test_delete_signed_url_key_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -938,9 +963,10 @@ def test_delete_signed_url_key_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) - assert "key_name_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) + assert "key_name_value" in http_call[1] + str(body) + str(params) def test_delete_signed_url_key_rest_flattened_error(): @@ -1001,7 +1027,7 @@ def test_get_rest( fingerprint="fingerprint_value", health_checks=["health_checks_value"], iap=compute.BackendServiceIAP(enabled=True), - id="id_value", + id=205, kind="kind_value", load_balancing_scheme=compute.BackendService.LoadBalancingScheme.EXTERNAL, locality_lb_policy=compute.BackendService.LocalityLbPolicy.INVALID_LB_POLICY, @@ -1066,7 +1092,7 @@ def test_get_rest( assert response.fingerprint == "fingerprint_value" assert response.health_checks == ["health_checks_value"] assert response.iap == compute.BackendServiceIAP(enabled=True) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert ( response.load_balancing_scheme @@ -1126,8 +1152,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1217,13 +1244,14 @@ def test_get_health_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.ResourceGroupReference.to_json( resource_group_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_get_health_rest_flattened_error(): @@ -1264,7 +1292,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1276,7 +1304,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1300,7 +1328,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1312,7 +1340,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1352,12 +1380,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1444,7 +1473,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1528,7 +1558,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1540,7 +1570,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1564,7 +1594,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1576,7 +1606,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1618,13 +1648,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1665,7 +1696,7 @@ def test_set_security_policy_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1677,7 +1708,7 @@ def test_set_security_policy_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1701,7 +1732,7 @@ def test_set_security_policy_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1713,7 +1744,7 @@ def test_set_security_policy_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1757,13 +1788,14 @@ def test_set_security_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.SecurityPolicyReference.to_json( security_policy_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_security_policy_rest_flattened_error(): @@ -1804,7 +1836,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1816,7 +1848,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1840,7 +1872,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1852,7 +1884,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1894,13 +1926,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_disk_types.py b/tests/unit/gapic/compute_v1/test_disk_types.py index 47bf9fdd7..f4277f95a 100644 --- a/tests/unit/gapic/compute_v1/test_disk_types.py +++ b/tests/unit/gapic/compute_v1/test_disk_types.py @@ -112,6 +112,27 @@ def test_disk_types_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.DiskTypesRestTransport, "rest"),] +) +def test_disk_types_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [DiskTypesClient,]) def test_disk_types_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -466,7 +487,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -554,10 +576,10 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetDiskTypeReque # Designate an appropriate value for the returned response. return_value = compute.DiskType( creation_timestamp="creation_timestamp_value", - default_disk_size_gb="default_disk_size_gb_value", + default_disk_size_gb=2097, deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", region="region_value", @@ -577,10 +599,10 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetDiskTypeReque # Establish that the response is the type that we expect. assert isinstance(response, compute.DiskType) assert response.creation_timestamp == "creation_timestamp_value" - assert response.default_disk_size_gb == "default_disk_size_gb_value" + assert response.default_disk_size_gb == 2097 assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.region == "region_value" @@ -619,9 +641,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_type_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_type_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -709,8 +732,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_disks.py b/tests/unit/gapic/compute_v1/test_disks.py index e55b37af8..bdd1b5b08 100644 --- a/tests/unit/gapic/compute_v1/test_disks.py +++ b/tests/unit/gapic/compute_v1/test_disks.py @@ -109,6 +109,25 @@ def test_disks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.DisksRestTransport, "rest"),] +) +def test_disks_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [DisksClient,]) def test_disks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -402,7 +421,7 @@ def test_add_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -414,7 +433,7 @@ def test_add_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -438,7 +457,7 @@ def test_add_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -450,7 +469,7 @@ def test_add_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -495,14 +514,15 @@ def test_add_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.DisksAddResourcePoliciesRequest.to_json( disks_add_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_resource_policies_rest_flattened_error(): @@ -601,7 +621,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -694,7 +715,7 @@ def test_create_snapshot_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -706,7 +727,7 @@ def test_create_snapshot_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -730,7 +751,7 @@ def test_create_snapshot_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -742,7 +763,7 @@ def test_create_snapshot_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -785,14 +806,15 @@ def test_create_snapshot_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.Snapshot.to_json( snapshot_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_create_snapshot_rest_flattened_error(): @@ -830,7 +852,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteDiskReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -842,7 +864,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteDiskReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -866,7 +888,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteDiskReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -878,7 +900,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteDiskReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -917,9 +939,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -959,25 +982,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetDiskRequest): type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ], - id="id_value", + id=205, kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, last_attach_timestamp="last_attach_timestamp_value", last_detach_timestamp="last_detach_timestamp_value", - license_codes=["license_codes_value"], + license_codes=[1360], licenses=["licenses_value"], location_hint="location_hint_value", name="name_value", options="options_value", - physical_block_size_bytes="physical_block_size_bytes_value", - provisioned_iops="provisioned_iops_value", + physical_block_size_bytes=2663, + provisioned_iops=1740, region="region_value", replica_zones=["replica_zones_value"], resource_policies=["resource_policies_value"], satisfies_pzs=True, self_link="self_link_value", - size_gb="size_gb_value", + size_gb=739, source_disk="source_disk_value", source_disk_id="source_disk_id_value", source_image="source_image_value", @@ -1017,25 +1040,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetDiskRequest): type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} assert response.last_attach_timestamp == "last_attach_timestamp_value" assert response.last_detach_timestamp == "last_detach_timestamp_value" - assert response.license_codes == ["license_codes_value"] + assert response.license_codes == [1360] assert response.licenses == ["licenses_value"] assert response.location_hint == "location_hint_value" assert response.name == "name_value" assert response.options == "options_value" - assert response.physical_block_size_bytes == "physical_block_size_bytes_value" - assert response.provisioned_iops == "provisioned_iops_value" + assert response.physical_block_size_bytes == 2663 + assert response.provisioned_iops == 1740 assert response.region == "region_value" assert response.replica_zones == ["replica_zones_value"] assert response.resource_policies == ["resource_policies_value"] assert response.satisfies_pzs is True assert response.self_link == "self_link_value" - assert response.size_gb == "size_gb_value" + assert response.size_gb == 739 assert response.source_disk == "source_disk_value" assert response.source_disk_id == "source_disk_id_value" assert response.source_image == "source_image_value" @@ -1085,9 +1108,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1189,9 +1213,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1228,7 +1253,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertDiskReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1240,7 +1265,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertDiskReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1264,7 +1289,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertDiskReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1276,7 +1301,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertDiskReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1316,13 +1341,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Disk.to_json( disk_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1410,8 +1436,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1487,7 +1514,7 @@ def test_remove_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1499,7 +1526,7 @@ def test_remove_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1523,7 +1550,7 @@ def test_remove_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1535,7 +1562,7 @@ def test_remove_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1580,14 +1607,15 @@ def test_remove_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.DisksRemoveResourcePoliciesRequest.to_json( disks_remove_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_resource_policies_rest_flattened_error(): @@ -1627,7 +1655,7 @@ def test_resize_rest(transport: str = "rest", request_type=compute.ResizeDiskReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1639,7 +1667,7 @@ def test_resize_rest(transport: str = "rest", request_type=compute.ResizeDiskReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1663,7 +1691,7 @@ def test_resize_rest(transport: str = "rest", request_type=compute.ResizeDiskReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1675,7 +1703,7 @@ def test_resize_rest(transport: str = "rest", request_type=compute.ResizeDiskReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1705,9 +1733,7 @@ def test_resize_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - disks_resize_request_resource = compute.DisksResizeRequest( - size_gb="size_gb_value" - ) + disks_resize_request_resource = compute.DisksResizeRequest(size_gb=739) client.resize( project="project_value", zone="zone_value", @@ -1720,14 +1746,15 @@ def test_resize_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.DisksResizeRequest.to_json( disks_resize_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_resize_rest_flattened_error(): @@ -1741,9 +1768,7 @@ def test_resize_rest_flattened_error(): project="project_value", zone="zone_value", disk="disk_value", - disks_resize_request_resource=compute.DisksResizeRequest( - size_gb="size_gb_value" - ), + disks_resize_request_resource=compute.DisksResizeRequest(size_gb=739), ) @@ -1838,14 +1863,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.ZoneSetPolicyRequest.to_json( zone_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1887,7 +1913,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1899,7 +1925,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1923,7 +1949,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1935,7 +1961,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1980,14 +2006,15 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.ZoneSetLabelsRequest.to_json( zone_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -2074,14 +2101,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py b/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py index e3fcde065..e34bb5d77 100644 --- a/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py +++ b/tests/unit/gapic/compute_v1/test_external_vpn_gateways.py @@ -120,6 +120,28 @@ def test_external_vpn_gateways_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.ExternalVpnGatewaysRestTransport, "rest"),], +) +def test_external_vpn_gateways_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ExternalVpnGatewaysClient,]) def test_external_vpn_gateways_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -429,7 +451,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -441,7 +463,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -465,7 +487,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -477,7 +499,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -518,8 +540,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "external_vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "external_vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -554,7 +577,7 @@ def test_get_rest( return_value = compute.ExternalVpnGateway( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, interfaces=[compute.ExternalVpnGatewayInterface(id=205)], kind="kind_value", label_fingerprint="label_fingerprint_value", @@ -576,7 +599,7 @@ def test_get_rest( assert isinstance(response, compute.ExternalVpnGateway) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.interfaces == [compute.ExternalVpnGatewayInterface(id=205)] assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" @@ -621,8 +644,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "external_vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "external_vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -662,7 +686,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -674,7 +698,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -698,7 +722,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -710,7 +734,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -755,12 +779,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ExternalVpnGateway.to_json( external_vpn_gateway_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -859,7 +884,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -947,7 +973,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -959,7 +985,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -983,7 +1009,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -995,7 +1021,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1041,13 +1067,14 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetLabelsRequest.to_json( global_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1137,13 +1164,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_firewall_policies.py b/tests/unit/gapic/compute_v1/test_firewall_policies.py index 9edef8eda..afe59eb65 100644 --- a/tests/unit/gapic/compute_v1/test_firewall_policies.py +++ b/tests/unit/gapic/compute_v1/test_firewall_policies.py @@ -118,6 +118,28 @@ def test_firewall_policies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.FirewallPoliciesRestTransport, "rest"),], +) +def test_firewall_policies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [FirewallPoliciesClient,]) def test_firewall_policies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_add_association_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_add_association_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_add_association_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_add_association_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -518,12 +540,13 @@ def test_add_association_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) assert compute.FirewallPolicyAssociation.to_json( firewall_policy_association_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_association_rest_flattened_error(): @@ -563,7 +586,7 @@ def test_add_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -575,7 +598,7 @@ def test_add_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -599,7 +622,7 @@ def test_add_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -611,7 +634,7 @@ def test_add_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -654,12 +677,13 @@ def test_add_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) assert compute.FirewallPolicyRule.to_json( firewall_policy_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_rule_rest_flattened_error(): @@ -699,7 +723,7 @@ def test_clone_rules_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -711,7 +735,7 @@ def test_clone_rules_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -735,7 +759,7 @@ def test_clone_rules_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -747,7 +771,7 @@ def test_clone_rules_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -784,7 +808,8 @@ def test_clone_rules_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_clone_rules_rest_flattened_error(): @@ -821,7 +846,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -833,7 +858,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -857,7 +882,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -869,7 +894,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -906,7 +931,8 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -945,7 +971,7 @@ def test_get_rest( description="description_value", display_name="display_name_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", parent="parent_value", @@ -973,7 +999,7 @@ def test_get_rest( assert response.description == "description_value" assert response.display_name == "display_name_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.parent == "parent_value" @@ -1012,7 +1038,8 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1093,7 +1120,8 @@ def test_get_association_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_get_association_rest_flattened_error(): @@ -1191,7 +1219,8 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1288,7 +1317,8 @@ def test_get_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_get_rule_rest_flattened_error(): @@ -1325,7 +1355,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1337,7 +1367,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1361,7 +1391,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1373,7 +1403,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1417,11 +1447,12 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") + params = http_params.get("params") assert compute.FirewallPolicy.to_json( firewall_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1525,6 +1556,7 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") + params = http_params.get("params") def test_list_rest_flattened_error(): @@ -1655,6 +1687,7 @@ def test_list_associations_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") + params = http_params.get("params") def test_list_associations_rest_flattened_error(): @@ -1688,7 +1721,7 @@ def test_move_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1700,7 +1733,7 @@ def test_move_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1724,7 +1757,7 @@ def test_move_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1736,7 +1769,7 @@ def test_move_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1773,7 +1806,8 @@ def test_move_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_move_rest_flattened_error(): @@ -1810,7 +1844,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1822,7 +1856,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1846,7 +1880,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1858,7 +1892,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1905,12 +1939,13 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) assert compute.FirewallPolicy.to_json( firewall_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1954,7 +1989,7 @@ def test_patch_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1966,7 +2001,7 @@ def test_patch_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1990,7 +2025,7 @@ def test_patch_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2002,7 +2037,7 @@ def test_patch_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2045,12 +2080,13 @@ def test_patch_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) assert compute.FirewallPolicyRule.to_json( firewall_policy_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rule_rest_flattened_error(): @@ -2090,7 +2126,7 @@ def test_remove_association_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2102,7 +2138,7 @@ def test_remove_association_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2126,7 +2162,7 @@ def test_remove_association_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2138,7 +2174,7 @@ def test_remove_association_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2175,7 +2211,8 @@ def test_remove_association_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_remove_association_rest_flattened_error(): @@ -2212,7 +2249,7 @@ def test_remove_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2224,7 +2261,7 @@ def test_remove_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2248,7 +2285,7 @@ def test_remove_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2260,7 +2297,7 @@ def test_remove_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2297,7 +2334,8 @@ def test_remove_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "firewall_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "firewall_policy_value" in http_call[1] + str(body) + str(params) def test_remove_rule_rest_flattened_error(): @@ -2401,12 +2439,13 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalOrganizationSetPolicyRequest.to_json( global_organization_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -2490,12 +2529,13 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_firewalls.py b/tests/unit/gapic/compute_v1/test_firewalls.py index de0fde737..6bfd4fd66 100644 --- a/tests/unit/gapic/compute_v1/test_firewalls.py +++ b/tests/unit/gapic/compute_v1/test_firewalls.py @@ -112,6 +112,27 @@ def test_firewalls_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.FirewallsRestTransport, "rest"),] +) +def test_firewalls_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [FirewallsClient,]) def test_firewalls_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -492,8 +513,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "firewall_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "firewall_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -529,7 +551,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetFirewallReque destination_ranges=["destination_ranges_value"], direction=compute.Firewall.Direction.EGRESS, disabled=True, - id="id_value", + id=205, kind="kind_value", log_config=compute.FirewallLogConfig(enable=True), name="name_value", @@ -560,7 +582,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetFirewallReque assert response.destination_ranges == ["destination_ranges_value"] assert response.direction == compute.Firewall.Direction.EGRESS assert response.disabled is True - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.log_config == compute.FirewallLogConfig(enable=True) assert response.name == "name_value" @@ -604,8 +626,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "firewall_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "firewall_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -643,7 +666,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -655,7 +678,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -679,7 +702,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -691,7 +714,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -733,12 +756,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Firewall.to_json( firewall_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -829,7 +853,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -903,7 +928,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchFirewallR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -915,7 +940,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchFirewallR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -939,7 +964,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchFirewallR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -951,7 +976,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchFirewallR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -995,13 +1020,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "firewall_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "firewall_value" in http_call[1] + str(body) + str(params) assert compute.Firewall.to_json( firewall_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1042,7 +1068,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1054,7 +1080,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1078,7 +1104,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1090,7 +1116,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1134,13 +1160,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "firewall_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "firewall_value" in http_call[1] + str(body) + str(params) assert compute.Firewall.to_json( firewall_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_forwarding_rules.py b/tests/unit/gapic/compute_v1/test_forwarding_rules.py index 2995c60a6..26e15180b 100644 --- a/tests/unit/gapic/compute_v1/test_forwarding_rules.py +++ b/tests/unit/gapic/compute_v1/test_forwarding_rules.py @@ -117,6 +117,28 @@ def test_forwarding_rules_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.ForwardingRulesRestTransport, "rest"),], +) +def test_forwarding_rules_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ForwardingRulesClient,]) def test_forwarding_rules_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -485,7 +507,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -587,7 +610,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -599,7 +622,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -623,7 +646,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -635,7 +658,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -676,9 +699,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -718,7 +742,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, ip_version=compute.ForwardingRule.IpVersion.IPV4, is_mirroring_collector=True, kind="kind_value", @@ -735,7 +759,7 @@ def test_get_rest( network_tier=compute.ForwardingRule.NetworkTier.PREMIUM, port_range="port_range_value", ports=["ports_value"], - psc_connection_id="psc_connection_id_value", + psc_connection_id=1793, region="region_value", self_link="self_link_value", service_directory_registrations=[ @@ -767,7 +791,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_version == compute.ForwardingRule.IpVersion.IPV4 assert response.is_mirroring_collector is True assert response.kind == "kind_value" @@ -787,7 +811,7 @@ def test_get_rest( assert response.network_tier == compute.ForwardingRule.NetworkTier.PREMIUM assert response.port_range == "port_range_value" assert response.ports == ["ports_value"] - assert response.psc_connection_id == "psc_connection_id_value" + assert response.psc_connection_id == 1793 assert response.region == "region_value" assert response.self_link == "self_link_value" assert response.service_directory_registrations == [ @@ -831,9 +855,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -872,7 +897,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -884,7 +909,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -908,7 +933,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -920,7 +945,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -964,13 +989,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.ForwardingRule.to_json( forwarding_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1060,8 +1086,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1147,7 +1174,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1159,7 +1186,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1183,7 +1210,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1195,7 +1222,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1240,14 +1267,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) assert compute.ForwardingRule.to_json( forwarding_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1289,7 +1317,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1301,7 +1329,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1325,7 +1353,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1337,7 +1365,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1382,14 +1410,15 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetLabelsRequest.to_json( region_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1431,7 +1460,7 @@ def test_set_target_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1443,7 +1472,7 @@ def test_set_target_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1467,7 +1496,7 @@ def test_set_target_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1479,7 +1508,7 @@ def test_set_target_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1522,14 +1551,15 @@ def test_set_target_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) assert compute.TargetReference.to_json( target_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_target_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_addresses.py b/tests/unit/gapic/compute_v1/test_global_addresses.py index fdbe7fd06..35f92ad4a 100644 --- a/tests/unit/gapic/compute_v1/test_global_addresses.py +++ b/tests/unit/gapic/compute_v1/test_global_addresses.py @@ -117,6 +117,28 @@ def test_global_addresses_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalAddressesRestTransport, "rest"),], +) +def test_global_addresses_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalAddressesClient,]) def test_global_addresses_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -426,7 +448,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -438,7 +460,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -462,7 +484,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -474,7 +496,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -513,8 +535,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "address_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "address_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -549,7 +572,7 @@ def test_get_rest( address_type=compute.Address.AddressType.EXTERNAL, creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, ip_version=compute.Address.IpVersion.IPV4, kind="kind_value", name="name_value", @@ -578,7 +601,7 @@ def test_get_rest( assert response.address_type == compute.Address.AddressType.EXTERNAL assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_version == compute.Address.IpVersion.IPV4 assert response.kind == "kind_value" assert response.name == "name_value" @@ -623,8 +646,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "address_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "address_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -662,7 +686,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -674,7 +698,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -698,7 +722,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -710,7 +734,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -750,12 +774,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Address.to_json( address_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -840,7 +865,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py b/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py index 333ea1017..87f819ca5 100644 --- a/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py +++ b/tests/unit/gapic/compute_v1/test_global_forwarding_rules.py @@ -120,6 +120,28 @@ def test_global_forwarding_rules_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalForwardingRulesRestTransport, "rest"),], +) +def test_global_forwarding_rules_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalForwardingRulesClient,]) def test_global_forwarding_rules_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -447,7 +469,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -459,7 +481,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -483,7 +505,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -495,7 +517,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -536,8 +558,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -578,7 +601,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, ip_version=compute.ForwardingRule.IpVersion.IPV4, is_mirroring_collector=True, kind="kind_value", @@ -595,7 +618,7 @@ def test_get_rest( network_tier=compute.ForwardingRule.NetworkTier.PREMIUM, port_range="port_range_value", ports=["ports_value"], - psc_connection_id="psc_connection_id_value", + psc_connection_id=1793, region="region_value", self_link="self_link_value", service_directory_registrations=[ @@ -627,7 +650,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_version == compute.ForwardingRule.IpVersion.IPV4 assert response.is_mirroring_collector is True assert response.kind == "kind_value" @@ -647,7 +670,7 @@ def test_get_rest( assert response.network_tier == compute.ForwardingRule.NetworkTier.PREMIUM assert response.port_range == "port_range_value" assert response.ports == ["ports_value"] - assert response.psc_connection_id == "psc_connection_id_value" + assert response.psc_connection_id == 1793 assert response.region == "region_value" assert response.self_link == "self_link_value" assert response.service_directory_registrations == [ @@ -691,8 +714,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -732,7 +756,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -744,7 +768,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -768,7 +792,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -780,7 +804,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -824,12 +848,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ForwardingRule.to_json( forwarding_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -920,7 +945,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1008,7 +1034,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1020,7 +1046,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1044,7 +1070,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1056,7 +1082,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1102,13 +1128,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) assert compute.ForwardingRule.to_json( forwarding_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1151,7 +1178,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1163,7 +1190,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1187,7 +1214,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1199,7 +1226,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1245,13 +1272,14 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetLabelsRequest.to_json( global_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1294,7 +1322,7 @@ def test_set_target_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1306,7 +1334,7 @@ def test_set_target_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1330,7 +1358,7 @@ def test_set_target_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1342,7 +1370,7 @@ def test_set_target_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1386,13 +1414,14 @@ def test_set_target_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "forwarding_rule_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "forwarding_rule_value" in http_call[1] + str(body) + str(params) assert compute.TargetReference.to_json( target_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_target_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py b/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py index 5694a714b..833f6fbac 100644 --- a/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py +++ b/tests/unit/gapic/compute_v1/test_global_network_endpoint_groups.py @@ -122,6 +122,28 @@ def test_global_network_endpoint_groups_client_from_service_account_info(client_ assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalNetworkEndpointGroupsRestTransport, "rest"),], +) +def test_global_network_endpoint_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalNetworkEndpointGroupsClient,]) def test_global_network_endpoint_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -454,7 +476,7 @@ def test_attach_network_endpoints_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -466,7 +488,7 @@ def test_attach_network_endpoints_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -490,7 +512,7 @@ def test_attach_network_endpoints_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -502,7 +524,7 @@ def test_attach_network_endpoints_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -550,13 +572,14 @@ def test_attach_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) assert compute.GlobalNetworkEndpointGroupsAttachEndpointsRequest.to_json( global_network_endpoint_groups_attach_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_attach_network_endpoints_rest_flattened_error(): @@ -602,7 +625,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -614,7 +637,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -638,7 +661,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -650,7 +673,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -692,8 +715,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -734,7 +758,7 @@ def test_detach_network_endpoints_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -746,7 +770,7 @@ def test_detach_network_endpoints_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -770,7 +794,7 @@ def test_detach_network_endpoints_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -782,7 +806,7 @@ def test_detach_network_endpoints_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -830,13 +854,14 @@ def test_detach_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) assert compute.GlobalNetworkEndpointGroupsDetachEndpointsRequest.to_json( global_network_endpoint_groups_detach_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_detach_network_endpoints_rest_flattened_error(): @@ -883,7 +908,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", default_port=1289, description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", network="network_value", @@ -918,7 +943,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.default_port == 1289 assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network == "network_value" @@ -966,8 +991,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1008,7 +1034,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1020,7 +1046,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1044,7 +1070,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1056,7 +1082,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1101,12 +1127,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroup.to_json( network_endpoint_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1201,7 +1228,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1364,8 +1392,9 @@ def test_list_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_list_network_endpoints_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_operations.py b/tests/unit/gapic/compute_v1/test_global_operations.py index c08bc4fac..6141295c6 100644 --- a/tests/unit/gapic/compute_v1/test_global_operations.py +++ b/tests/unit/gapic/compute_v1/test_global_operations.py @@ -118,6 +118,28 @@ def test_global_operations_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalOperationsRestTransport, "rest"),], +) +def test_global_operations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalOperationsClient,]) def test_global_operations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -490,7 +512,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -622,8 +645,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -661,7 +685,7 @@ def test_get_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -673,7 +697,7 @@ def test_get_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -697,7 +721,7 @@ def test_get_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -709,7 +733,7 @@ def test_get_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -748,8 +772,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -836,7 +861,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -912,7 +938,7 @@ def test_wait_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -924,7 +950,7 @@ def test_wait_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -948,7 +974,7 @@ def test_wait_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -960,7 +986,7 @@ def test_wait_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -999,8 +1025,9 @@ def test_wait_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_wait_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_organization_operations.py b/tests/unit/gapic/compute_v1/test_global_organization_operations.py index 4be3bd2e8..1cc609c3e 100644 --- a/tests/unit/gapic/compute_v1/test_global_organization_operations.py +++ b/tests/unit/gapic/compute_v1/test_global_organization_operations.py @@ -122,6 +122,28 @@ def test_global_organization_operations_client_from_service_account_info(client_ assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalOrganizationOperationsRestTransport, "rest"),], +) +def test_global_organization_operations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalOrganizationOperationsClient,]) def test_global_organization_operations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -494,7 +516,8 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "operation_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -533,7 +556,7 @@ def test_get_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -545,7 +568,7 @@ def test_get_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -569,7 +592,7 @@ def test_get_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -581,7 +604,7 @@ def test_get_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -620,7 +643,8 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "operation_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -711,6 +735,7 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") + params = http_params.get("params") def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py b/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py index 40f05db55..ea04a4812 100644 --- a/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py +++ b/tests/unit/gapic/compute_v1/test_global_public_delegated_prefixes.py @@ -126,6 +126,28 @@ def test_global_public_delegated_prefixes_client_from_service_account_info( assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.GlobalPublicDelegatedPrefixesRestTransport, "rest"),], +) +def test_global_public_delegated_prefixes_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [GlobalPublicDelegatedPrefixesClient,]) def test_global_public_delegated_prefixes_client_from_service_account_file( client_class, @@ -460,7 +482,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -472,7 +494,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -496,7 +518,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -508,7 +530,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -550,8 +572,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -587,7 +610,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, ip_cidr_range="ip_cidr_range_value", is_live_migration=True, kind="kind_value", @@ -616,7 +639,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_cidr_range == "ip_cidr_range_value" assert response.is_live_migration is True assert response.kind == "kind_value" @@ -665,8 +688,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -707,7 +731,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -719,7 +743,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -743,7 +767,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -755,7 +779,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -800,12 +824,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.PublicDelegatedPrefix.to_json( public_delegated_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -903,7 +928,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -995,7 +1021,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1007,7 +1033,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1031,7 +1057,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1043,7 +1069,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1089,13 +1115,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) assert compute.PublicDelegatedPrefix.to_json( public_delegated_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_health_checks.py b/tests/unit/gapic/compute_v1/test_health_checks.py index 717aa23e3..99c41f498 100644 --- a/tests/unit/gapic/compute_v1/test_health_checks.py +++ b/tests/unit/gapic/compute_v1/test_health_checks.py @@ -114,6 +114,27 @@ def test_health_checks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.HealthChecksRestTransport, "rest"),] +) +def test_health_checks_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [HealthChecksClient,]) def test_health_checks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -466,7 +487,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -567,7 +589,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -579,7 +601,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -603,7 +625,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -615,7 +637,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -654,8 +676,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -694,7 +717,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetHealthCheckRe http2_health_check=compute.HTTP2HealthCheck(host="host_value"), http_health_check=compute.HTTPHealthCheck(host="host_value"), https_health_check=compute.HTTPSHealthCheck(host="host_value"), - id="id_value", + id=205, kind="kind_value", log_config=compute.HealthCheckLogConfig(enable=True), name="name_value", @@ -727,7 +750,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetHealthCheckRe assert response.http2_health_check == compute.HTTP2HealthCheck(host="host_value") assert response.http_health_check == compute.HTTPHealthCheck(host="host_value") assert response.https_health_check == compute.HTTPSHealthCheck(host="host_value") - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.log_config == compute.HealthCheckLogConfig(enable=True) assert response.name == "name_value" @@ -770,8 +793,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -809,7 +833,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -821,7 +845,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -845,7 +869,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -857,7 +881,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -897,12 +921,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -987,7 +1012,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1071,7 +1097,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1083,7 +1109,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1107,7 +1133,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1119,7 +1145,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1161,13 +1187,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1206,7 +1233,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1218,7 +1245,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1242,7 +1269,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1254,7 +1281,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1296,13 +1323,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_images.py b/tests/unit/gapic/compute_v1/test_images.py index 2b1393a4d..11e00a377 100644 --- a/tests/unit/gapic/compute_v1/test_images.py +++ b/tests/unit/gapic/compute_v1/test_images.py @@ -109,6 +109,25 @@ def test_images_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.ImagesRestTransport, "rest"),] +) +def test_images_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ImagesClient,]) def test_images_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -400,7 +419,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteImageRe error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -412,7 +431,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteImageRe start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -436,7 +455,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteImageRe assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -448,7 +467,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteImageRe assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -487,8 +506,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "image_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "image_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -524,7 +544,7 @@ def test_deprecate_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -536,7 +556,7 @@ def test_deprecate_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -560,7 +580,7 @@ def test_deprecate_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -572,7 +592,7 @@ def test_deprecate_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -614,13 +634,14 @@ def test_deprecate_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "image_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "image_value" in http_call[1] + str(body) + str(params) assert compute.DeprecationStatus.to_json( deprecation_status_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_deprecate_rest_flattened_error(): @@ -652,25 +673,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetImageRequest) with mock.patch.object(Session, "request") as req: # Designate an appropriate value for the returned response. return_value = compute.Image( - archive_size_bytes="archive_size_bytes_value", + archive_size_bytes=1922, creation_timestamp="creation_timestamp_value", deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - disk_size_gb="disk_size_gb_value", + disk_size_gb=1261, family="family_value", guest_os_features=[ compute.GuestOsFeature( type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ], - id="id_value", + id=205, image_encryption_key=compute.CustomerEncryptionKey( kms_key_name="kms_key_name_value" ), kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, - license_codes=["license_codes_value"], + license_codes=[1360], licenses=["licenses_value"], name="name_value", raw_disk=compute.RawDisk(container_type=compute.RawDisk.ContainerType.TAR), @@ -709,25 +730,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetImageRequest) # Establish that the response is the type that we expect. assert isinstance(response, compute.Image) - assert response.archive_size_bytes == "archive_size_bytes_value" + assert response.archive_size_bytes == 1922 assert response.creation_timestamp == "creation_timestamp_value" assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.disk_size_gb == "disk_size_gb_value" + assert response.disk_size_gb == 1261 assert response.family == "family_value" assert response.guest_os_features == [ compute.GuestOsFeature( type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ] - assert response.id == "id_value" + assert response.id == 205 assert response.image_encryption_key == compute.CustomerEncryptionKey( kms_key_name="kms_key_name_value" ) assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} - assert response.license_codes == ["license_codes_value"] + assert response.license_codes == [1360] assert response.licenses == ["licenses_value"] assert response.name == "name_value" assert response.raw_disk == compute.RawDisk( @@ -788,8 +809,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "image_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "image_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -818,25 +840,25 @@ def test_get_from_family_rest( with mock.patch.object(Session, "request") as req: # Designate an appropriate value for the returned response. return_value = compute.Image( - archive_size_bytes="archive_size_bytes_value", + archive_size_bytes=1922, creation_timestamp="creation_timestamp_value", deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - disk_size_gb="disk_size_gb_value", + disk_size_gb=1261, family="family_value", guest_os_features=[ compute.GuestOsFeature( type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ], - id="id_value", + id=205, image_encryption_key=compute.CustomerEncryptionKey( kms_key_name="kms_key_name_value" ), kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, - license_codes=["license_codes_value"], + license_codes=[1360], licenses=["licenses_value"], name="name_value", raw_disk=compute.RawDisk(container_type=compute.RawDisk.ContainerType.TAR), @@ -875,25 +897,25 @@ def test_get_from_family_rest( # Establish that the response is the type that we expect. assert isinstance(response, compute.Image) - assert response.archive_size_bytes == "archive_size_bytes_value" + assert response.archive_size_bytes == 1922 assert response.creation_timestamp == "creation_timestamp_value" assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.disk_size_gb == "disk_size_gb_value" + assert response.disk_size_gb == 1261 assert response.family == "family_value" assert response.guest_os_features == [ compute.GuestOsFeature( type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ] - assert response.id == "id_value" + assert response.id == 205 assert response.image_encryption_key == compute.CustomerEncryptionKey( kms_key_name="kms_key_name_value" ) assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} - assert response.license_codes == ["license_codes_value"] + assert response.license_codes == [1360] assert response.licenses == ["licenses_value"] assert response.name == "name_value" assert response.raw_disk == compute.RawDisk( @@ -954,8 +976,9 @@ def test_get_from_family_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "family_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "family_value" in http_call[1] + str(body) + str(params) def test_get_from_family_rest_flattened_error(): @@ -1056,8 +1079,9 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1093,7 +1117,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertImageRe error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1105,7 +1129,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertImageRe start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1129,7 +1153,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertImageRe assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1141,7 +1165,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertImageRe assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1171,7 +1195,7 @@ def test_insert_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - image_resource = compute.Image(archive_size_bytes="archive_size_bytes_value") + image_resource = compute.Image(archive_size_bytes=1922) client.insert( project="project_value", image_resource=image_resource, ) @@ -1181,12 +1205,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Image.to_json( image_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1198,7 +1223,7 @@ def test_insert_rest_flattened_error(): client.insert( compute.InsertImageRequest(), project="project_value", - image_resource=compute.Image(archive_size_bytes="archive_size_bytes_value"), + image_resource=compute.Image(archive_size_bytes=1922), ) @@ -1216,7 +1241,7 @@ def test_list_rest(transport: str = "rest", request_type=compute.ListImagesReque # Designate an appropriate value for the returned response. return_value = compute.ImageList( id="id_value", - items=[compute.Image(archive_size_bytes="archive_size_bytes_value")], + items=[compute.Image(archive_size_bytes=1922)], kind="kind_value", next_page_token="next_page_token_value", self_link="self_link_value", @@ -1234,9 +1259,7 @@ def test_list_rest(transport: str = "rest", request_type=compute.ListImagesReque # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListPager) assert response.id == "id_value" - assert response.items == [ - compute.Image(archive_size_bytes="archive_size_bytes_value") - ] + assert response.items == [compute.Image(archive_size_bytes=1922)] assert response.kind == "kind_value" assert response.next_page_token == "next_page_token_value" assert response.self_link == "self_link_value" @@ -1271,7 +1294,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1345,7 +1369,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchImageRequ error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1357,7 +1381,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchImageRequ start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1381,7 +1405,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchImageRequ assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1393,7 +1417,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchImageRequ assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1423,7 +1447,7 @@ def test_patch_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - image_resource = compute.Image(archive_size_bytes="archive_size_bytes_value") + image_resource = compute.Image(archive_size_bytes=1922) client.patch( project="project_value", image="image_value", image_resource=image_resource, ) @@ -1433,13 +1457,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "image_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "image_value" in http_call[1] + str(body) + str(params) assert compute.Image.to_json( image_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1452,7 +1477,7 @@ def test_patch_rest_flattened_error(): compute.PatchImageRequest(), project="project_value", image="image_value", - image_resource=compute.Image(archive_size_bytes="archive_size_bytes_value"), + image_resource=compute.Image(archive_size_bytes=1922), ) @@ -1546,13 +1571,14 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetPolicyRequest.to_json( global_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1593,7 +1619,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1605,7 +1631,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1629,7 +1655,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1641,7 +1667,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1685,13 +1711,14 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetLabelsRequest.to_json( global_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1776,13 +1803,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_instance_group_managers.py b/tests/unit/gapic/compute_v1/test_instance_group_managers.py index 03427414b..d9660c0e9 100644 --- a/tests/unit/gapic/compute_v1/test_instance_group_managers.py +++ b/tests/unit/gapic/compute_v1/test_instance_group_managers.py @@ -120,6 +120,28 @@ def test_instance_group_managers_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.InstanceGroupManagersRestTransport, "rest"),], +) +def test_instance_group_managers_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InstanceGroupManagersClient,]) def test_instance_group_managers_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -448,7 +470,7 @@ def test_abandon_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -460,7 +482,7 @@ def test_abandon_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -484,7 +506,7 @@ def test_abandon_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -496,7 +518,7 @@ def test_abandon_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -543,14 +565,15 @@ def test_abandon_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersAbandonInstancesRequest.to_json( instance_group_managers_abandon_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_abandon_instances_rest_flattened_error(): @@ -674,7 +697,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -784,7 +808,7 @@ def test_apply_updates_to_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -796,7 +820,7 @@ def test_apply_updates_to_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -820,7 +844,7 @@ def test_apply_updates_to_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -832,7 +856,7 @@ def test_apply_updates_to_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -879,14 +903,15 @@ def test_apply_updates_to_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersApplyUpdatesRequest.to_json( instance_group_managers_apply_updates_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_apply_updates_to_instances_rest_flattened_error(): @@ -931,7 +956,7 @@ def test_create_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -943,7 +968,7 @@ def test_create_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -967,7 +992,7 @@ def test_create_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -979,7 +1004,7 @@ def test_create_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1026,14 +1051,15 @@ def test_create_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersCreateInstancesRequest.to_json( instance_group_managers_create_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_create_instances_rest_flattened_error(): @@ -1077,7 +1103,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1089,7 +1115,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1113,7 +1139,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1125,7 +1151,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1168,9 +1194,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -1212,7 +1239,7 @@ def test_delete_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1224,7 +1251,7 @@ def test_delete_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1248,7 +1275,7 @@ def test_delete_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1260,7 +1287,7 @@ def test_delete_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1307,14 +1334,15 @@ def test_delete_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersDeleteInstancesRequest.to_json( instance_group_managers_delete_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_delete_instances_rest_flattened_error(): @@ -1359,7 +1387,7 @@ def test_delete_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1371,7 +1399,7 @@ def test_delete_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1395,7 +1423,7 @@ def test_delete_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1407,7 +1435,7 @@ def test_delete_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1454,14 +1482,15 @@ def test_delete_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersDeletePerInstanceConfigsReq.to_json( instance_group_managers_delete_per_instance_configs_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_delete_per_instance_configs_rest_flattened_error(): @@ -1511,7 +1540,7 @@ def test_get_rest( target_shape=compute.DistributionPolicy.TargetShape.ANY ), fingerprint="fingerprint_value", - id="id_value", + id=205, instance_group="instance_group_value", instance_template="instance_template_value", kind="kind_value", @@ -1565,7 +1594,7 @@ def test_get_rest( target_shape=compute.DistributionPolicy.TargetShape.ANY ) assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.instance_group == "instance_group_value" assert response.instance_template == "instance_template_value" assert response.kind == "kind_value" @@ -1630,9 +1659,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1673,7 +1703,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1685,7 +1715,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1709,7 +1739,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1721,7 +1751,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1771,13 +1801,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManager.to_json( instance_group_manager_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1891,8 +1922,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -2043,9 +2075,10 @@ def test_list_errors_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_errors_rest_flattened_error(): @@ -2201,9 +2234,10 @@ def test_list_managed_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_managed_instances_rest_flattened_error(): @@ -2356,9 +2390,10 @@ def test_list_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_per_instance_configs_rest_flattened_error(): @@ -2454,7 +2489,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2466,7 +2501,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2490,7 +2525,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2502,7 +2537,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2553,14 +2588,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManager.to_json( instance_group_manager_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -2609,7 +2645,7 @@ def test_patch_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2621,7 +2657,7 @@ def test_patch_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2645,7 +2681,7 @@ def test_patch_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2657,7 +2693,7 @@ def test_patch_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2706,14 +2742,15 @@ def test_patch_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersPatchPerInstanceConfigsReq.to_json( instance_group_managers_patch_per_instance_configs_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_per_instance_configs_rest_flattened_error(): @@ -2760,7 +2797,7 @@ def test_recreate_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2772,7 +2809,7 @@ def test_recreate_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2796,7 +2833,7 @@ def test_recreate_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2808,7 +2845,7 @@ def test_recreate_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2855,14 +2892,15 @@ def test_recreate_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersRecreateInstancesRequest.to_json( instance_group_managers_recreate_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_recreate_instances_rest_flattened_error(): @@ -2906,7 +2944,7 @@ def test_resize_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2918,7 +2956,7 @@ def test_resize_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2942,7 +2980,7 @@ def test_resize_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2954,7 +2992,7 @@ def test_resize_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2998,10 +3036,11 @@ def test_resize_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) - assert str(443) in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) + assert str(443) in http_call[1] + str(body) + str(params) def test_resize_rest_flattened_error(): @@ -3044,7 +3083,7 @@ def test_set_instance_template_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3056,7 +3095,7 @@ def test_set_instance_template_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3080,7 +3119,7 @@ def test_set_instance_template_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3092,7 +3131,7 @@ def test_set_instance_template_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3139,14 +3178,15 @@ def test_set_instance_template_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersSetInstanceTemplateRequest.to_json( instance_group_managers_set_instance_template_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_instance_template_rest_flattened_error(): @@ -3191,7 +3231,7 @@ def test_set_target_pools_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3203,7 +3243,7 @@ def test_set_target_pools_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3227,7 +3267,7 @@ def test_set_target_pools_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3239,7 +3279,7 @@ def test_set_target_pools_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3286,14 +3326,15 @@ def test_set_target_pools_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersSetTargetPoolsRequest.to_json( instance_group_managers_set_target_pools_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_target_pools_rest_flattened_error(): @@ -3338,7 +3379,7 @@ def test_update_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3350,7 +3391,7 @@ def test_update_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3374,7 +3415,7 @@ def test_update_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3386,7 +3427,7 @@ def test_update_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3435,14 +3476,15 @@ def test_update_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManagersUpdatePerInstanceConfigsReq.to_json( instance_group_managers_update_per_instance_configs_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_per_instance_configs_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_instance_groups.py b/tests/unit/gapic/compute_v1/test_instance_groups.py index ea9d87d46..4f645f482 100644 --- a/tests/unit/gapic/compute_v1/test_instance_groups.py +++ b/tests/unit/gapic/compute_v1/test_instance_groups.py @@ -117,6 +117,28 @@ def test_instance_groups_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.InstanceGroupsRestTransport, "rest"),], +) +def test_instance_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InstanceGroupsClient,]) def test_instance_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -416,7 +438,7 @@ def test_add_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -428,7 +450,7 @@ def test_add_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -452,7 +474,7 @@ def test_add_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -464,7 +486,7 @@ def test_add_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -509,14 +531,15 @@ def test_add_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupsAddInstancesRequest.to_json( instance_groups_add_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_instances_rest_flattened_error(): @@ -621,7 +644,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -722,7 +746,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -734,7 +758,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -758,7 +782,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -770,7 +794,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -811,9 +835,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -848,7 +873,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", named_ports=[compute.NamedPort(name="name_value")], @@ -873,7 +898,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.named_ports == [compute.NamedPort(name="name_value")] @@ -917,9 +942,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -958,7 +984,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -970,7 +996,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -994,7 +1020,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1006,7 +1032,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1050,13 +1076,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroup.to_json( instance_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1150,8 +1177,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1292,14 +1320,15 @@ def test_list_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupsListInstancesRequest.to_json( instance_groups_list_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_list_instances_rest_flattened_error(): @@ -1394,7 +1423,7 @@ def test_remove_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1406,7 +1435,7 @@ def test_remove_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1430,7 +1459,7 @@ def test_remove_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1442,7 +1471,7 @@ def test_remove_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1487,14 +1516,15 @@ def test_remove_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupsRemoveInstancesRequest.to_json( instance_groups_remove_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_instances_rest_flattened_error(): @@ -1536,7 +1566,7 @@ def test_set_named_ports_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1548,7 +1578,7 @@ def test_set_named_ports_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1572,7 +1602,7 @@ def test_set_named_ports_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1584,7 +1614,7 @@ def test_set_named_ports_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1629,14 +1659,15 @@ def test_set_named_ports_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupsSetNamedPortsRequest.to_json( instance_groups_set_named_ports_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_named_ports_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_instance_templates.py b/tests/unit/gapic/compute_v1/test_instance_templates.py index f751a07d4..aa93172ef 100644 --- a/tests/unit/gapic/compute_v1/test_instance_templates.py +++ b/tests/unit/gapic/compute_v1/test_instance_templates.py @@ -118,6 +118,28 @@ def test_instance_templates_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.InstanceTemplatesRestTransport, "rest"),], +) +def test_instance_templates_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InstanceTemplatesClient,]) def test_instance_templates_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -514,8 +536,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "instance_template_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "instance_template_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -548,7 +571,7 @@ def test_get_rest( return_value = compute.InstanceTemplate( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", properties=compute.InstanceProperties( @@ -575,7 +598,7 @@ def test_get_rest( assert isinstance(response, compute.InstanceTemplate) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.properties == compute.InstanceProperties( @@ -620,8 +643,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "instance_template_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "instance_template_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -722,8 +746,9 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -761,7 +786,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -773,7 +798,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -797,7 +822,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -809,7 +834,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -852,12 +877,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.InstanceTemplate.to_json( instance_template_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -948,7 +974,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1100,13 +1127,14 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetPolicyRequest.to_json( global_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1192,13 +1220,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_instances.py b/tests/unit/gapic/compute_v1/test_instances.py index 8800d3fe0..a4930d907 100644 --- a/tests/unit/gapic/compute_v1/test_instances.py +++ b/tests/unit/gapic/compute_v1/test_instances.py @@ -112,6 +112,27 @@ def test_instances_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.InstancesRestTransport, "rest"),] +) +def test_instances_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InstancesClient,]) def test_instances_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_add_access_config_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_add_access_config_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_add_access_config_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_add_access_config_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -497,15 +518,16 @@ def test_add_access_config_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "network_interface_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "network_interface_value" in http_call[1] + str(body) + str(params) assert compute.AccessConfig.to_json( access_config_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_access_config_rest_flattened_error(): @@ -546,7 +568,7 @@ def test_add_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -558,7 +580,7 @@ def test_add_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -582,7 +604,7 @@ def test_add_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -594,7 +616,7 @@ def test_add_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -639,14 +661,15 @@ def test_add_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesAddResourcePoliciesRequest.to_json( instances_add_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_resource_policies_rest_flattened_error(): @@ -757,7 +780,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -853,7 +877,7 @@ def test_attach_disk_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -865,7 +889,7 @@ def test_attach_disk_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -889,7 +913,7 @@ def test_attach_disk_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -901,7 +925,7 @@ def test_attach_disk_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -944,14 +968,15 @@ def test_attach_disk_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.AttachedDisk.to_json( attached_disk_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_attach_disk_rest_flattened_error(): @@ -991,7 +1016,7 @@ def test_bulk_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1003,7 +1028,7 @@ def test_bulk_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1027,7 +1052,7 @@ def test_bulk_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1039,7 +1064,7 @@ def test_bulk_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1070,7 +1095,7 @@ def test_bulk_insert_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. bulk_insert_instance_resource_resource = compute.BulkInsertInstanceResource( - count="count_value" + count=553 ) client.bulk_insert( project="project_value", @@ -1083,13 +1108,14 @@ def test_bulk_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.BulkInsertInstanceResource.to_json( bulk_insert_instance_resource_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_bulk_insert_rest_flattened_error(): @@ -1103,7 +1129,7 @@ def test_bulk_insert_rest_flattened_error(): project="project_value", zone="zone_value", bulk_insert_instance_resource_resource=compute.BulkInsertInstanceResource( - count="count_value" + count=553 ), ) @@ -1130,7 +1156,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1142,7 +1168,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1166,7 +1192,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1178,7 +1204,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1217,9 +1243,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -1258,7 +1285,7 @@ def test_delete_access_config_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1270,7 +1297,7 @@ def test_delete_access_config_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1294,7 +1321,7 @@ def test_delete_access_config_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1306,7 +1333,7 @@ def test_delete_access_config_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1349,11 +1376,12 @@ def test_delete_access_config_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "access_config_value" in http_call[1] + str(body) - assert "network_interface_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "access_config_value" in http_call[1] + str(body) + str(params) + assert "network_interface_value" in http_call[1] + str(body) + str(params) def test_delete_access_config_rest_flattened_error(): @@ -1394,7 +1422,7 @@ def test_detach_disk_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1406,7 +1434,7 @@ def test_detach_disk_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1430,7 +1458,7 @@ def test_detach_disk_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1442,7 +1470,7 @@ def test_detach_disk_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1484,10 +1512,11 @@ def test_detach_disk_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "device_name_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "device_name_value" in http_call[1] + str(body) + str(params) def test_detach_disk_rest_flattened_error(): @@ -1534,7 +1563,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetInstanceReque fingerprint="fingerprint_value", guest_accelerators=[compute.AcceleratorConfig(accelerator_count=1805)], hostname="hostname_value", - id="id_value", + id=205, kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, @@ -1600,7 +1629,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetInstanceReque compute.AcceleratorConfig(accelerator_count=1805) ] assert response.hostname == "hostname_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} @@ -1672,9 +1701,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1775,10 +1805,11 @@ def test_get_effective_firewalls_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "network_interface_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "network_interface_value" in http_call[1] + str(body) + str(params) def test_get_effective_firewalls_rest_flattened_error(): @@ -1871,9 +1902,10 @@ def test_get_guest_attributes_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_get_guest_attributes_rest_flattened_error(): @@ -1975,9 +2007,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -2054,9 +2087,10 @@ def test_get_screenshot_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_get_screenshot_rest_flattened_error(): @@ -2090,9 +2124,9 @@ def test_get_serial_port_output_rest( return_value = compute.SerialPortOutput( contents="contents_value", kind="kind_value", - next_="next__value", + next_=542, self_link="self_link_value", - start="start_value", + start=558, ) # Wrap the value into a proper Response obj @@ -2107,9 +2141,9 @@ def test_get_serial_port_output_rest( assert isinstance(response, compute.SerialPortOutput) assert response.contents == "contents_value" assert response.kind == "kind_value" - assert response.next_ == "next__value" + assert response.next_ == 542 assert response.self_link == "self_link_value" - assert response.start == "start_value" + assert response.start == 558 def test_get_serial_port_output_rest_from_dict(): @@ -2142,9 +2176,10 @@ def test_get_serial_port_output_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_get_serial_port_output_rest_flattened_error(): @@ -2233,9 +2268,10 @@ def test_get_shielded_instance_identity_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_get_shielded_instance_identity_rest_flattened_error(): @@ -2274,7 +2310,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2286,7 +2322,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2310,7 +2346,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2322,7 +2358,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2368,13 +2404,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Instance.to_json( instance_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -2476,8 +2513,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -2602,9 +2640,10 @@ def test_list_referrers_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_list_referrers_rest_flattened_error(): @@ -2687,7 +2726,7 @@ def test_remove_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2699,7 +2738,7 @@ def test_remove_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2723,7 +2762,7 @@ def test_remove_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2735,7 +2774,7 @@ def test_remove_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2780,14 +2819,15 @@ def test_remove_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesRemoveResourcePoliciesRequest.to_json( instances_remove_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_resource_policies_rest_flattened_error(): @@ -2827,7 +2867,7 @@ def test_reset_rest(transport: str = "rest", request_type=compute.ResetInstanceR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2839,7 +2879,7 @@ def test_reset_rest(transport: str = "rest", request_type=compute.ResetInstanceR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2863,7 +2903,7 @@ def test_reset_rest(transport: str = "rest", request_type=compute.ResetInstanceR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2875,7 +2915,7 @@ def test_reset_rest(transport: str = "rest", request_type=compute.ResetInstanceR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2914,9 +2954,10 @@ def test_reset_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_reset_rest_flattened_error(): @@ -2955,7 +2996,7 @@ def test_set_deletion_protection_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2967,7 +3008,7 @@ def test_set_deletion_protection_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2991,7 +3032,7 @@ def test_set_deletion_protection_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3003,7 +3044,7 @@ def test_set_deletion_protection_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3042,9 +3083,10 @@ def test_set_deletion_protection_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_set_deletion_protection_rest_flattened_error(): @@ -3083,7 +3125,7 @@ def test_set_disk_auto_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3095,7 +3137,7 @@ def test_set_disk_auto_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3119,7 +3161,7 @@ def test_set_disk_auto_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3131,7 +3173,7 @@ def test_set_disk_auto_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3174,11 +3216,12 @@ def test_set_disk_auto_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert str(True) in http_call[1] + str(body) - assert "device_name_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert str(True) in http_call[1] + str(body) + str(params) + assert "device_name_value" in http_call[1] + str(body) + str(params) def test_set_disk_auto_delete_rest_flattened_error(): @@ -3288,14 +3331,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.ZoneSetPolicyRequest.to_json( zone_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -3337,7 +3381,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3349,7 +3393,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3373,7 +3417,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3385,7 +3429,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3430,14 +3474,15 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesSetLabelsRequest.to_json( instances_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -3479,7 +3524,7 @@ def test_set_machine_resources_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3491,7 +3536,7 @@ def test_set_machine_resources_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3515,7 +3560,7 @@ def test_set_machine_resources_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3527,7 +3572,7 @@ def test_set_machine_resources_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3572,14 +3617,15 @@ def test_set_machine_resources_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesSetMachineResourcesRequest.to_json( instances_set_machine_resources_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_machine_resources_rest_flattened_error(): @@ -3621,7 +3667,7 @@ def test_set_machine_type_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3633,7 +3679,7 @@ def test_set_machine_type_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3657,7 +3703,7 @@ def test_set_machine_type_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3669,7 +3715,7 @@ def test_set_machine_type_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3714,14 +3760,15 @@ def test_set_machine_type_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesSetMachineTypeRequest.to_json( instances_set_machine_type_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_machine_type_rest_flattened_error(): @@ -3763,7 +3810,7 @@ def test_set_metadata_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3775,7 +3822,7 @@ def test_set_metadata_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3799,7 +3846,7 @@ def test_set_metadata_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3811,7 +3858,7 @@ def test_set_metadata_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3854,14 +3901,15 @@ def test_set_metadata_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.Metadata.to_json( metadata_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_metadata_rest_flattened_error(): @@ -3901,7 +3949,7 @@ def test_set_min_cpu_platform_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3913,7 +3961,7 @@ def test_set_min_cpu_platform_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3937,7 +3985,7 @@ def test_set_min_cpu_platform_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3949,7 +3997,7 @@ def test_set_min_cpu_platform_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3994,14 +4042,15 @@ def test_set_min_cpu_platform_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesSetMinCpuPlatformRequest.to_json( instances_set_min_cpu_platform_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_min_cpu_platform_rest_flattened_error(): @@ -4043,7 +4092,7 @@ def test_set_scheduling_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4055,7 +4104,7 @@ def test_set_scheduling_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4079,7 +4128,7 @@ def test_set_scheduling_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4091,7 +4140,7 @@ def test_set_scheduling_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4134,14 +4183,15 @@ def test_set_scheduling_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.Scheduling.to_json( scheduling_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_scheduling_rest_flattened_error(): @@ -4181,7 +4231,7 @@ def test_set_service_account_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4193,7 +4243,7 @@ def test_set_service_account_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4217,7 +4267,7 @@ def test_set_service_account_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4229,7 +4279,7 @@ def test_set_service_account_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4274,14 +4324,15 @@ def test_set_service_account_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesSetServiceAccountRequest.to_json( instances_set_service_account_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_service_account_rest_flattened_error(): @@ -4324,7 +4375,7 @@ def test_set_shielded_instance_integrity_policy_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4336,7 +4387,7 @@ def test_set_shielded_instance_integrity_policy_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4360,7 +4411,7 @@ def test_set_shielded_instance_integrity_policy_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4372,7 +4423,7 @@ def test_set_shielded_instance_integrity_policy_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4417,14 +4468,15 @@ def test_set_shielded_instance_integrity_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.ShieldedInstanceIntegrityPolicy.to_json( shielded_instance_integrity_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_shielded_instance_integrity_policy_rest_flattened_error(): @@ -4466,7 +4518,7 @@ def test_set_tags_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4478,7 +4530,7 @@ def test_set_tags_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4502,7 +4554,7 @@ def test_set_tags_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4514,7 +4566,7 @@ def test_set_tags_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4557,14 +4609,15 @@ def test_set_tags_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.Tags.to_json( tags_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_tags_rest_flattened_error(): @@ -4605,7 +4658,7 @@ def test_simulate_maintenance_event_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4617,7 +4670,7 @@ def test_simulate_maintenance_event_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4641,7 +4694,7 @@ def test_simulate_maintenance_event_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4653,7 +4706,7 @@ def test_simulate_maintenance_event_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4692,9 +4745,10 @@ def test_simulate_maintenance_event_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_simulate_maintenance_event_rest_flattened_error(): @@ -4731,7 +4785,7 @@ def test_start_rest(transport: str = "rest", request_type=compute.StartInstanceR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4743,7 +4797,7 @@ def test_start_rest(transport: str = "rest", request_type=compute.StartInstanceR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4767,7 +4821,7 @@ def test_start_rest(transport: str = "rest", request_type=compute.StartInstanceR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4779,7 +4833,7 @@ def test_start_rest(transport: str = "rest", request_type=compute.StartInstanceR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4818,9 +4872,10 @@ def test_start_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_start_rest_flattened_error(): @@ -4859,7 +4914,7 @@ def test_start_with_encryption_key_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -4871,7 +4926,7 @@ def test_start_with_encryption_key_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -4895,7 +4950,7 @@ def test_start_with_encryption_key_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -4907,7 +4962,7 @@ def test_start_with_encryption_key_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -4958,14 +5013,15 @@ def test_start_with_encryption_key_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.InstancesStartWithEncryptionKeyRequest.to_json( instances_start_with_encryption_key_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_start_with_encryption_key_rest_flattened_error(): @@ -5011,7 +5067,7 @@ def test_stop_rest(transport: str = "rest", request_type=compute.StopInstanceReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5023,7 +5079,7 @@ def test_stop_rest(transport: str = "rest", request_type=compute.StopInstanceReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5047,7 +5103,7 @@ def test_stop_rest(transport: str = "rest", request_type=compute.StopInstanceReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5059,7 +5115,7 @@ def test_stop_rest(transport: str = "rest", request_type=compute.StopInstanceReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5098,9 +5154,10 @@ def test_stop_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) def test_stop_rest_flattened_error(): @@ -5184,14 +5241,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): @@ -5233,7 +5291,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5245,7 +5303,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5269,7 +5327,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5281,7 +5339,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5328,14 +5386,15 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.Instance.to_json( instance_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): @@ -5379,7 +5438,7 @@ def test_update_access_config_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5391,7 +5450,7 @@ def test_update_access_config_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5415,7 +5474,7 @@ def test_update_access_config_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5427,7 +5486,7 @@ def test_update_access_config_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5471,15 +5530,16 @@ def test_update_access_config_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "network_interface_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "network_interface_value" in http_call[1] + str(body) + str(params) assert compute.AccessConfig.to_json( access_config_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_access_config_rest_flattened_error(): @@ -5520,7 +5580,7 @@ def test_update_display_device_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5532,7 +5592,7 @@ def test_update_display_device_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5556,7 +5616,7 @@ def test_update_display_device_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5568,7 +5628,7 @@ def test_update_display_device_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5611,14 +5671,15 @@ def test_update_display_device_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.DisplayDevice.to_json( display_device_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_display_device_rest_flattened_error(): @@ -5658,7 +5719,7 @@ def test_update_network_interface_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5670,7 +5731,7 @@ def test_update_network_interface_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5694,7 +5755,7 @@ def test_update_network_interface_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5706,7 +5767,7 @@ def test_update_network_interface_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5752,15 +5813,16 @@ def test_update_network_interface_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) - assert "network_interface_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) + assert "network_interface_value" in http_call[1] + str(body) + str(params) assert compute.NetworkInterface.to_json( network_interface_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_network_interface_rest_flattened_error(): @@ -5804,7 +5866,7 @@ def test_update_shielded_instance_config_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -5816,7 +5878,7 @@ def test_update_shielded_instance_config_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -5840,7 +5902,7 @@ def test_update_shielded_instance_config_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -5852,7 +5914,7 @@ def test_update_shielded_instance_config_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -5897,14 +5959,15 @@ def test_update_shielded_instance_config_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "instance_value" in http_call[1] + str(body) + str(params) assert compute.ShieldedInstanceConfig.to_json( shielded_instance_config_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_shielded_instance_config_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_interconnect_attachments.py b/tests/unit/gapic/compute_v1/test_interconnect_attachments.py index 9154a4d03..f325c86cc 100644 --- a/tests/unit/gapic/compute_v1/test_interconnect_attachments.py +++ b/tests/unit/gapic/compute_v1/test_interconnect_attachments.py @@ -120,6 +120,28 @@ def test_interconnect_attachments_client_from_service_account_info(client_class) assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.InterconnectAttachmentsRestTransport, "rest"),], +) +def test_interconnect_attachments_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InterconnectAttachmentsClient,]) def test_interconnect_attachments_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -515,7 +537,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -624,7 +647,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -636,7 +659,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -660,7 +683,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -672,7 +695,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -715,9 +738,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "interconnect_attachment_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "interconnect_attachment_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -762,7 +786,7 @@ def test_get_rest( edge_availability_domain=compute.InterconnectAttachment.EdgeAvailabilityDomain.AVAILABILITY_DOMAIN_1, encryption=compute.InterconnectAttachment.Encryption.IPSEC, google_reference_id="google_reference_id_value", - id="id_value", + id=205, interconnect="interconnect_value", ipsec_internal_addresses=["ipsec_internal_addresses_value"], kind="kind_value", @@ -770,7 +794,7 @@ def test_get_rest( name="name_value", operational_status=compute.InterconnectAttachment.OperationalStatus.OS_ACTIVE, pairing_key="pairing_key_value", - partner_asn="partner_asn_value", + partner_asn=1181, partner_metadata=compute.InterconnectAttachmentPartnerMetadata( interconnect_name="interconnect_name_value" ), @@ -809,7 +833,7 @@ def test_get_rest( ) assert response.encryption == compute.InterconnectAttachment.Encryption.IPSEC assert response.google_reference_id == "google_reference_id_value" - assert response.id == "id_value" + assert response.id == 205 assert response.interconnect == "interconnect_value" assert response.ipsec_internal_addresses == ["ipsec_internal_addresses_value"] assert response.kind == "kind_value" @@ -820,7 +844,7 @@ def test_get_rest( == compute.InterconnectAttachment.OperationalStatus.OS_ACTIVE ) assert response.pairing_key == "pairing_key_value" - assert response.partner_asn == "partner_asn_value" + assert response.partner_asn == 1181 assert response.partner_metadata == compute.InterconnectAttachmentPartnerMetadata( interconnect_name="interconnect_name_value" ) @@ -870,9 +894,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "interconnect_attachment_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "interconnect_attachment_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -913,7 +938,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -925,7 +950,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -949,7 +974,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -961,7 +986,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1007,13 +1032,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.InterconnectAttachment.to_json( interconnect_attachment_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1107,8 +1133,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1203,7 +1230,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1215,7 +1242,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1239,7 +1266,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1251,7 +1278,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1298,14 +1325,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "interconnect_attachment_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "interconnect_attachment_value" in http_call[1] + str(body) + str(params) assert compute.InterconnectAttachment.to_json( interconnect_attachment_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_interconnect_locations.py b/tests/unit/gapic/compute_v1/test_interconnect_locations.py index d2c4d1381..7312bc97b 100644 --- a/tests/unit/gapic/compute_v1/test_interconnect_locations.py +++ b/tests/unit/gapic/compute_v1/test_interconnect_locations.py @@ -120,6 +120,28 @@ def test_interconnect_locations_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.InterconnectLocationsRestTransport, "rest"),], +) +def test_interconnect_locations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InterconnectLocationsClient,]) def test_interconnect_locations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -448,15 +470,11 @@ def test_get_rest( description="description_value", facility_provider="facility_provider_value", facility_provider_facility_id="facility_provider_facility_id_value", - id="id_value", + id=205, kind="kind_value", name="name_value", peeringdb_facility_id="peeringdb_facility_id_value", - region_infos=[ - compute.InterconnectLocationRegionInfo( - expected_rtt_ms="expected_rtt_ms_value" - ) - ], + region_infos=[compute.InterconnectLocationRegionInfo(expected_rtt_ms=1610)], self_link="self_link_value", status=compute.InterconnectLocation.Status.AVAILABLE, ) @@ -481,12 +499,12 @@ def test_get_rest( assert ( response.facility_provider_facility_id == "facility_provider_facility_id_value" ) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.peeringdb_facility_id == "peeringdb_facility_id_value" assert response.region_infos == [ - compute.InterconnectLocationRegionInfo(expected_rtt_ms="expected_rtt_ms_value") + compute.InterconnectLocationRegionInfo(expected_rtt_ms=1610) ] assert response.self_link == "self_link_value" assert response.status == compute.InterconnectLocation.Status.AVAILABLE @@ -525,8 +543,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "interconnect_location_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "interconnect_location_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -615,7 +634,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_interconnects.py b/tests/unit/gapic/compute_v1/test_interconnects.py index d694e3f79..e26bf7831 100644 --- a/tests/unit/gapic/compute_v1/test_interconnects.py +++ b/tests/unit/gapic/compute_v1/test_interconnects.py @@ -117,6 +117,27 @@ def test_interconnects_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.InterconnectsRestTransport, "rest"),] +) +def test_interconnects_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [InterconnectsClient,]) def test_interconnects_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -416,7 +437,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -428,7 +449,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -452,7 +473,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -464,7 +485,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -503,8 +524,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "interconnect_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "interconnect_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -549,7 +571,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetInterconnectR ], google_ip_address="google_ip_address_value", google_reference_id="google_reference_id_value", - id="id_value", + id=205, interconnect_attachments=["interconnect_attachments_value"], interconnect_type=compute.Interconnect.InterconnectType.DEDICATED, kind="kind_value", @@ -589,7 +611,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetInterconnectR ] assert response.google_ip_address == "google_ip_address_value" assert response.google_reference_id == "google_reference_id_value" - assert response.id == "id_value" + assert response.id == 205 assert response.interconnect_attachments == ["interconnect_attachments_value"] assert response.interconnect_type == compute.Interconnect.InterconnectType.DEDICATED assert response.kind == "kind_value" @@ -639,8 +661,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "interconnect_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "interconnect_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -731,8 +754,9 @@ def test_get_diagnostics_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "interconnect_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "interconnect_value" in http_call[1] + str(body) + str(params) def test_get_diagnostics_rest_flattened_error(): @@ -770,7 +794,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -782,7 +806,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -806,7 +830,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -818,7 +842,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -858,12 +882,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Interconnect.to_json( interconnect_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -948,7 +973,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1032,7 +1058,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1044,7 +1070,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1068,7 +1094,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1080,7 +1106,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1122,13 +1148,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "interconnect_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "interconnect_value" in http_call[1] + str(body) + str(params) assert compute.Interconnect.to_json( interconnect_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_license_codes.py b/tests/unit/gapic/compute_v1/test_license_codes.py index bb88f4b76..99d81a433 100644 --- a/tests/unit/gapic/compute_v1/test_license_codes.py +++ b/tests/unit/gapic/compute_v1/test_license_codes.py @@ -113,6 +113,27 @@ def test_license_codes_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.LicenseCodesRestTransport, "rest"),] +) +def test_license_codes_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [LicenseCodesClient,]) def test_license_codes_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -401,7 +422,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetLicenseCodeRe return_value = compute.LicenseCode( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", license_alias=[ compute.LicenseCodeLicenseAlias(description="description_value") @@ -424,7 +445,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetLicenseCodeRe assert isinstance(response, compute.LicenseCode) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.license_alias == [ compute.LicenseCodeLicenseAlias(description="description_value") @@ -465,8 +486,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "license_code_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "license_code_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -548,13 +570,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_licenses.py b/tests/unit/gapic/compute_v1/test_licenses.py index 50ad26ff1..cca708c67 100644 --- a/tests/unit/gapic/compute_v1/test_licenses.py +++ b/tests/unit/gapic/compute_v1/test_licenses.py @@ -112,6 +112,27 @@ def test_licenses_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.LicensesRestTransport, "rest"),] +) +def test_licenses_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [LicensesClient,]) def test_licenses_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -492,8 +513,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "license__value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "license__value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -525,9 +547,9 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetLicenseReques charges_use_fee=True, creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", - license_code="license_code_value", + license_code=1245, name="name_value", resource_requirements=compute.LicenseResourceRequirements( min_guest_cpu_count=2042 @@ -549,9 +571,9 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetLicenseReques assert response.charges_use_fee is True assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" - assert response.license_code == "license_code_value" + assert response.license_code == 1245 assert response.name == "name_value" assert response.resource_requirements == compute.LicenseResourceRequirements( min_guest_cpu_count=2042 @@ -590,8 +612,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "license__value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "license__value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -692,8 +715,9 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -731,7 +755,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -743,7 +767,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -767,7 +791,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -779,7 +803,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -819,12 +843,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.License.to_json( license_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -905,7 +930,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1053,13 +1079,14 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetPolicyRequest.to_json( global_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1144,13 +1171,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_machine_types.py b/tests/unit/gapic/compute_v1/test_machine_types.py index bd7232bf8..40e2f7fbd 100644 --- a/tests/unit/gapic/compute_v1/test_machine_types.py +++ b/tests/unit/gapic/compute_v1/test_machine_types.py @@ -114,6 +114,27 @@ def test_machine_types_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.MachineTypesRestTransport, "rest"),] +) +def test_machine_types_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [MachineTypesClient,]) def test_machine_types_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -476,7 +497,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -571,12 +593,12 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetMachineTypeRe deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", guest_cpus=1090, - id="id_value", + id=205, image_space_gb=1430, is_shared_cpu=True, kind="kind_value", maximum_persistent_disks=2603, - maximum_persistent_disks_size_gb="maximum_persistent_disks_size_gb_value", + maximum_persistent_disks_size_gb=3437, memory_mb=967, name="name_value", scratch_disks=[compute.ScratchDisks(disk_gb=723)], @@ -599,15 +621,12 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetMachineTypeRe assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" assert response.guest_cpus == 1090 - assert response.id == "id_value" + assert response.id == 205 assert response.image_space_gb == 1430 assert response.is_shared_cpu is True assert response.kind == "kind_value" assert response.maximum_persistent_disks == 2603 - assert ( - response.maximum_persistent_disks_size_gb - == "maximum_persistent_disks_size_gb_value" - ) + assert response.maximum_persistent_disks_size_gb == 3437 assert response.memory_mb == 967 assert response.name == "name_value" assert response.scratch_disks == [compute.ScratchDisks(disk_gb=723)] @@ -647,9 +666,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "machine_type_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "machine_type_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -745,8 +765,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py b/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py index b02392cab..8aa7a7793 100644 --- a/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py +++ b/tests/unit/gapic/compute_v1/test_network_endpoint_groups.py @@ -120,6 +120,28 @@ def test_network_endpoint_groups_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.NetworkEndpointGroupsRestTransport, "rest"),], +) +def test_network_endpoint_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [NetworkEndpointGroupsClient,]) def test_network_endpoint_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -517,7 +539,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -627,7 +650,7 @@ def test_attach_network_endpoints_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -639,7 +662,7 @@ def test_attach_network_endpoints_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -663,7 +686,7 @@ def test_attach_network_endpoints_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -675,7 +698,7 @@ def test_attach_network_endpoints_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -724,14 +747,15 @@ def test_attach_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroupsAttachEndpointsRequest.to_json( network_endpoint_groups_attach_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_attach_network_endpoints_rest_flattened_error(): @@ -777,7 +801,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -789,7 +813,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -813,7 +837,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -825,7 +849,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -868,9 +892,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -912,7 +937,7 @@ def test_detach_network_endpoints_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -924,7 +949,7 @@ def test_detach_network_endpoints_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -948,7 +973,7 @@ def test_detach_network_endpoints_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -960,7 +985,7 @@ def test_detach_network_endpoints_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1009,14 +1034,15 @@ def test_detach_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroupsDetachEndpointsRequest.to_json( network_endpoint_groups_detach_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_detach_network_endpoints_rest_flattened_error(): @@ -1064,7 +1090,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", default_port=1289, description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", network="network_value", @@ -1099,7 +1125,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.default_port == 1289 assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network == "network_value" @@ -1148,9 +1174,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1191,7 +1218,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1203,7 +1230,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1227,7 +1254,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1239,7 +1266,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1285,13 +1312,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroup.to_json( network_endpoint_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1389,8 +1417,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1560,14 +1589,15 @@ def test_list_network_endpoints_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroupsListEndpointsRequest.to_json( network_endpoint_groups_list_endpoints_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_list_network_endpoints_rest_flattened_error(): @@ -1720,14 +1750,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_networks.py b/tests/unit/gapic/compute_v1/test_networks.py index 2c71147e5..385c7c697 100644 --- a/tests/unit/gapic/compute_v1/test_networks.py +++ b/tests/unit/gapic/compute_v1/test_networks.py @@ -112,6 +112,27 @@ def test_networks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.NetworksRestTransport, "rest"),] +) +def test_networks_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [NetworksClient,]) def test_networks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_add_peering_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_add_peering_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_add_peering_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_add_peering_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -497,13 +518,14 @@ def test_add_peering_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) assert compute.NetworksAddPeeringRequest.to_json( networks_add_peering_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_peering_rest_flattened_error(): @@ -544,7 +566,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -556,7 +578,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -580,7 +602,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -592,7 +614,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -631,8 +653,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -666,7 +689,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNetworkReques creation_timestamp="creation_timestamp_value", description="description_value", gateway_i_pv4="gateway_i_pv4_value", - id="id_value", + id=205, kind="kind_value", mtu=342, name="name_value", @@ -693,7 +716,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNetworkReques assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.gateway_i_pv4 == "gateway_i_pv4_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.mtu == 342 assert response.name == "name_value" @@ -735,8 +758,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -833,8 +857,9 @@ def test_get_effective_firewalls_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) def test_get_effective_firewalls_rest_flattened_error(): @@ -872,7 +897,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -884,7 +909,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -908,7 +933,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -920,7 +945,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -960,12 +985,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Network.to_json( network_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1048,7 +1074,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1175,8 +1202,9 @@ def test_list_peering_routes_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) def test_list_peering_routes_rest_flattened_error(): @@ -1265,7 +1293,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchNetworkRe error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1277,7 +1305,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchNetworkRe start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1301,7 +1329,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchNetworkRe assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1313,7 +1341,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchNetworkRe assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1355,13 +1383,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) assert compute.Network.to_json( network_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1400,7 +1429,7 @@ def test_remove_peering_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1412,7 +1441,7 @@ def test_remove_peering_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1436,7 +1465,7 @@ def test_remove_peering_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1448,7 +1477,7 @@ def test_remove_peering_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1492,13 +1521,14 @@ def test_remove_peering_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) assert compute.NetworksRemovePeeringRequest.to_json( networks_remove_peering_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_peering_rest_flattened_error(): @@ -1539,7 +1569,7 @@ def test_switch_to_custom_mode_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1551,7 +1581,7 @@ def test_switch_to_custom_mode_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1575,7 +1605,7 @@ def test_switch_to_custom_mode_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1587,7 +1617,7 @@ def test_switch_to_custom_mode_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1626,8 +1656,9 @@ def test_switch_to_custom_mode_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) def test_switch_to_custom_mode_rest_flattened_error(): @@ -1665,7 +1696,7 @@ def test_update_peering_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1677,7 +1708,7 @@ def test_update_peering_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1701,7 +1732,7 @@ def test_update_peering_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1713,7 +1744,7 @@ def test_update_peering_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1757,13 +1788,14 @@ def test_update_peering_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "network_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "network_value" in http_call[1] + str(body) + str(params) assert compute.NetworksUpdatePeeringRequest.to_json( networks_update_peering_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_peering_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_node_groups.py b/tests/unit/gapic/compute_v1/test_node_groups.py index f085711e3..4e48c96dd 100644 --- a/tests/unit/gapic/compute_v1/test_node_groups.py +++ b/tests/unit/gapic/compute_v1/test_node_groups.py @@ -114,6 +114,27 @@ def test_node_groups_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.NodeGroupsRestTransport, "rest"),] +) +def test_node_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [NodeGroupsClient,]) def test_node_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -409,7 +430,7 @@ def test_add_nodes_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -421,7 +442,7 @@ def test_add_nodes_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -445,7 +466,7 @@ def test_add_nodes_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -457,7 +478,7 @@ def test_add_nodes_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -502,14 +523,15 @@ def test_add_nodes_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) assert compute.NodeGroupsAddNodesRequest.to_json( node_groups_add_nodes_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_nodes_rest_flattened_error(): @@ -618,7 +640,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -714,7 +737,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -726,7 +749,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -750,7 +773,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -762,7 +785,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -801,9 +824,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -842,7 +866,7 @@ def test_delete_nodes_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -854,7 +878,7 @@ def test_delete_nodes_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -878,7 +902,7 @@ def test_delete_nodes_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -890,7 +914,7 @@ def test_delete_nodes_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -935,14 +959,15 @@ def test_delete_nodes_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) assert compute.NodeGroupsDeleteNodesRequest.to_json( node_groups_delete_nodes_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_delete_nodes_rest_flattened_error(): @@ -979,7 +1004,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeGroupRequ creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", location_hint="location_hint_value", maintenance_policy=compute.NodeGroup.MaintenancePolicy.DEFAULT, @@ -1010,7 +1035,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeGroupRequ assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.location_hint == "location_hint_value" assert response.maintenance_policy == compute.NodeGroup.MaintenancePolicy.DEFAULT @@ -1055,9 +1080,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1159,9 +1185,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1200,7 +1227,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1212,7 +1239,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1236,7 +1263,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1248,7 +1275,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1293,14 +1320,15 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert str(1911) in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert str(1911) in http_call[1] + str(body) + str(params) assert compute.NodeGroup.to_json( node_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1397,8 +1425,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1531,9 +1560,10 @@ def test_list_nodes_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) def test_list_nodes_rest_flattened_error(): @@ -1620,7 +1650,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1632,7 +1662,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1656,7 +1686,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1668,7 +1698,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1713,14 +1743,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) assert compute.NodeGroup.to_json( node_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1831,14 +1862,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.ZoneSetPolicyRequest.to_json( zone_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1880,7 +1912,7 @@ def test_set_node_template_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1892,7 +1924,7 @@ def test_set_node_template_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1916,7 +1948,7 @@ def test_set_node_template_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1928,7 +1960,7 @@ def test_set_node_template_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1973,14 +2005,15 @@ def test_set_node_template_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_group_value" in http_call[1] + str(body) + str(params) assert compute.NodeGroupsSetNodeTemplateRequest.to_json( node_groups_set_node_template_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_node_template_rest_flattened_error(): @@ -2067,14 +2100,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_node_templates.py b/tests/unit/gapic/compute_v1/test_node_templates.py index 8b0ad9201..b71e569f3 100644 --- a/tests/unit/gapic/compute_v1/test_node_templates.py +++ b/tests/unit/gapic/compute_v1/test_node_templates.py @@ -117,6 +117,27 @@ def test_node_templates_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.NodeTemplatesRestTransport, "rest"),] +) +def test_node_templates_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [NodeTemplatesClient,]) def test_node_templates_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -483,7 +504,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -584,7 +606,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -596,7 +618,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -620,7 +642,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -632,7 +654,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -673,9 +695,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "node_template_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "node_template_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -710,7 +733,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeTemplateR creation_timestamp="creation_timestamp_value", description="description_value", disks=[compute.LocalDisk(disk_count=1075)], - id="id_value", + id=205, kind="kind_value", name="name_value", node_affinity_labels={"key_value": "value_value"}, @@ -745,7 +768,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeTemplateR assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.disks == [compute.LocalDisk(disk_count=1075)] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.node_affinity_labels == {"key_value": "value_value"} @@ -794,9 +817,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "node_template_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "node_template_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -898,9 +922,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -939,7 +964,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -951,7 +976,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -975,7 +1000,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -987,7 +1012,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1031,13 +1056,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.NodeTemplate.to_json( node_template_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1135,8 +1161,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1291,14 +1318,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetPolicyRequest.to_json( region_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1385,14 +1413,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_node_types.py b/tests/unit/gapic/compute_v1/test_node_types.py index 575856b68..50305d33f 100644 --- a/tests/unit/gapic/compute_v1/test_node_types.py +++ b/tests/unit/gapic/compute_v1/test_node_types.py @@ -112,6 +112,27 @@ def test_node_types_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.NodeTypesRestTransport, "rest"),] +) +def test_node_types_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [NodeTypesClient,]) def test_node_types_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -464,7 +485,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -556,7 +578,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeTypeReque deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", guest_cpus=1090, - id="id_value", + id=205, kind="kind_value", local_ssd_gb=1244, memory_mb=967, @@ -580,7 +602,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetNodeTypeReque assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" assert response.guest_cpus == 1090 - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.local_ssd_gb == 1244 assert response.memory_mb == 967 @@ -619,9 +641,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "node_type_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "node_type_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -707,8 +730,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_packet_mirrorings.py b/tests/unit/gapic/compute_v1/test_packet_mirrorings.py index 4f459cc8b..41e9c1012 100644 --- a/tests/unit/gapic/compute_v1/test_packet_mirrorings.py +++ b/tests/unit/gapic/compute_v1/test_packet_mirrorings.py @@ -118,6 +118,28 @@ def test_packet_mirrorings_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.PacketMirroringsRestTransport, "rest"),], +) +def test_packet_mirrorings_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [PacketMirroringsClient,]) def test_packet_mirrorings_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -496,7 +518,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -598,7 +621,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -610,7 +633,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -634,7 +657,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -646,7 +669,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -687,9 +710,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "packet_mirroring_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "packet_mirroring_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -728,7 +752,7 @@ def test_get_rest( description="description_value", enable=compute.PacketMirroring.Enable.FALSE, filter=compute.PacketMirroringFilter(I_p_protocols=["I_p_protocols_value"]), - id="id_value", + id=205, kind="kind_value", mirrored_resources=compute.PacketMirroringMirroredResourceInfo( instances=[ @@ -765,7 +789,7 @@ def test_get_rest( assert response.filter == compute.PacketMirroringFilter( I_p_protocols=["I_p_protocols_value"] ) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.mirrored_resources == compute.PacketMirroringMirroredResourceInfo( instances=[ @@ -815,9 +839,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "packet_mirroring_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "packet_mirroring_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -856,7 +881,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -868,7 +893,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -892,7 +917,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -904,7 +929,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -950,13 +975,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.PacketMirroring.to_json( packet_mirroring_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1060,8 +1086,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1147,7 +1174,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1159,7 +1186,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1183,7 +1210,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1195,7 +1222,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1242,14 +1269,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "packet_mirroring_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "packet_mirroring_value" in http_call[1] + str(body) + str(params) assert compute.PacketMirroring.to_json( packet_mirroring_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1339,14 +1367,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_projects.py b/tests/unit/gapic/compute_v1/test_projects.py index 913e8ffb9..52f73c597 100644 --- a/tests/unit/gapic/compute_v1/test_projects.py +++ b/tests/unit/gapic/compute_v1/test_projects.py @@ -112,6 +112,27 @@ def test_projects_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.ProjectsRestTransport, "rest"),] +) +def test_projects_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ProjectsClient,]) def test_projects_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_disable_xpn_host_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_disable_xpn_host_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_disable_xpn_host_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_disable_xpn_host_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -490,7 +511,8 @@ def test_disable_xpn_host_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_disable_xpn_host_rest_flattened_error(): @@ -526,7 +548,7 @@ def test_disable_xpn_resource_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -538,7 +560,7 @@ def test_disable_xpn_resource_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -562,7 +584,7 @@ def test_disable_xpn_resource_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -574,7 +596,7 @@ def test_disable_xpn_resource_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -617,12 +639,13 @@ def test_disable_xpn_resource_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ProjectsDisableXpnResourceRequest.to_json( projects_disable_xpn_resource_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_disable_xpn_resource_rest_flattened_error(): @@ -662,7 +685,7 @@ def test_enable_xpn_host_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -674,7 +697,7 @@ def test_enable_xpn_host_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -698,7 +721,7 @@ def test_enable_xpn_host_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -710,7 +733,7 @@ def test_enable_xpn_host_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -747,7 +770,8 @@ def test_enable_xpn_host_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_enable_xpn_host_rest_flattened_error(): @@ -783,7 +807,7 @@ def test_enable_xpn_resource_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -795,7 +819,7 @@ def test_enable_xpn_resource_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -819,7 +843,7 @@ def test_enable_xpn_resource_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -831,7 +855,7 @@ def test_enable_xpn_resource_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -874,12 +898,13 @@ def test_enable_xpn_resource_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ProjectsEnableXpnResourceRequest.to_json( projects_enable_xpn_resource_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_enable_xpn_resource_rest_flattened_error(): @@ -916,7 +941,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetProjectReques default_service_account="default_service_account_value", description="description_value", enabled_features=["enabled_features_value"], - id="id_value", + id=205, kind="kind_value", name="name_value", quotas=[compute.Quota(limit=0.543)], @@ -945,7 +970,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetProjectReques assert response.default_service_account == "default_service_account_value" assert response.description == "description_value" assert response.enabled_features == ["enabled_features_value"] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.quotas == [compute.Quota(limit=0.543)] @@ -984,7 +1009,8 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1019,7 +1045,7 @@ def test_get_xpn_host_rest( default_service_account="default_service_account_value", description="description_value", enabled_features=["enabled_features_value"], - id="id_value", + id=205, kind="kind_value", name="name_value", quotas=[compute.Quota(limit=0.543)], @@ -1048,7 +1074,7 @@ def test_get_xpn_host_rest( assert response.default_service_account == "default_service_account_value" assert response.description == "description_value" assert response.enabled_features == ["enabled_features_value"] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.quotas == [compute.Quota(limit=0.543)] @@ -1087,7 +1113,8 @@ def test_get_xpn_host_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_get_xpn_host_rest_flattened_error(): @@ -1164,7 +1191,8 @@ def test_get_xpn_resources_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_get_xpn_resources_rest_flattened_error(): @@ -1311,12 +1339,13 @@ def test_list_xpn_hosts_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ProjectsListXpnHostsRequest.to_json( projects_list_xpn_hosts_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_list_xpn_hosts_rest_flattened_error(): @@ -1396,7 +1425,7 @@ def test_move_disk_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1408,7 +1437,7 @@ def test_move_disk_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1432,7 +1461,7 @@ def test_move_disk_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1444,7 +1473,7 @@ def test_move_disk_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1487,12 +1516,13 @@ def test_move_disk_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.DiskMoveRequest.to_json( disk_move_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_move_disk_rest_flattened_error(): @@ -1532,7 +1562,7 @@ def test_move_instance_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1544,7 +1574,7 @@ def test_move_instance_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1568,7 +1598,7 @@ def test_move_instance_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1580,7 +1610,7 @@ def test_move_instance_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1623,12 +1653,13 @@ def test_move_instance_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.InstanceMoveRequest.to_json( instance_move_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_move_instance_rest_flattened_error(): @@ -1669,7 +1700,7 @@ def test_set_common_instance_metadata_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1681,7 +1712,7 @@ def test_set_common_instance_metadata_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1705,7 +1736,7 @@ def test_set_common_instance_metadata_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1717,7 +1748,7 @@ def test_set_common_instance_metadata_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1757,12 +1788,13 @@ def test_set_common_instance_metadata_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Metadata.to_json( metadata_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_common_instance_metadata_rest_flattened_error(): @@ -1800,7 +1832,7 @@ def test_set_default_network_tier_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1812,7 +1844,7 @@ def test_set_default_network_tier_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1836,7 +1868,7 @@ def test_set_default_network_tier_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1848,7 +1880,7 @@ def test_set_default_network_tier_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1891,12 +1923,13 @@ def test_set_default_network_tier_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.ProjectsSetDefaultNetworkTierRequest.to_json( projects_set_default_network_tier_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_default_network_tier_rest_flattened_error(): @@ -1936,7 +1969,7 @@ def test_set_usage_export_bucket_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1948,7 +1981,7 @@ def test_set_usage_export_bucket_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1972,7 +2005,7 @@ def test_set_usage_export_bucket_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1984,7 +2017,7 @@ def test_set_usage_export_bucket_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2027,12 +2060,13 @@ def test_set_usage_export_bucket_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.UsageExportLocation.to_json( usage_export_location_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_usage_export_bucket_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py b/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py index e1330fc06..a37158ba4 100644 --- a/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py +++ b/tests/unit/gapic/compute_v1/test_public_advertised_prefixes.py @@ -120,6 +120,28 @@ def test_public_advertised_prefixes_client_from_service_account_info(client_clas assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.PublicAdvertisedPrefixesRestTransport, "rest"),], +) +def test_public_advertised_prefixes_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [PublicAdvertisedPrefixesClient,]) def test_public_advertised_prefixes_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -451,7 +473,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -463,7 +485,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -487,7 +509,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -499,7 +521,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -541,8 +563,11 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_advertised_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_advertised_prefix_value" in http_call[1] + str(body) + str( + params + ) def test_delete_rest_flattened_error(): @@ -579,7 +604,7 @@ def test_get_rest( description="description_value", dns_verification_ip="dns_verification_ip_value", fingerprint="fingerprint_value", - id="id_value", + id=205, ip_cidr_range="ip_cidr_range_value", kind="kind_value", name="name_value", @@ -607,7 +632,7 @@ def test_get_rest( assert response.description == "description_value" assert response.dns_verification_ip == "dns_verification_ip_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_cidr_range == "ip_cidr_range_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -652,8 +677,11 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_advertised_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_advertised_prefix_value" in http_call[1] + str(body) + str( + params + ) def test_get_rest_flattened_error(): @@ -693,7 +721,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -705,7 +733,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -729,7 +757,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -741,7 +769,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -786,12 +814,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.PublicAdvertisedPrefix.to_json( public_advertised_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -888,7 +917,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -981,7 +1011,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -993,7 +1023,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1017,7 +1047,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1029,7 +1059,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1075,13 +1105,16 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "public_advertised_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "public_advertised_prefix_value" in http_call[1] + str(body) + str( + params + ) assert compute.PublicAdvertisedPrefix.to_json( public_advertised_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py b/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py index 665f7ac29..cc8ee28f4 100644 --- a/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py +++ b/tests/unit/gapic/compute_v1/test_public_delegated_prefixes.py @@ -120,6 +120,28 @@ def test_public_delegated_prefixes_client_from_service_account_info(client_class assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.PublicDelegatedPrefixesRestTransport, "rest"),], +) +def test_public_delegated_prefixes_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [PublicDelegatedPrefixesClient,]) def test_public_delegated_prefixes_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -519,7 +541,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -628,7 +651,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -640,7 +663,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -664,7 +687,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -676,7 +699,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -719,9 +742,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -758,7 +782,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, ip_cidr_range="ip_cidr_range_value", is_live_migration=True, kind="kind_value", @@ -787,7 +811,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_cidr_range == "ip_cidr_range_value" assert response.is_live_migration is True assert response.kind == "kind_value" @@ -837,9 +861,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -880,7 +905,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -892,7 +917,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -916,7 +941,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -928,7 +953,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -974,13 +999,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.PublicDelegatedPrefix.to_json( public_delegated_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1080,8 +1106,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1174,7 +1201,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1186,7 +1213,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1210,7 +1237,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1222,7 +1249,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1269,14 +1296,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "public_delegated_prefix_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "public_delegated_prefix_value" in http_call[1] + str(body) + str(params) assert compute.PublicDelegatedPrefix.to_json( public_delegated_prefix_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_autoscalers.py b/tests/unit/gapic/compute_v1/test_region_autoscalers.py index 9bcec6b41..a1702fecf 100644 --- a/tests/unit/gapic/compute_v1/test_region_autoscalers.py +++ b/tests/unit/gapic/compute_v1/test_region_autoscalers.py @@ -118,6 +118,28 @@ def test_region_autoscalers_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionAutoscalersRestTransport, "rest"),], +) +def test_region_autoscalers_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionAutoscalersClient,]) def test_region_autoscalers_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -516,9 +538,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "autoscaler_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "autoscaler_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -553,7 +576,7 @@ def test_get_rest( autoscaling_policy=compute.AutoscalingPolicy(cool_down_period_sec=2112), creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", recommended_size=1693, @@ -585,7 +608,7 @@ def test_get_rest( ) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.recommended_size == 1693 @@ -636,9 +659,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "autoscaler_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "autoscaler_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -677,7 +701,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -689,7 +713,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -713,7 +737,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -725,7 +749,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -769,13 +793,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -875,8 +900,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -962,7 +988,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -974,7 +1000,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -998,7 +1024,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1010,7 +1036,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1054,13 +1080,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1101,7 +1128,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1113,7 +1140,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1137,7 +1164,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1149,7 +1176,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1193,13 +1220,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Autoscaler.to_json( autoscaler_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_backend_services.py b/tests/unit/gapic/compute_v1/test_region_backend_services.py index dd5bb80e6..e92ab0aa4 100644 --- a/tests/unit/gapic/compute_v1/test_region_backend_services.py +++ b/tests/unit/gapic/compute_v1/test_region_backend_services.py @@ -120,6 +120,28 @@ def test_region_backend_services_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionBackendServicesRestTransport, "rest"),], +) +def test_region_backend_services_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionBackendServicesClient,]) def test_region_backend_services_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -447,7 +469,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -459,7 +481,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -483,7 +505,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -495,7 +517,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -538,9 +560,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -603,7 +626,7 @@ def test_get_rest( fingerprint="fingerprint_value", health_checks=["health_checks_value"], iap=compute.BackendServiceIAP(enabled=True), - id="id_value", + id=205, kind="kind_value", load_balancing_scheme=compute.BackendService.LoadBalancingScheme.EXTERNAL, locality_lb_policy=compute.BackendService.LocalityLbPolicy.INVALID_LB_POLICY, @@ -668,7 +691,7 @@ def test_get_rest( assert response.fingerprint == "fingerprint_value" assert response.health_checks == ["health_checks_value"] assert response.iap == compute.BackendServiceIAP(enabled=True) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert ( response.load_balancing_scheme @@ -732,9 +755,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -830,14 +854,15 @@ def test_get_health_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.ResourceGroupReference.to_json( resource_group_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_get_health_rest_flattened_error(): @@ -881,7 +906,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -893,7 +918,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -917,7 +942,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -929,7 +954,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -973,13 +998,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1073,8 +1099,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1164,7 +1191,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1176,7 +1203,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1200,7 +1227,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1212,7 +1239,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1257,14 +1284,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1308,7 +1336,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1320,7 +1348,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1344,7 +1372,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1356,7 +1384,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1401,14 +1429,15 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "backend_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "backend_service_value" in http_call[1] + str(body) + str(params) assert compute.BackendService.to_json( backend_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_commitments.py b/tests/unit/gapic/compute_v1/test_region_commitments.py index 9cd8457a5..646b10fe4 100644 --- a/tests/unit/gapic/compute_v1/test_region_commitments.py +++ b/tests/unit/gapic/compute_v1/test_region_commitments.py @@ -118,6 +118,28 @@ def test_region_commitments_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionCommitmentsRestTransport, "rest"),], +) +def test_region_commitments_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionCommitmentsClient,]) def test_region_commitments_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -492,7 +514,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -588,9 +611,9 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", end_timestamp="end_timestamp_value", - id="id_value", + id=205, kind="kind_value", - license_resource=compute.LicenseResourceCommitment(amount="amount_value"), + license_resource=compute.LicenseResourceCommitment(amount=660), name="name_value", plan=compute.Commitment.Plan.INVALID, region="region_value", @@ -618,11 +641,9 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.end_timestamp == "end_timestamp_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" - assert response.license_resource == compute.LicenseResourceCommitment( - amount="amount_value" - ) + assert response.license_resource == compute.LicenseResourceCommitment(amount=660) assert response.name == "name_value" assert response.plan == compute.Commitment.Plan.INVALID assert response.region == "region_value" @@ -668,9 +689,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "commitment_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "commitment_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -709,7 +731,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -721,7 +743,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -745,7 +767,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -757,7 +779,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -801,13 +823,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Commitment.to_json( commitment_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -903,8 +926,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_disk_types.py b/tests/unit/gapic/compute_v1/test_region_disk_types.py index 456fb5c8d..eb9da29f9 100644 --- a/tests/unit/gapic/compute_v1/test_region_disk_types.py +++ b/tests/unit/gapic/compute_v1/test_region_disk_types.py @@ -117,6 +117,28 @@ def test_region_disk_types_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionDiskTypesRestTransport, "rest"),], +) +def test_region_disk_types_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionDiskTypesClient,]) def test_region_disk_types_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -420,10 +442,10 @@ def test_get_rest( # Designate an appropriate value for the returned response. return_value = compute.DiskType( creation_timestamp="creation_timestamp_value", - default_disk_size_gb="default_disk_size_gb_value", + default_disk_size_gb=2097, deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", region="region_value", @@ -443,10 +465,10 @@ def test_get_rest( # Establish that the response is the type that we expect. assert isinstance(response, compute.DiskType) assert response.creation_timestamp == "creation_timestamp_value" - assert response.default_disk_size_gb == "default_disk_size_gb_value" + assert response.default_disk_size_gb == 2097 assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.region == "region_value" @@ -485,9 +507,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_type_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_type_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -577,8 +600,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_disks.py b/tests/unit/gapic/compute_v1/test_region_disks.py index 1d0cebbb1..cde064f89 100644 --- a/tests/unit/gapic/compute_v1/test_region_disks.py +++ b/tests/unit/gapic/compute_v1/test_region_disks.py @@ -114,6 +114,27 @@ def test_region_disks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.RegionDisksRestTransport, "rest"),] +) +def test_region_disks_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionDisksClient,]) def test_region_disks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -409,7 +430,7 @@ def test_add_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -421,7 +442,7 @@ def test_add_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -445,7 +466,7 @@ def test_add_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -457,7 +478,7 @@ def test_add_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -502,14 +523,15 @@ def test_add_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.RegionDisksAddResourcePoliciesRequest.to_json( region_disks_add_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_resource_policies_rest_flattened_error(): @@ -551,7 +573,7 @@ def test_create_snapshot_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -563,7 +585,7 @@ def test_create_snapshot_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -587,7 +609,7 @@ def test_create_snapshot_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -599,7 +621,7 @@ def test_create_snapshot_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -642,14 +664,15 @@ def test_create_snapshot_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.Snapshot.to_json( snapshot_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_create_snapshot_rest_flattened_error(): @@ -689,7 +712,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -701,7 +724,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -725,7 +748,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -737,7 +760,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -776,9 +799,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -818,25 +842,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionDiskReq type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ], - id="id_value", + id=205, kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, last_attach_timestamp="last_attach_timestamp_value", last_detach_timestamp="last_detach_timestamp_value", - license_codes=["license_codes_value"], + license_codes=[1360], licenses=["licenses_value"], location_hint="location_hint_value", name="name_value", options="options_value", - physical_block_size_bytes="physical_block_size_bytes_value", - provisioned_iops="provisioned_iops_value", + physical_block_size_bytes=2663, + provisioned_iops=1740, region="region_value", replica_zones=["replica_zones_value"], resource_policies=["resource_policies_value"], satisfies_pzs=True, self_link="self_link_value", - size_gb="size_gb_value", + size_gb=739, source_disk="source_disk_value", source_disk_id="source_disk_id_value", source_image="source_image_value", @@ -876,25 +900,25 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionDiskReq type_=compute.GuestOsFeature.Type.FEATURE_TYPE_UNSPECIFIED ) ] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} assert response.last_attach_timestamp == "last_attach_timestamp_value" assert response.last_detach_timestamp == "last_detach_timestamp_value" - assert response.license_codes == ["license_codes_value"] + assert response.license_codes == [1360] assert response.licenses == ["licenses_value"] assert response.location_hint == "location_hint_value" assert response.name == "name_value" assert response.options == "options_value" - assert response.physical_block_size_bytes == "physical_block_size_bytes_value" - assert response.provisioned_iops == "provisioned_iops_value" + assert response.physical_block_size_bytes == 2663 + assert response.provisioned_iops == 1740 assert response.region == "region_value" assert response.replica_zones == ["replica_zones_value"] assert response.resource_policies == ["resource_policies_value"] assert response.satisfies_pzs is True assert response.self_link == "self_link_value" - assert response.size_gb == "size_gb_value" + assert response.size_gb == 739 assert response.source_disk == "source_disk_value" assert response.source_disk_id == "source_disk_id_value" assert response.source_image == "source_image_value" @@ -944,9 +968,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1048,9 +1073,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1089,7 +1115,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1101,7 +1127,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1125,7 +1151,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1137,7 +1163,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1177,13 +1203,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Disk.to_json( disk_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1273,8 +1300,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1353,7 +1381,7 @@ def test_remove_resource_policies_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1365,7 +1393,7 @@ def test_remove_resource_policies_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1389,7 +1417,7 @@ def test_remove_resource_policies_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1401,7 +1429,7 @@ def test_remove_resource_policies_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1446,14 +1474,15 @@ def test_remove_resource_policies_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.RegionDisksRemoveResourcePoliciesRequest.to_json( region_disks_remove_resource_policies_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_resource_policies_rest_flattened_error(): @@ -1495,7 +1524,7 @@ def test_resize_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1507,7 +1536,7 @@ def test_resize_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1531,7 +1560,7 @@ def test_resize_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1543,7 +1572,7 @@ def test_resize_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1574,7 +1603,7 @@ def test_resize_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. region_disks_resize_request_resource = compute.RegionDisksResizeRequest( - size_gb="size_gb_value" + size_gb=739 ) client.resize( project="project_value", @@ -1588,14 +1617,15 @@ def test_resize_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "disk_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "disk_value" in http_call[1] + str(body) + str(params) assert compute.RegionDisksResizeRequest.to_json( region_disks_resize_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_resize_rest_flattened_error(): @@ -1610,7 +1640,7 @@ def test_resize_rest_flattened_error(): region="region_value", disk="disk_value", region_disks_resize_request_resource=compute.RegionDisksResizeRequest( - size_gb="size_gb_value" + size_gb=739 ), ) @@ -1706,14 +1736,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetPolicyRequest.to_json( region_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1755,7 +1786,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1767,7 +1798,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1791,7 +1822,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1803,7 +1834,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1848,14 +1879,15 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetLabelsRequest.to_json( region_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1942,14 +1974,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_health_check_services.py b/tests/unit/gapic/compute_v1/test_region_health_check_services.py index 40d7ad53c..4b9f049af 100644 --- a/tests/unit/gapic/compute_v1/test_region_health_check_services.py +++ b/tests/unit/gapic/compute_v1/test_region_health_check_services.py @@ -122,6 +122,28 @@ def test_region_health_check_services_client_from_service_account_info(client_cl assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionHealthCheckServicesRestTransport, "rest"),], +) +def test_region_health_check_services_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionHealthCheckServicesClient,]) def test_region_health_check_services_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -453,7 +475,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -465,7 +487,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -489,7 +511,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -501,7 +523,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -544,9 +566,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_service_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -585,7 +608,7 @@ def test_get_rest( fingerprint="fingerprint_value", health_checks=["health_checks_value"], health_status_aggregation_policy=compute.HealthCheckService.HealthStatusAggregationPolicy.AND, - id="id_value", + id=205, kind="kind_value", name="name_value", network_endpoint_groups=["network_endpoint_groups_value"], @@ -612,7 +635,7 @@ def test_get_rest( response.health_status_aggregation_policy == compute.HealthCheckService.HealthStatusAggregationPolicy.AND ) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network_endpoint_groups == ["network_endpoint_groups_value"] @@ -655,9 +678,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_service_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -698,7 +722,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -710,7 +734,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -734,7 +758,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -746,7 +770,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -792,13 +816,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheckService.to_json( health_check_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -898,8 +923,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -989,7 +1015,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1001,7 +1027,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1025,7 +1051,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1037,7 +1063,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1084,14 +1110,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_service_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_service_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheckService.to_json( health_check_service_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_health_checks.py b/tests/unit/gapic/compute_v1/test_region_health_checks.py index 4d1eb1d5b..61b02d822 100644 --- a/tests/unit/gapic/compute_v1/test_region_health_checks.py +++ b/tests/unit/gapic/compute_v1/test_region_health_checks.py @@ -120,6 +120,28 @@ def test_region_health_checks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionHealthChecksRestTransport, "rest"),], +) +def test_region_health_checks_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionHealthChecksClient,]) def test_region_health_checks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -429,7 +451,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -441,7 +463,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -465,7 +487,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -477,7 +499,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -520,9 +542,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -566,7 +589,7 @@ def test_get_rest( http2_health_check=compute.HTTP2HealthCheck(host="host_value"), http_health_check=compute.HTTPHealthCheck(host="host_value"), https_health_check=compute.HTTPSHealthCheck(host="host_value"), - id="id_value", + id=205, kind="kind_value", log_config=compute.HealthCheckLogConfig(enable=True), name="name_value", @@ -599,7 +622,7 @@ def test_get_rest( assert response.http2_health_check == compute.HTTP2HealthCheck(host="host_value") assert response.http_health_check == compute.HTTPHealthCheck(host="host_value") assert response.https_health_check == compute.HTTPSHealthCheck(host="host_value") - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.log_config == compute.HealthCheckLogConfig(enable=True) assert response.name == "name_value" @@ -646,9 +669,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -689,7 +713,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -701,7 +725,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -725,7 +749,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -737,7 +761,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -781,13 +805,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -879,8 +904,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -970,7 +996,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -982,7 +1008,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1006,7 +1032,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1018,7 +1044,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1063,14 +1089,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1112,7 +1139,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1124,7 +1151,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1148,7 +1175,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1160,7 +1187,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1205,14 +1232,15 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "health_check_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "health_check_value" in http_call[1] + str(body) + str(params) assert compute.HealthCheck.to_json( health_check_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py b/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py index f9c68594c..6acebbaaa 100644 --- a/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py +++ b/tests/unit/gapic/compute_v1/test_region_instance_group_managers.py @@ -122,6 +122,28 @@ def test_region_instance_group_managers_client_from_service_account_info(client_ assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionInstanceGroupManagersRestTransport, "rest"),], +) +def test_region_instance_group_managers_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionInstanceGroupManagersClient,]) def test_region_instance_group_managers_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -454,7 +476,7 @@ def test_abandon_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -466,7 +488,7 @@ def test_abandon_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -490,7 +512,7 @@ def test_abandon_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -502,7 +524,7 @@ def test_abandon_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -549,14 +571,15 @@ def test_abandon_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersAbandonInstancesRequest.to_json( region_instance_group_managers_abandon_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_abandon_instances_rest_flattened_error(): @@ -601,7 +624,7 @@ def test_apply_updates_to_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -613,7 +636,7 @@ def test_apply_updates_to_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -637,7 +660,7 @@ def test_apply_updates_to_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -649,7 +672,7 @@ def test_apply_updates_to_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -696,14 +719,15 @@ def test_apply_updates_to_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersApplyUpdatesRequest.to_json( region_instance_group_managers_apply_updates_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_apply_updates_to_instances_rest_flattened_error(): @@ -748,7 +772,7 @@ def test_create_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -760,7 +784,7 @@ def test_create_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -784,7 +808,7 @@ def test_create_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -796,7 +820,7 @@ def test_create_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -843,14 +867,15 @@ def test_create_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersCreateInstancesRequest.to_json( region_instance_group_managers_create_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_create_instances_rest_flattened_error(): @@ -895,7 +920,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -907,7 +932,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -931,7 +956,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -943,7 +968,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -986,9 +1011,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -1030,7 +1056,7 @@ def test_delete_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1042,7 +1068,7 @@ def test_delete_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1066,7 +1092,7 @@ def test_delete_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1078,7 +1104,7 @@ def test_delete_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1125,14 +1151,15 @@ def test_delete_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersDeleteInstancesRequest.to_json( region_instance_group_managers_delete_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_delete_instances_rest_flattened_error(): @@ -1177,7 +1204,7 @@ def test_delete_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1189,7 +1216,7 @@ def test_delete_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1213,7 +1240,7 @@ def test_delete_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1225,7 +1252,7 @@ def test_delete_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1272,14 +1299,15 @@ def test_delete_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagerDeleteInstanceConfigReq.to_json( region_instance_group_manager_delete_instance_config_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_delete_per_instance_configs_rest_flattened_error(): @@ -1329,7 +1357,7 @@ def test_get_rest( target_shape=compute.DistributionPolicy.TargetShape.ANY ), fingerprint="fingerprint_value", - id="id_value", + id=205, instance_group="instance_group_value", instance_template="instance_template_value", kind="kind_value", @@ -1383,7 +1411,7 @@ def test_get_rest( target_shape=compute.DistributionPolicy.TargetShape.ANY ) assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.instance_group == "instance_group_value" assert response.instance_template == "instance_template_value" assert response.kind == "kind_value" @@ -1448,9 +1476,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1492,7 +1521,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1504,7 +1533,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1528,7 +1557,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1540,7 +1569,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1590,13 +1619,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManager.to_json( instance_group_manager_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1710,8 +1740,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1865,9 +1896,10 @@ def test_list_errors_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_errors_rest_flattened_error(): @@ -2024,9 +2056,10 @@ def test_list_managed_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_managed_instances_rest_flattened_error(): @@ -2179,9 +2212,10 @@ def test_list_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) def test_list_per_instance_configs_rest_flattened_error(): @@ -2277,7 +2311,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2289,7 +2323,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2313,7 +2347,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2325,7 +2359,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2376,14 +2410,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.InstanceGroupManager.to_json( instance_group_manager_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -2432,7 +2467,7 @@ def test_patch_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2444,7 +2479,7 @@ def test_patch_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2468,7 +2503,7 @@ def test_patch_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2480,7 +2515,7 @@ def test_patch_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2529,14 +2564,15 @@ def test_patch_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagerPatchInstanceConfigReq.to_json( region_instance_group_manager_patch_instance_config_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_per_instance_configs_rest_flattened_error(): @@ -2583,7 +2619,7 @@ def test_recreate_instances_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2595,7 +2631,7 @@ def test_recreate_instances_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2619,7 +2655,7 @@ def test_recreate_instances_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2631,7 +2667,7 @@ def test_recreate_instances_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2678,14 +2714,15 @@ def test_recreate_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersRecreateRequest.to_json( region_instance_group_managers_recreate_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_recreate_instances_rest_flattened_error(): @@ -2730,7 +2767,7 @@ def test_resize_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2742,7 +2779,7 @@ def test_resize_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2766,7 +2803,7 @@ def test_resize_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2778,7 +2815,7 @@ def test_resize_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2822,10 +2859,11 @@ def test_resize_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) - assert str(443) in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) + assert str(443) in http_call[1] + str(body) + str(params) def test_resize_rest_flattened_error(): @@ -2868,7 +2906,7 @@ def test_set_instance_template_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -2880,7 +2918,7 @@ def test_set_instance_template_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -2904,7 +2942,7 @@ def test_set_instance_template_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -2916,7 +2954,7 @@ def test_set_instance_template_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -2963,14 +3001,15 @@ def test_set_instance_template_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersSetTemplateRequest.to_json( region_instance_group_managers_set_template_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_instance_template_rest_flattened_error(): @@ -3015,7 +3054,7 @@ def test_set_target_pools_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3027,7 +3066,7 @@ def test_set_target_pools_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3051,7 +3090,7 @@ def test_set_target_pools_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3063,7 +3102,7 @@ def test_set_target_pools_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3110,14 +3149,15 @@ def test_set_target_pools_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagersSetTargetPoolsRequest.to_json( region_instance_group_managers_set_target_pools_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_target_pools_rest_flattened_error(): @@ -3162,7 +3202,7 @@ def test_update_per_instance_configs_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -3174,7 +3214,7 @@ def test_update_per_instance_configs_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -3198,7 +3238,7 @@ def test_update_per_instance_configs_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -3210,7 +3250,7 @@ def test_update_per_instance_configs_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -3259,14 +3299,15 @@ def test_update_per_instance_configs_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_manager_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_manager_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupManagerUpdateInstanceConfigReq.to_json( region_instance_group_manager_update_instance_config_req_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_per_instance_configs_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_instance_groups.py b/tests/unit/gapic/compute_v1/test_region_instance_groups.py index 54b92c473..b388ac57c 100644 --- a/tests/unit/gapic/compute_v1/test_region_instance_groups.py +++ b/tests/unit/gapic/compute_v1/test_region_instance_groups.py @@ -120,6 +120,28 @@ def test_region_instance_groups_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionInstanceGroupsRestTransport, "rest"),], +) +def test_region_instance_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionInstanceGroupsClient,]) def test_region_instance_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -443,7 +465,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", named_ports=[compute.NamedPort(name="name_value")], @@ -468,7 +490,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.named_ports == [compute.NamedPort(name="name_value")] @@ -514,9 +536,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -612,8 +635,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -765,14 +789,15 @@ def test_list_instances_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupsListInstancesRequest.to_json( region_instance_groups_list_instances_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_list_instances_rest_flattened_error(): @@ -872,7 +897,7 @@ def test_set_named_ports_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -884,7 +909,7 @@ def test_set_named_ports_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -908,7 +933,7 @@ def test_set_named_ports_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -920,7 +945,7 @@ def test_set_named_ports_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -967,14 +992,15 @@ def test_set_named_ports_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "instance_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "instance_group_value" in http_call[1] + str(body) + str(params) assert compute.RegionInstanceGroupsSetNamedPortsRequest.to_json( region_instance_groups_set_named_ports_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_named_ports_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_instances.py b/tests/unit/gapic/compute_v1/test_region_instances.py index e38868e10..191b8ad93 100644 --- a/tests/unit/gapic/compute_v1/test_region_instances.py +++ b/tests/unit/gapic/compute_v1/test_region_instances.py @@ -116,6 +116,28 @@ def test_region_instances_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionInstancesRestTransport, "rest"),], +) +def test_region_instances_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionInstancesClient,]) def test_region_instances_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -425,7 +447,7 @@ def test_bulk_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -437,7 +459,7 @@ def test_bulk_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -461,7 +483,7 @@ def test_bulk_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -473,7 +495,7 @@ def test_bulk_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -504,7 +526,7 @@ def test_bulk_insert_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. bulk_insert_instance_resource_resource = compute.BulkInsertInstanceResource( - count="count_value" + count=553 ) client.bulk_insert( project="project_value", @@ -517,13 +539,14 @@ def test_bulk_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.BulkInsertInstanceResource.to_json( bulk_insert_instance_resource_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_bulk_insert_rest_flattened_error(): @@ -537,7 +560,7 @@ def test_bulk_insert_rest_flattened_error(): project="project_value", region="region_value", bulk_insert_instance_resource_resource=compute.BulkInsertInstanceResource( - count="count_value" + count=553 ), ) diff --git a/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py b/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py index 099f677e4..89527269d 100644 --- a/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py +++ b/tests/unit/gapic/compute_v1/test_region_network_endpoint_groups.py @@ -122,6 +122,28 @@ def test_region_network_endpoint_groups_client_from_service_account_info(client_ assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionNetworkEndpointGroupsRestTransport, "rest"),], +) +def test_region_network_endpoint_groups_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionNetworkEndpointGroupsClient,]) def test_region_network_endpoint_groups_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -454,7 +476,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -466,7 +488,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -490,7 +512,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -502,7 +524,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -545,9 +567,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -590,7 +613,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", default_port=1289, description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", network="network_value", @@ -625,7 +648,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.default_port == 1289 assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network == "network_value" @@ -674,9 +697,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "network_endpoint_group_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "network_endpoint_group_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -718,7 +742,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -730,7 +754,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -754,7 +778,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -766,7 +790,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -812,13 +836,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.NetworkEndpointGroup.to_json( network_endpoint_group_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -916,8 +941,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py b/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py index 8719081af..fe13f3563 100644 --- a/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py +++ b/tests/unit/gapic/compute_v1/test_region_notification_endpoints.py @@ -122,6 +122,28 @@ def test_region_notification_endpoints_client_from_service_account_info(client_c assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionNotificationEndpointsRestTransport, "rest"),], +) +def test_region_notification_endpoints_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionNotificationEndpointsClient,]) def test_region_notification_endpoints_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -454,7 +476,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -466,7 +488,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -490,7 +512,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -502,7 +524,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -545,9 +567,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "notification_endpoint_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "notification_endpoint_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -586,7 +609,7 @@ def test_get_rest( grpc_settings=compute.NotificationEndpointGrpcSettings( authority="authority_value" ), - id="id_value", + id=205, kind="kind_value", name="name_value", region="region_value", @@ -608,7 +631,7 @@ def test_get_rest( assert response.grpc_settings == compute.NotificationEndpointGrpcSettings( authority="authority_value" ) - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.region == "region_value" @@ -649,9 +672,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "notification_endpoint_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "notification_endpoint_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -693,7 +717,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -705,7 +729,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -729,7 +753,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -741,7 +765,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -787,13 +811,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.NotificationEndpoint.to_json( notification_endpoint_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -893,8 +918,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_operations.py b/tests/unit/gapic/compute_v1/test_region_operations.py index 94ca3699c..ab978f284 100644 --- a/tests/unit/gapic/compute_v1/test_region_operations.py +++ b/tests/unit/gapic/compute_v1/test_region_operations.py @@ -118,6 +118,28 @@ def test_region_operations_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionOperationsRestTransport, "rest"),], +) +def test_region_operations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionOperationsClient,]) def test_region_operations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -463,9 +485,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -504,7 +527,7 @@ def test_get_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -516,7 +539,7 @@ def test_get_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -540,7 +563,7 @@ def test_get_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -552,7 +575,7 @@ def test_get_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -591,9 +614,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -683,8 +707,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -762,7 +787,7 @@ def test_wait_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -774,7 +799,7 @@ def test_wait_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -798,7 +823,7 @@ def test_wait_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -810,7 +835,7 @@ def test_wait_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -849,9 +874,10 @@ def test_wait_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_wait_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py b/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py index a869abde5..f107ffb9b 100644 --- a/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py +++ b/tests/unit/gapic/compute_v1/test_region_ssl_certificates.py @@ -120,6 +120,28 @@ def test_region_ssl_certificates_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionSslCertificatesRestTransport, "rest"),], +) +def test_region_ssl_certificates_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionSslCertificatesClient,]) def test_region_ssl_certificates_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -447,7 +469,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -459,7 +481,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -483,7 +505,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -495,7 +517,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -538,9 +560,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "ssl_certificate_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "ssl_certificate_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -578,7 +601,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", expire_time="expire_time_value", - id="id_value", + id=205, kind="kind_value", managed=compute.SslCertificateManagedSslCertificate( domain_status={"key_value": "value_value"} @@ -608,7 +631,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.expire_time == "expire_time_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.managed == compute.SslCertificateManagedSslCertificate( domain_status={"key_value": "value_value"} @@ -658,9 +681,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "ssl_certificate_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "ssl_certificate_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -701,7 +725,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -713,7 +737,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -737,7 +761,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -749,7 +773,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -795,13 +819,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.SslCertificate.to_json( ssl_certificate_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -895,8 +920,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py b/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py index a5d92bff5..2fc88ebc5 100644 --- a/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py +++ b/tests/unit/gapic/compute_v1/test_region_target_http_proxies.py @@ -120,6 +120,28 @@ def test_region_target_http_proxies_client_from_service_account_info(client_clas assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionTargetHttpProxiesRestTransport, "rest"),], +) +def test_region_target_http_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionTargetHttpProxiesClient,]) def test_region_target_http_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -447,7 +469,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -459,7 +481,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -483,7 +505,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -495,7 +517,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -538,9 +560,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -577,7 +600,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_bind=True, @@ -599,7 +622,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_bind is True @@ -642,9 +665,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -685,7 +709,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -697,7 +721,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -721,7 +745,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -733,7 +757,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -779,13 +803,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpProxy.to_json( target_http_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -883,8 +908,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -974,7 +1000,7 @@ def test_set_url_map_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -986,7 +1012,7 @@ def test_set_url_map_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1010,7 +1036,7 @@ def test_set_url_map_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1022,7 +1048,7 @@ def test_set_url_map_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1067,14 +1093,15 @@ def test_set_url_map_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) assert compute.UrlMapReference.to_json( url_map_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_url_map_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py b/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py index d926deebd..580ad0a38 100644 --- a/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py +++ b/tests/unit/gapic/compute_v1/test_region_target_https_proxies.py @@ -120,6 +120,28 @@ def test_region_target_https_proxies_client_from_service_account_info(client_cla assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.RegionTargetHttpsProxiesRestTransport, "rest"),], +) +def test_region_target_https_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionTargetHttpsProxiesClient,]) def test_region_target_https_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -451,7 +473,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -463,7 +485,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -487,7 +509,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -499,7 +521,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -542,9 +564,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -582,7 +605,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_bind=True, @@ -609,7 +632,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_bind is True @@ -656,9 +679,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -699,7 +723,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -711,7 +735,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -735,7 +759,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -747,7 +771,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -793,13 +817,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpsProxy.to_json( target_https_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -899,8 +924,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -991,7 +1017,7 @@ def test_set_ssl_certificates_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1003,7 +1029,7 @@ def test_set_ssl_certificates_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1027,7 +1053,7 @@ def test_set_ssl_certificates_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1039,7 +1065,7 @@ def test_set_ssl_certificates_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1086,14 +1112,15 @@ def test_set_ssl_certificates_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.RegionTargetHttpsProxiesSetSslCertificatesRequest.to_json( region_target_https_proxies_set_ssl_certificates_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_ssl_certificates_rest_flattened_error(): @@ -1137,7 +1164,7 @@ def test_set_url_map_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1149,7 +1176,7 @@ def test_set_url_map_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1173,7 +1200,7 @@ def test_set_url_map_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1185,7 +1212,7 @@ def test_set_url_map_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1230,14 +1257,15 @@ def test_set_url_map_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.UrlMapReference.to_json( url_map_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_url_map_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_region_url_maps.py b/tests/unit/gapic/compute_v1/test_region_url_maps.py index 6aa557a59..0c2fa29a7 100644 --- a/tests/unit/gapic/compute_v1/test_region_url_maps.py +++ b/tests/unit/gapic/compute_v1/test_region_url_maps.py @@ -117,6 +117,27 @@ def test_region_url_maps_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.RegionUrlMapsRestTransport, "rest"),] +) +def test_region_url_maps_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionUrlMapsClient,]) def test_region_url_maps_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -416,7 +437,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -428,7 +449,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -452,7 +473,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -464,7 +485,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -503,9 +524,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -551,7 +573,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionUrlMapR ] ), host_rules=[compute.HostRule(description="description_value")], - id="id_value", + id=205, kind="kind_value", name="name_value", path_matchers=[ @@ -592,7 +614,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionUrlMapR ] ) assert response.host_rules == [compute.HostRule(description="description_value")] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.path_matchers == [ @@ -637,9 +659,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -678,7 +701,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -690,7 +713,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -714,7 +737,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -726,7 +749,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -768,13 +791,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -866,8 +890,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -945,7 +970,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -957,7 +982,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -981,7 +1006,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -993,7 +1018,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1036,14 +1061,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1085,7 +1111,7 @@ def test_update_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1097,7 +1123,7 @@ def test_update_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1121,7 +1147,7 @@ def test_update_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1133,7 +1159,7 @@ def test_update_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1176,14 +1202,15 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): @@ -1272,14 +1299,15 @@ def test_validate_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.RegionUrlMapsValidateRequest.to_json( region_url_maps_validate_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_validate_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_regions.py b/tests/unit/gapic/compute_v1/test_regions.py index dd53a7bf2..a4bbce669 100644 --- a/tests/unit/gapic/compute_v1/test_regions.py +++ b/tests/unit/gapic/compute_v1/test_regions.py @@ -111,6 +111,25 @@ def test_regions_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.RegionsRestTransport, "rest"),] +) +def test_regions_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RegionsClient,]) def test_regions_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -398,7 +417,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionRequest creation_timestamp="creation_timestamp_value", deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", quotas=[compute.Quota(limit=0.543)], @@ -421,7 +440,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRegionRequest assert response.creation_timestamp == "creation_timestamp_value" assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.quotas == [compute.Quota(limit=0.543)] @@ -461,8 +480,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -545,7 +565,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_reservations.py b/tests/unit/gapic/compute_v1/test_reservations.py index b207a87a6..7996bee17 100644 --- a/tests/unit/gapic/compute_v1/test_reservations.py +++ b/tests/unit/gapic/compute_v1/test_reservations.py @@ -114,6 +114,27 @@ def test_reservations_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.ReservationsRestTransport, "rest"),] +) +def test_reservations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ReservationsClient,]) def test_reservations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -466,7 +487,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -565,7 +587,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -577,7 +599,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -601,7 +623,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -613,7 +635,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -652,9 +674,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "reservation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "reservation_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -687,14 +710,12 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetReservationRe commitment="commitment_value", creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", satisfies_pzs=True, self_link="self_link_value", - specific_reservation=compute.AllocationSpecificSKUReservation( - count="count_value" - ), + specific_reservation=compute.AllocationSpecificSKUReservation(count=553), specific_reservation_required=True, status=compute.Reservation.Status.CREATING, zone="zone_value", @@ -713,13 +734,13 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetReservationRe assert response.commitment == "commitment_value" assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.satisfies_pzs is True assert response.self_link == "self_link_value" assert response.specific_reservation == compute.AllocationSpecificSKUReservation( - count="count_value" + count=553 ) assert response.specific_reservation_required is True assert response.status == compute.Reservation.Status.CREATING @@ -756,9 +777,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "reservation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "reservation_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -860,9 +882,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -901,7 +924,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -913,7 +936,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -937,7 +960,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -949,7 +972,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -991,13 +1014,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.Reservation.to_json( reservation_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1085,8 +1109,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1172,7 +1197,7 @@ def test_resize_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1184,7 +1209,7 @@ def test_resize_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1208,7 +1233,7 @@ def test_resize_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1220,7 +1245,7 @@ def test_resize_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1251,7 +1276,7 @@ def test_resize_rest_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. reservations_resize_request_resource = compute.ReservationsResizeRequest( - specific_sku_count="specific_sku_count_value" + specific_sku_count=1920 ) client.resize( project="project_value", @@ -1265,14 +1290,15 @@ def test_resize_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "reservation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "reservation_value" in http_call[1] + str(body) + str(params) assert compute.ReservationsResizeRequest.to_json( reservations_resize_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_resize_rest_flattened_error(): @@ -1287,7 +1313,7 @@ def test_resize_rest_flattened_error(): zone="zone_value", reservation="reservation_value", reservations_resize_request_resource=compute.ReservationsResizeRequest( - specific_sku_count="specific_sku_count_value" + specific_sku_count=1920 ), ) @@ -1383,14 +1409,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.ZoneSetPolicyRequest.to_json( zone_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1477,14 +1504,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_resource_policies.py b/tests/unit/gapic/compute_v1/test_resource_policies.py index 05b8ed4c3..8831229a6 100644 --- a/tests/unit/gapic/compute_v1/test_resource_policies.py +++ b/tests/unit/gapic/compute_v1/test_resource_policies.py @@ -118,6 +118,28 @@ def test_resource_policies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.ResourcePoliciesRestTransport, "rest"),], +) +def test_resource_policies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ResourcePoliciesClient,]) def test_resource_policies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -492,7 +514,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -594,7 +617,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -606,7 +629,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -630,7 +653,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -642,7 +665,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -683,9 +706,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_policy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -722,7 +746,7 @@ def test_get_rest( group_placement_policy=compute.ResourcePolicyGroupPlacementPolicy( availability_domain_count=2650 ), - id="id_value", + id=205, instance_schedule_policy=compute.ResourcePolicyInstanceSchedulePolicy( expiration_time="expiration_time_value" ), @@ -759,7 +783,7 @@ def test_get_rest( response.group_placement_policy == compute.ResourcePolicyGroupPlacementPolicy(availability_domain_count=2650) ) - assert response.id == "id_value" + assert response.id == 205 assert ( response.instance_schedule_policy == compute.ResourcePolicyInstanceSchedulePolicy( @@ -818,9 +842,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_policy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -922,9 +947,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -963,7 +989,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -975,7 +1001,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -999,7 +1025,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1011,7 +1037,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1055,13 +1081,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.ResourcePolicy.to_json( resource_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1157,8 +1184,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1313,14 +1341,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetPolicyRequest.to_json( region_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1408,14 +1437,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_routers.py b/tests/unit/gapic/compute_v1/test_routers.py index 9d215ccd0..10545aa69 100644 --- a/tests/unit/gapic/compute_v1/test_routers.py +++ b/tests/unit/gapic/compute_v1/test_routers.py @@ -111,6 +111,25 @@ def test_routers_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.RoutersRestTransport, "rest"),] +) +def test_routers_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RoutersClient,]) def test_routers_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -473,7 +492,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -567,7 +587,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouterR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -579,7 +599,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouterR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -603,7 +623,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouterR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -615,7 +635,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouterR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -654,9 +674,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -697,7 +718,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRouterRequest creation_timestamp="creation_timestamp_value", description="description_value", encrypted_interconnect_router=True, - id="id_value", + id=205, interfaces=[compute.RouterInterface(ip_range="ip_range_value")], kind="kind_value", name="name_value", @@ -726,7 +747,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRouterRequest assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.encrypted_interconnect_router is True - assert response.id == "id_value" + assert response.id == 205 assert response.interfaces == [compute.RouterInterface(ip_range="ip_range_value")] assert response.kind == "kind_value" assert response.name == "name_value" @@ -766,9 +787,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -858,9 +880,10 @@ def test_get_nat_mapping_info_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) def test_get_nat_mapping_info_rest_flattened_error(): @@ -997,9 +1020,10 @@ def test_get_router_status_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) def test_get_router_status_rest_flattened_error(): @@ -1036,7 +1060,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouterR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1048,7 +1072,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouterR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1072,7 +1096,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouterR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1084,7 +1108,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouterR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1128,13 +1152,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Router.to_json( router_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1234,8 +1259,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1311,7 +1337,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchRouterReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1323,7 +1349,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchRouterReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1347,7 +1373,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchRouterReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1359,7 +1385,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchRouterReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1404,14 +1430,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) assert compute.Router.to_json( router_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1506,14 +1533,15 @@ def test_preview_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) assert compute.Router.to_json( router_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_preview_rest_flattened_error(): @@ -1555,7 +1583,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateRouterR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1567,7 +1595,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateRouterR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1591,7 +1619,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateRouterR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1603,7 +1631,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateRouterR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1648,14 +1676,15 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "router_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "router_value" in http_call[1] + str(body) + str(params) assert compute.Router.to_json( router_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_routes.py b/tests/unit/gapic/compute_v1/test_routes.py index 98571a88b..aed46e74a 100644 --- a/tests/unit/gapic/compute_v1/test_routes.py +++ b/tests/unit/gapic/compute_v1/test_routes.py @@ -109,6 +109,25 @@ def test_routes_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.RoutesRestTransport, "rest"),] +) +def test_routes_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [RoutesClient,]) def test_routes_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -400,7 +419,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouteRe error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -412,7 +431,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouteRe start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -436,7 +455,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouteRe assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -448,7 +467,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteRouteRe assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -487,8 +506,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "route_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "route_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -518,7 +538,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRouteRequest) creation_timestamp="creation_timestamp_value", description="description_value", dest_range="dest_range_value", - id="id_value", + id=205, kind="kind_value", name="name_value", network="network_value", @@ -548,7 +568,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetRouteRequest) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.dest_range == "dest_range_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network == "network_value" @@ -597,8 +617,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "route_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "route_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -632,7 +653,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouteRe error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -644,7 +665,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouteRe start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -668,7 +689,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouteRe assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -680,7 +701,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertRouteRe assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -720,12 +741,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.Route.to_json( route_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -810,7 +832,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_security_policies.py b/tests/unit/gapic/compute_v1/test_security_policies.py index 620812004..7db7b6e47 100644 --- a/tests/unit/gapic/compute_v1/test_security_policies.py +++ b/tests/unit/gapic/compute_v1/test_security_policies.py @@ -118,6 +118,28 @@ def test_security_policies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.SecurityPoliciesRestTransport, "rest"),], +) +def test_security_policies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [SecurityPoliciesClient,]) def test_security_policies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_add_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_add_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_add_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_add_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -519,13 +541,14 @@ def test_add_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) assert compute.SecurityPolicyRule.to_json( security_policy_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_rule_rest_flattened_error(): @@ -566,7 +589,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -578,7 +601,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -602,7 +625,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -614,7 +637,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -653,8 +676,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -688,7 +712,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", rules=[compute.SecurityPolicyRule(action="action_value")], @@ -708,7 +732,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.rules == [compute.SecurityPolicyRule(action="action_value")] @@ -745,8 +769,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -841,8 +866,9 @@ def test_get_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) def test_get_rule_rest_flattened_error(): @@ -880,7 +906,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -892,7 +918,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -916,7 +942,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -928,7 +954,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -970,12 +996,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.SecurityPolicy.to_json( security_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1064,7 +1091,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1202,7 +1230,8 @@ def test_list_preconfigured_expression_sets_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_preconfigured_expression_sets_rest_flattened_error(): @@ -1239,7 +1268,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1251,7 +1280,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1275,7 +1304,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1287,7 +1316,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1331,13 +1360,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) assert compute.SecurityPolicy.to_json( security_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1378,7 +1408,7 @@ def test_patch_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1390,7 +1420,7 @@ def test_patch_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1414,7 +1444,7 @@ def test_patch_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1426,7 +1456,7 @@ def test_patch_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1470,13 +1500,14 @@ def test_patch_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) assert compute.SecurityPolicyRule.to_json( security_policy_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rule_rest_flattened_error(): @@ -1517,7 +1548,7 @@ def test_remove_rule_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1529,7 +1560,7 @@ def test_remove_rule_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1553,7 +1584,7 @@ def test_remove_rule_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1565,7 +1596,7 @@ def test_remove_rule_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1604,8 +1635,9 @@ def test_remove_rule_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "security_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "security_policy_value" in http_call[1] + str(body) + str(params) def test_remove_rule_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_snapshots.py b/tests/unit/gapic/compute_v1/test_snapshots.py index 7cf38a538..7f9b403e2 100644 --- a/tests/unit/gapic/compute_v1/test_snapshots.py +++ b/tests/unit/gapic/compute_v1/test_snapshots.py @@ -112,6 +112,27 @@ def test_snapshots_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.SnapshotsRestTransport, "rest"),] +) +def test_snapshots_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [SnapshotsClient,]) def test_snapshots_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -405,7 +426,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -417,7 +438,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -441,7 +462,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -453,7 +474,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -492,8 +513,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "snapshot_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "snapshot_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -526,13 +548,13 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSnapshotReque chain_name="chain_name_value", creation_timestamp="creation_timestamp_value", description="description_value", - disk_size_gb="disk_size_gb_value", - download_bytes="download_bytes_value", - id="id_value", + disk_size_gb=1261, + download_bytes=1502, + id=205, kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, - license_codes=["license_codes_value"], + license_codes=[1360], licenses=["licenses_value"], location_hint="location_hint_value", name="name_value", @@ -547,7 +569,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSnapshotReque ), source_disk_id="source_disk_id_value", status=compute.Snapshot.Status.CREATING, - storage_bytes="storage_bytes_value", + storage_bytes=1403, storage_bytes_status=compute.Snapshot.StorageBytesStatus.UPDATING, storage_locations=["storage_locations_value"], ) @@ -566,13 +588,13 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSnapshotReque assert response.chain_name == "chain_name_value" assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.disk_size_gb == "disk_size_gb_value" - assert response.download_bytes == "download_bytes_value" - assert response.id == "id_value" + assert response.disk_size_gb == 1261 + assert response.download_bytes == 1502 + assert response.id == 205 assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} - assert response.license_codes == ["license_codes_value"] + assert response.license_codes == [1360] assert response.licenses == ["licenses_value"] assert response.location_hint == "location_hint_value" assert response.name == "name_value" @@ -587,7 +609,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSnapshotReque ) assert response.source_disk_id == "source_disk_id_value" assert response.status == compute.Snapshot.Status.CREATING - assert response.storage_bytes == "storage_bytes_value" + assert response.storage_bytes == 1403 assert response.storage_bytes_status == compute.Snapshot.StorageBytesStatus.UPDATING assert response.storage_locations == ["storage_locations_value"] @@ -622,8 +644,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "snapshot_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "snapshot_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -724,8 +747,9 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -808,7 +832,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -952,13 +977,14 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetPolicyRequest.to_json( global_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -999,7 +1025,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1011,7 +1037,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1035,7 +1061,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1047,7 +1073,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1091,13 +1117,14 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.GlobalSetLabelsRequest.to_json( global_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1182,13 +1209,14 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_ssl_certificates.py b/tests/unit/gapic/compute_v1/test_ssl_certificates.py index 08064f887..f1673c7e1 100644 --- a/tests/unit/gapic/compute_v1/test_ssl_certificates.py +++ b/tests/unit/gapic/compute_v1/test_ssl_certificates.py @@ -117,6 +117,28 @@ def test_ssl_certificates_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.SslCertificatesRestTransport, "rest"),], +) +def test_ssl_certificates_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [SslCertificatesClient,]) def test_ssl_certificates_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -485,7 +507,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -587,7 +610,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -599,7 +622,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -623,7 +646,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -635,7 +658,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -674,8 +697,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "ssl_certificate_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "ssl_certificate_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -710,7 +734,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", expire_time="expire_time_value", - id="id_value", + id=205, kind="kind_value", managed=compute.SslCertificateManagedSslCertificate( domain_status={"key_value": "value_value"} @@ -740,7 +764,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.expire_time == "expire_time_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.managed == compute.SslCertificateManagedSslCertificate( domain_status={"key_value": "value_value"} @@ -786,8 +810,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "ssl_certificate_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "ssl_certificate_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -825,7 +850,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -837,7 +862,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -861,7 +886,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -873,7 +898,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -915,12 +940,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.SslCertificate.to_json( ssl_certificate_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1007,7 +1033,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_ssl_policies.py b/tests/unit/gapic/compute_v1/test_ssl_policies.py index 08844d4ba..b92d387e0 100644 --- a/tests/unit/gapic/compute_v1/test_ssl_policies.py +++ b/tests/unit/gapic/compute_v1/test_ssl_policies.py @@ -114,6 +114,27 @@ def test_ssl_policies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.SslPoliciesRestTransport, "rest"),] +) +def test_ssl_policies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [SslPoliciesClient,]) def test_ssl_policies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -409,7 +430,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -421,7 +442,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -445,7 +466,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -457,7 +478,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -496,8 +517,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "ssl_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "ssl_policy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -531,7 +553,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSslPolicyRequ description="description_value", enabled_features=["enabled_features_value"], fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", min_tls_version=compute.SslPolicy.MinTlsVersion.TLS_1_0, name="name_value", @@ -555,7 +577,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSslPolicyRequ assert response.description == "description_value" assert response.enabled_features == ["enabled_features_value"] assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.min_tls_version == compute.SslPolicy.MinTlsVersion.TLS_1_0 assert response.name == "name_value" @@ -596,8 +618,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "ssl_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "ssl_policy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -635,7 +658,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -647,7 +670,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -671,7 +694,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -683,7 +706,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -725,12 +748,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.SslPolicy.to_json( ssl_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -819,7 +843,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -939,7 +964,8 @@ def test_list_available_features_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_available_features_rest_flattened_error(): @@ -975,7 +1001,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -987,7 +1013,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1011,7 +1037,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1023,7 +1049,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1067,13 +1093,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "ssl_policy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "ssl_policy_value" in http_call[1] + str(body) + str(params) assert compute.SslPolicy.to_json( ssl_policy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_subnetworks.py b/tests/unit/gapic/compute_v1/test_subnetworks.py index 4ac9a4175..cb7294140 100644 --- a/tests/unit/gapic/compute_v1/test_subnetworks.py +++ b/tests/unit/gapic/compute_v1/test_subnetworks.py @@ -114,6 +114,27 @@ def test_subnetworks_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.SubnetworksRestTransport, "rest"),] +) +def test_subnetworks_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [SubnetworksClient,]) def test_subnetworks_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -472,7 +493,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -571,7 +593,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -583,7 +605,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -607,7 +629,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -619,7 +641,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -660,9 +682,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "subnetwork_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "subnetwork_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -701,7 +724,7 @@ def test_expand_ip_cidr_range_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -713,7 +736,7 @@ def test_expand_ip_cidr_range_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -737,7 +760,7 @@ def test_expand_ip_cidr_range_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -749,7 +772,7 @@ def test_expand_ip_cidr_range_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -794,14 +817,15 @@ def test_expand_ip_cidr_range_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "subnetwork_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "subnetwork_value" in http_call[1] + str(body) + str(params) assert compute.SubnetworksExpandIpCidrRangeRequest.to_json( subnetworks_expand_ip_cidr_range_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_expand_ip_cidr_range_rest_flattened_error(): @@ -839,7 +863,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSubnetworkReq enable_flow_logs=True, fingerprint="fingerprint_value", gateway_address="gateway_address_value", - id="id_value", + id=205, ip_cidr_range="ip_cidr_range_value", ipv6_cidr_range="ipv6_cidr_range_value", kind="kind_value", @@ -875,7 +899,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetSubnetworkReq assert response.enable_flow_logs is True assert response.fingerprint == "fingerprint_value" assert response.gateway_address == "gateway_address_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ip_cidr_range == "ip_cidr_range_value" assert response.ipv6_cidr_range == "ipv6_cidr_range_value" assert response.kind == "kind_value" @@ -931,9 +955,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "subnetwork_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "subnetwork_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1035,9 +1060,10 @@ def test_get_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) def test_get_iam_policy_rest_flattened_error(): @@ -1076,7 +1102,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1088,7 +1114,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1112,7 +1138,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1124,7 +1150,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1168,13 +1194,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.Subnetwork.to_json( subnetwork_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1266,8 +1293,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1406,7 +1434,8 @@ def test_list_usable_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_usable_rest_flattened_error(): @@ -1492,7 +1521,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1504,7 +1533,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1528,7 +1557,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1540,7 +1569,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1585,14 +1614,15 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "subnetwork_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "subnetwork_value" in http_call[1] + str(body) + str(params) assert compute.Subnetwork.to_json( subnetwork_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1703,14 +1733,15 @@ def test_set_iam_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetPolicyRequest.to_json( region_set_policy_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_iam_policy_rest_flattened_error(): @@ -1753,7 +1784,7 @@ def test_set_private_ip_google_access_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1765,7 +1796,7 @@ def test_set_private_ip_google_access_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1789,7 +1820,7 @@ def test_set_private_ip_google_access_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1801,7 +1832,7 @@ def test_set_private_ip_google_access_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1846,14 +1877,15 @@ def test_set_private_ip_google_access_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "subnetwork_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "subnetwork_value" in http_call[1] + str(body) + str(params) assert compute.SubnetworksSetPrivateIpGoogleAccessRequest.to_json( subnetworks_set_private_ip_google_access_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_private_ip_google_access_rest_flattened_error(): @@ -1940,14 +1972,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py b/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py index 8f313530e..1290b6ef8 100644 --- a/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py +++ b/tests/unit/gapic/compute_v1/test_target_grpc_proxies.py @@ -118,6 +118,28 @@ def test_target_grpc_proxies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetGrpcProxiesRestTransport, "rest"),], +) +def test_target_grpc_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetGrpcProxiesClient,]) def test_target_grpc_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -514,8 +536,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_grpc_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_grpc_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -549,7 +572,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", self_link="self_link_value", @@ -571,7 +594,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.self_link == "self_link_value" @@ -610,8 +633,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_grpc_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_grpc_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -649,7 +673,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -661,7 +685,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -685,7 +709,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -697,7 +721,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -740,12 +764,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.TargetGrpcProxy.to_json( target_grpc_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -836,7 +861,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -920,7 +946,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -932,7 +958,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -956,7 +982,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -968,7 +994,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1012,13 +1038,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_grpc_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_grpc_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetGrpcProxy.to_json( target_grpc_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_http_proxies.py b/tests/unit/gapic/compute_v1/test_target_http_proxies.py index 81575216d..932e4a888 100644 --- a/tests/unit/gapic/compute_v1/test_target_http_proxies.py +++ b/tests/unit/gapic/compute_v1/test_target_http_proxies.py @@ -118,6 +118,28 @@ def test_target_http_proxies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetHttpProxiesRestTransport, "rest"),], +) +def test_target_http_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetHttpProxiesClient,]) def test_target_http_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -488,7 +510,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -590,7 +613,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -602,7 +625,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -626,7 +649,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -638,7 +661,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -677,8 +700,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -712,7 +736,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_bind=True, @@ -734,7 +758,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_bind is True @@ -773,8 +797,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -812,7 +837,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -824,7 +849,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -848,7 +873,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -860,7 +885,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -903,12 +928,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpProxy.to_json( target_http_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -999,7 +1025,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1083,7 +1110,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1095,7 +1122,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1119,7 +1146,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1131,7 +1158,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1175,13 +1202,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpProxy.to_json( target_http_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1222,7 +1250,7 @@ def test_set_url_map_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1234,7 +1262,7 @@ def test_set_url_map_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1258,7 +1286,7 @@ def test_set_url_map_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1270,7 +1298,7 @@ def test_set_url_map_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1312,13 +1340,14 @@ def test_set_url_map_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_http_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_http_proxy_value" in http_call[1] + str(body) + str(params) assert compute.UrlMapReference.to_json( url_map_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_url_map_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_https_proxies.py b/tests/unit/gapic/compute_v1/test_target_https_proxies.py index 07c0591de..4cd46442c 100644 --- a/tests/unit/gapic/compute_v1/test_target_https_proxies.py +++ b/tests/unit/gapic/compute_v1/test_target_https_proxies.py @@ -120,6 +120,28 @@ def test_target_https_proxies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetHttpsProxiesRestTransport, "rest"),], +) +def test_target_https_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetHttpsProxiesClient,]) def test_target_https_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -497,7 +519,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -603,7 +626,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -615,7 +638,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -639,7 +662,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -651,7 +674,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -692,8 +715,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -730,7 +754,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", fingerprint="fingerprint_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_bind=True, @@ -757,7 +781,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.fingerprint == "fingerprint_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_bind is True @@ -802,8 +826,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -843,7 +868,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -855,7 +880,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -879,7 +904,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -891,7 +916,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -936,12 +961,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpsProxy.to_json( target_https_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1038,7 +1064,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1126,7 +1153,7 @@ def test_patch_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1138,7 +1165,7 @@ def test_patch_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1162,7 +1189,7 @@ def test_patch_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1174,7 +1201,7 @@ def test_patch_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1220,13 +1247,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpsProxy.to_json( target_https_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1269,7 +1297,7 @@ def test_set_quic_override_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1281,7 +1309,7 @@ def test_set_quic_override_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1305,7 +1333,7 @@ def test_set_quic_override_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1317,7 +1345,7 @@ def test_set_quic_override_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1363,13 +1391,14 @@ def test_set_quic_override_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpsProxiesSetQuicOverrideRequest.to_json( target_https_proxies_set_quic_override_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_quic_override_rest_flattened_error(): @@ -1413,7 +1442,7 @@ def test_set_ssl_certificates_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1425,7 +1454,7 @@ def test_set_ssl_certificates_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1449,7 +1478,7 @@ def test_set_ssl_certificates_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1461,7 +1490,7 @@ def test_set_ssl_certificates_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1507,13 +1536,14 @@ def test_set_ssl_certificates_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetHttpsProxiesSetSslCertificatesRequest.to_json( target_https_proxies_set_ssl_certificates_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_ssl_certificates_rest_flattened_error(): @@ -1556,7 +1586,7 @@ def test_set_ssl_policy_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1568,7 +1598,7 @@ def test_set_ssl_policy_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1592,7 +1622,7 @@ def test_set_ssl_policy_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1604,7 +1634,7 @@ def test_set_ssl_policy_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1650,13 +1680,14 @@ def test_set_ssl_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.SslPolicyReference.to_json( ssl_policy_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_ssl_policy_rest_flattened_error(): @@ -1699,7 +1730,7 @@ def test_set_url_map_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1711,7 +1742,7 @@ def test_set_url_map_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1735,7 +1766,7 @@ def test_set_url_map_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1747,7 +1778,7 @@ def test_set_url_map_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1791,13 +1822,14 @@ def test_set_url_map_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_https_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_https_proxy_value" in http_call[1] + str(body) + str(params) assert compute.UrlMapReference.to_json( url_map_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_url_map_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_instances.py b/tests/unit/gapic/compute_v1/test_target_instances.py index a2b6fd1ba..08451015d 100644 --- a/tests/unit/gapic/compute_v1/test_target_instances.py +++ b/tests/unit/gapic/compute_v1/test_target_instances.py @@ -117,6 +117,28 @@ def test_target_instances_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetInstancesRestTransport, "rest"),], +) +def test_target_instances_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetInstancesClient,]) def test_target_instances_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -489,7 +511,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -591,7 +614,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -603,7 +626,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -627,7 +650,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -639,7 +662,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -680,9 +703,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "target_instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "target_instance_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -716,7 +740,7 @@ def test_get_rest( return_value = compute.TargetInstance( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, instance="instance_value", kind="kind_value", name="name_value", @@ -737,7 +761,7 @@ def test_get_rest( assert isinstance(response, compute.TargetInstance) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.instance == "instance_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -778,9 +802,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "target_instance_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "target_instance_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -819,7 +844,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -831,7 +856,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -855,7 +880,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -867,7 +892,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -911,13 +936,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) assert compute.TargetInstance.to_json( target_instance_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1011,8 +1037,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_pools.py b/tests/unit/gapic/compute_v1/test_target_pools.py index 7a5254ad5..8ece4a9b1 100644 --- a/tests/unit/gapic/compute_v1/test_target_pools.py +++ b/tests/unit/gapic/compute_v1/test_target_pools.py @@ -114,6 +114,27 @@ def test_target_pools_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.TargetPoolsRestTransport, "rest"),] +) +def test_target_pools_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetPoolsClient,]) def test_target_pools_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -409,7 +430,7 @@ def test_add_health_check_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -421,7 +442,7 @@ def test_add_health_check_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -445,7 +466,7 @@ def test_add_health_check_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -457,7 +478,7 @@ def test_add_health_check_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -504,14 +525,15 @@ def test_add_health_check_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.TargetPoolsAddHealthCheckRequest.to_json( target_pools_add_health_check_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_health_check_rest_flattened_error(): @@ -555,7 +577,7 @@ def test_add_instance_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -567,7 +589,7 @@ def test_add_instance_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -591,7 +613,7 @@ def test_add_instance_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -603,7 +625,7 @@ def test_add_instance_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -648,14 +670,15 @@ def test_add_instance_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.TargetPoolsAddInstanceRequest.to_json( target_pools_add_instance_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_add_instance_rest_flattened_error(): @@ -754,7 +777,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -853,7 +877,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -865,7 +889,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -889,7 +913,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -901,7 +925,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -942,9 +966,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -979,7 +1004,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetTargetPoolReq description="description_value", failover_ratio=0.1494, health_checks=["health_checks_value"], - id="id_value", + id=205, instances=["instances_value"], kind="kind_value", name="name_value", @@ -1003,7 +1028,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetTargetPoolReq assert response.description == "description_value" assert math.isclose(response.failover_ratio, 0.1494, rel_tol=1e-6) assert response.health_checks == ["health_checks_value"] - assert response.id == "id_value" + assert response.id == 205 assert response.instances == ["instances_value"] assert response.kind == "kind_value" assert response.name == "name_value" @@ -1044,9 +1069,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -1136,14 +1162,15 @@ def test_get_health_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.InstanceReference.to_json( instance_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_get_health_rest_flattened_error(): @@ -1185,7 +1212,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1197,7 +1224,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1221,7 +1248,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1233,7 +1260,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1275,13 +1302,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.TargetPool.to_json( target_pool_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1369,8 +1397,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1456,7 +1485,7 @@ def test_remove_health_check_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1468,7 +1497,7 @@ def test_remove_health_check_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1492,7 +1521,7 @@ def test_remove_health_check_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1504,7 +1533,7 @@ def test_remove_health_check_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1551,14 +1580,15 @@ def test_remove_health_check_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.TargetPoolsRemoveHealthCheckRequest.to_json( target_pools_remove_health_check_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_health_check_rest_flattened_error(): @@ -1602,7 +1632,7 @@ def test_remove_instance_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1614,7 +1644,7 @@ def test_remove_instance_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1638,7 +1668,7 @@ def test_remove_instance_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1650,7 +1680,7 @@ def test_remove_instance_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1695,14 +1725,15 @@ def test_remove_instance_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.TargetPoolsRemoveInstanceRequest.to_json( target_pools_remove_instance_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_remove_instance_rest_flattened_error(): @@ -1744,7 +1775,7 @@ def test_set_backup_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1756,7 +1787,7 @@ def test_set_backup_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1780,7 +1811,7 @@ def test_set_backup_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1792,7 +1823,7 @@ def test_set_backup_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1835,14 +1866,15 @@ def test_set_backup_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_pool_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_pool_value" in http_call[1] + str(body) + str(params) assert compute.TargetReference.to_json( target_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_backup_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py b/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py index aa4a5ec16..5360adbfb 100644 --- a/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py +++ b/tests/unit/gapic/compute_v1/test_target_ssl_proxies.py @@ -118,6 +118,28 @@ def test_target_ssl_proxies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetSslProxiesRestTransport, "rest"),], +) +def test_target_ssl_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetSslProxiesClient,]) def test_target_ssl_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -514,8 +536,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -548,7 +571,7 @@ def test_get_rest( return_value = compute.TargetSslProxy( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_header=compute.TargetSslProxy.ProxyHeader.NONE, @@ -570,7 +593,7 @@ def test_get_rest( assert isinstance(response, compute.TargetSslProxy) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_header == compute.TargetSslProxy.ProxyHeader.NONE @@ -610,8 +633,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -649,7 +673,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -661,7 +685,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -685,7 +709,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -697,7 +721,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -740,12 +764,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.TargetSslProxy.to_json( target_ssl_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -836,7 +861,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -920,7 +946,7 @@ def test_set_backend_service_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -932,7 +958,7 @@ def test_set_backend_service_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -956,7 +982,7 @@ def test_set_backend_service_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -968,7 +994,7 @@ def test_set_backend_service_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1012,13 +1038,14 @@ def test_set_backend_service_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetSslProxiesSetBackendServiceRequest.to_json( target_ssl_proxies_set_backend_service_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_backend_service_rest_flattened_error(): @@ -1059,7 +1086,7 @@ def test_set_proxy_header_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1071,7 +1098,7 @@ def test_set_proxy_header_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1095,7 +1122,7 @@ def test_set_proxy_header_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1107,7 +1134,7 @@ def test_set_proxy_header_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1151,13 +1178,14 @@ def test_set_proxy_header_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetSslProxiesSetProxyHeaderRequest.to_json( target_ssl_proxies_set_proxy_header_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_proxy_header_rest_flattened_error(): @@ -1199,7 +1227,7 @@ def test_set_ssl_certificates_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1211,7 +1239,7 @@ def test_set_ssl_certificates_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1235,7 +1263,7 @@ def test_set_ssl_certificates_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1247,7 +1275,7 @@ def test_set_ssl_certificates_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1291,13 +1319,14 @@ def test_set_ssl_certificates_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetSslProxiesSetSslCertificatesRequest.to_json( target_ssl_proxies_set_ssl_certificates_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_ssl_certificates_rest_flattened_error(): @@ -1338,7 +1367,7 @@ def test_set_ssl_policy_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1350,7 +1379,7 @@ def test_set_ssl_policy_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1374,7 +1403,7 @@ def test_set_ssl_policy_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1386,7 +1415,7 @@ def test_set_ssl_policy_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1430,13 +1459,14 @@ def test_set_ssl_policy_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_ssl_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_ssl_proxy_value" in http_call[1] + str(body) + str(params) assert compute.SslPolicyReference.to_json( ssl_policy_reference_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_ssl_policy_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py b/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py index 0b5da0d8b..6213882aa 100644 --- a/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py +++ b/tests/unit/gapic/compute_v1/test_target_tcp_proxies.py @@ -118,6 +118,28 @@ def test_target_tcp_proxies_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetTcpProxiesRestTransport, "rest"),], +) +def test_target_tcp_proxies_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetTcpProxiesClient,]) def test_target_tcp_proxies_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -427,7 +449,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -439,7 +461,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -463,7 +485,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -475,7 +497,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -514,8 +536,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_tcp_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_tcp_proxy_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -548,7 +571,7 @@ def test_get_rest( return_value = compute.TargetTcpProxy( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", proxy_bind=True, @@ -569,7 +592,7 @@ def test_get_rest( assert isinstance(response, compute.TargetTcpProxy) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.proxy_bind is True @@ -608,8 +631,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_tcp_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_tcp_proxy_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -647,7 +671,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -659,7 +683,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -683,7 +707,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -695,7 +719,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -738,12 +762,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.TargetTcpProxy.to_json( target_tcp_proxy_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -834,7 +859,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -918,7 +944,7 @@ def test_set_backend_service_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -930,7 +956,7 @@ def test_set_backend_service_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -954,7 +980,7 @@ def test_set_backend_service_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -966,7 +992,7 @@ def test_set_backend_service_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1010,13 +1036,14 @@ def test_set_backend_service_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_tcp_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_tcp_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetTcpProxiesSetBackendServiceRequest.to_json( target_tcp_proxies_set_backend_service_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_backend_service_rest_flattened_error(): @@ -1057,7 +1084,7 @@ def test_set_proxy_header_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1069,7 +1096,7 @@ def test_set_proxy_header_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1093,7 +1120,7 @@ def test_set_proxy_header_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1105,7 +1132,7 @@ def test_set_proxy_header_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1149,13 +1176,14 @@ def test_set_proxy_header_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "target_tcp_proxy_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "target_tcp_proxy_value" in http_call[1] + str(body) + str(params) assert compute.TargetTcpProxiesSetProxyHeaderRequest.to_json( target_tcp_proxies_set_proxy_header_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_proxy_header_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py b/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py index d04398cae..16bbd97aa 100644 --- a/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py +++ b/tests/unit/gapic/compute_v1/test_target_vpn_gateways.py @@ -118,6 +118,28 @@ def test_target_vpn_gateways_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.TargetVpnGatewaysRestTransport, "rest"),], +) +def test_target_vpn_gateways_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [TargetVpnGatewaysClient,]) def test_target_vpn_gateways_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -490,7 +512,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -592,7 +615,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -604,7 +627,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -628,7 +651,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -640,7 +663,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -681,9 +704,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -718,7 +742,7 @@ def test_get_rest( creation_timestamp="creation_timestamp_value", description="description_value", forwarding_rules=["forwarding_rules_value"], - id="id_value", + id=205, kind="kind_value", name="name_value", network="network_value", @@ -741,7 +765,7 @@ def test_get_rest( assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.forwarding_rules == ["forwarding_rules_value"] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.network == "network_value" @@ -783,9 +807,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "target_vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "target_vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -824,7 +849,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -836,7 +861,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -860,7 +885,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -872,7 +897,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -916,13 +941,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.TargetVpnGateway.to_json( target_vpn_gateway_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1016,8 +1042,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_url_maps.py b/tests/unit/gapic/compute_v1/test_url_maps.py index 1cc472f9c..bc45efef0 100644 --- a/tests/unit/gapic/compute_v1/test_url_maps.py +++ b/tests/unit/gapic/compute_v1/test_url_maps.py @@ -111,6 +111,27 @@ def test_url_maps_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.UrlMapsRestTransport, "rest"),] +) +def test_url_maps_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [UrlMapsClient,]) def test_url_maps_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -463,7 +484,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -557,7 +579,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteUrlMapR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -569,7 +591,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteUrlMapR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -593,7 +615,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteUrlMapR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -605,7 +627,7 @@ def test_delete_rest(transport: str = "rest", request_type=compute.DeleteUrlMapR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -644,8 +666,9 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -690,7 +713,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetUrlMapRequest ] ), host_rules=[compute.HostRule(description="description_value")], - id="id_value", + id=205, kind="kind_value", name="name_value", path_matchers=[ @@ -731,7 +754,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetUrlMapRequest ] ) assert response.host_rules == [compute.HostRule(description="description_value")] - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.path_matchers == [ @@ -776,8 +799,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -813,7 +837,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertUrlMapR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -825,7 +849,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertUrlMapR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -849,7 +873,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertUrlMapR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -861,7 +885,7 @@ def test_insert_rest(transport: str = "rest", request_type=compute.InsertUrlMapR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -901,12 +925,13 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -946,7 +971,7 @@ def test_invalidate_cache_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -958,7 +983,7 @@ def test_invalidate_cache_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -982,7 +1007,7 @@ def test_invalidate_cache_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -994,7 +1019,7 @@ def test_invalidate_cache_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1038,13 +1063,14 @@ def test_invalidate_cache_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.CacheInvalidationRule.to_json( cache_invalidation_rule_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_invalidate_cache_rest_flattened_error(): @@ -1132,7 +1158,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1206,7 +1233,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchUrlMapReq error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1218,7 +1245,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchUrlMapReq start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1242,7 +1269,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchUrlMapReq assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1254,7 +1281,7 @@ def test_patch_rest(transport: str = "rest", request_type=compute.PatchUrlMapReq assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1296,13 +1323,14 @@ def test_patch_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_patch_rest_flattened_error(): @@ -1341,7 +1369,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateUrlMapR error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1353,7 +1381,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateUrlMapR start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1377,7 +1405,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateUrlMapR assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1389,7 +1417,7 @@ def test_update_rest(transport: str = "rest", request_type=compute.UpdateUrlMapR assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1431,13 +1459,14 @@ def test_update_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.UrlMap.to_json( url_map_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_update_rest_flattened_error(): @@ -1524,13 +1553,14 @@ def test_validate_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "url_map_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "url_map_value" in http_call[1] + str(body) + str(params) assert compute.UrlMapsValidateRequest.to_json( url_maps_validate_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_validate_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_vpn_gateways.py b/tests/unit/gapic/compute_v1/test_vpn_gateways.py index 05b241ad4..3e6f8de5a 100644 --- a/tests/unit/gapic/compute_v1/test_vpn_gateways.py +++ b/tests/unit/gapic/compute_v1/test_vpn_gateways.py @@ -114,6 +114,27 @@ def test_vpn_gateways_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.VpnGatewaysRestTransport, "rest"),] +) +def test_vpn_gateways_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [VpnGatewaysClient,]) def test_vpn_gateways_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -472,7 +493,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -571,7 +593,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -583,7 +605,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -607,7 +629,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -619,7 +641,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -660,9 +682,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -694,7 +717,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetVpnGatewayReq return_value = compute.VpnGateway( creation_timestamp="creation_timestamp_value", description="description_value", - id="id_value", + id=205, kind="kind_value", label_fingerprint="label_fingerprint_value", labels={"key_value": "value_value"}, @@ -717,7 +740,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetVpnGatewayReq assert isinstance(response, compute.VpnGateway) assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.label_fingerprint == "label_fingerprint_value" assert response.labels == {"key_value": "value_value"} @@ -760,9 +783,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -854,9 +878,10 @@ def test_get_status_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "vpn_gateway_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "vpn_gateway_value" in http_call[1] + str(body) + str(params) def test_get_status_rest_flattened_error(): @@ -895,7 +920,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -907,7 +932,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -931,7 +956,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -943,7 +968,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -987,13 +1012,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.VpnGateway.to_json( vpn_gateway_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1085,8 +1111,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -1172,7 +1199,7 @@ def test_set_labels_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -1184,7 +1211,7 @@ def test_set_labels_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -1208,7 +1235,7 @@ def test_set_labels_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -1220,7 +1247,7 @@ def test_set_labels_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -1265,14 +1292,15 @@ def test_set_labels_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.RegionSetLabelsRequest.to_json( region_set_labels_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_set_labels_rest_flattened_error(): @@ -1359,14 +1387,15 @@ def test_test_iam_permissions_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "resource_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "resource_value" in http_call[1] + str(body) + str(params) assert compute.TestPermissionsRequest.to_json( test_permissions_request_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_test_iam_permissions_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_vpn_tunnels.py b/tests/unit/gapic/compute_v1/test_vpn_tunnels.py index 1e8687427..07634e266 100644 --- a/tests/unit/gapic/compute_v1/test_vpn_tunnels.py +++ b/tests/unit/gapic/compute_v1/test_vpn_tunnels.py @@ -114,6 +114,27 @@ def test_vpn_tunnels_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.VpnTunnelsRestTransport, "rest"),] +) +def test_vpn_tunnels_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [VpnTunnelsClient,]) def test_vpn_tunnels_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -470,7 +491,8 @@ def test_aggregated_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_aggregated_list_rest_flattened_error(): @@ -566,7 +588,7 @@ def test_delete_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -578,7 +600,7 @@ def test_delete_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -602,7 +624,7 @@ def test_delete_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -614,7 +636,7 @@ def test_delete_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -655,9 +677,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "vpn_tunnel_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "vpn_tunnel_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -690,7 +713,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetVpnTunnelRequ creation_timestamp="creation_timestamp_value", description="description_value", detailed_status="detailed_status_value", - id="id_value", + id=205, ike_version=1182, kind="kind_value", local_traffic_selector=["local_traffic_selector_value"], @@ -724,7 +747,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetVpnTunnelRequ assert response.creation_timestamp == "creation_timestamp_value" assert response.description == "description_value" assert response.detailed_status == "detailed_status_value" - assert response.id == "id_value" + assert response.id == 205 assert response.ike_version == 1182 assert response.kind == "kind_value" assert response.local_traffic_selector == ["local_traffic_selector_value"] @@ -777,9 +800,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) - assert "vpn_tunnel_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) + assert "vpn_tunnel_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -818,7 +842,7 @@ def test_insert_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -830,7 +854,7 @@ def test_insert_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -854,7 +878,7 @@ def test_insert_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -866,7 +890,7 @@ def test_insert_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -910,13 +934,14 @@ def test_insert_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) assert compute.VpnTunnel.to_json( vpn_tunnel_resource, including_default_value_fields=False, use_integers_for_enums=False, - ) in http_call[1] + str(body) + ) in http_call[1] + str(body) + str(params) def test_insert_rest_flattened_error(): @@ -1006,8 +1031,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "region_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "region_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_zone_operations.py b/tests/unit/gapic/compute_v1/test_zone_operations.py index d37181c35..478c71c38 100644 --- a/tests/unit/gapic/compute_v1/test_zone_operations.py +++ b/tests/unit/gapic/compute_v1/test_zone_operations.py @@ -117,6 +117,28 @@ def test_zone_operations_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", + [(transports.ZoneOperationsRestTransport, "rest"),], +) +def test_zone_operations_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ZoneOperationsClient,]) def test_zone_operations_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -452,9 +474,10 @@ def test_delete_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_delete_rest_flattened_error(): @@ -493,7 +516,7 @@ def test_get_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -505,7 +528,7 @@ def test_get_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -529,7 +552,7 @@ def test_get_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -541,7 +564,7 @@ def test_get_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -580,9 +603,10 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -672,8 +696,9 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error(): @@ -751,7 +776,7 @@ def test_wait_rest( error=compute.Error(errors=[compute.Errors(code="code_value")]), http_error_message="http_error_message_value", http_error_status_code=2374, - id="id_value", + id=205, insert_time="insert_time_value", kind="kind_value", name="name_value", @@ -763,7 +788,7 @@ def test_wait_rest( start_time="start_time_value", status=compute.Operation.Status.DONE, status_message="status_message_value", - target_id="target_id_value", + target_id=947, target_link="target_link_value", user="user_value", warnings=[compute.Warnings(code=compute.Warnings.Code.CLEANUP_FAILED)], @@ -787,7 +812,7 @@ def test_wait_rest( assert response.error == compute.Error(errors=[compute.Errors(code="code_value")]) assert response.http_error_message == "http_error_message_value" assert response.http_error_status_code == 2374 - assert response.id == "id_value" + assert response.id == 205 assert response.insert_time == "insert_time_value" assert response.kind == "kind_value" assert response.name == "name_value" @@ -799,7 +824,7 @@ def test_wait_rest( assert response.start_time == "start_time_value" assert response.status == compute.Operation.Status.DONE assert response.status_message == "status_message_value" - assert response.target_id == "target_id_value" + assert response.target_id == 947 assert response.target_link == "target_link_value" assert response.user == "user_value" assert response.warnings == [ @@ -838,9 +863,10 @@ def test_wait_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) - assert "operation_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) + assert "operation_value" in http_call[1] + str(body) + str(params) def test_wait_rest_flattened_error(): diff --git a/tests/unit/gapic/compute_v1/test_zones.py b/tests/unit/gapic/compute_v1/test_zones.py index 9f513c918..db3ca996b 100644 --- a/tests/unit/gapic/compute_v1/test_zones.py +++ b/tests/unit/gapic/compute_v1/test_zones.py @@ -109,6 +109,25 @@ def test_zones_client_from_service_account_info(client_class): assert client.transport._host == "compute.googleapis.com:443" +@pytest.mark.parametrize( + "transport_class,transport_name", [(transports.ZonesRestTransport, "rest"),] +) +def test_zones_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + @pytest.mark.parametrize("client_class", [ZonesClient,]) def test_zones_client_from_service_account_file(client_class): creds = ga_credentials.AnonymousCredentials() @@ -397,7 +416,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetZoneRequest): creation_timestamp="creation_timestamp_value", deprecated=compute.DeprecationStatus(deleted="deleted_value"), description="description_value", - id="id_value", + id=205, kind="kind_value", name="name_value", region="region_value", @@ -420,7 +439,7 @@ def test_get_rest(transport: str = "rest", request_type=compute.GetZoneRequest): assert response.creation_timestamp == "creation_timestamp_value" assert response.deprecated == compute.DeprecationStatus(deleted="deleted_value") assert response.description == "description_value" - assert response.id == "id_value" + assert response.id == 205 assert response.kind == "kind_value" assert response.name == "name_value" assert response.region == "region_value" @@ -459,8 +478,9 @@ def test_get_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) - assert "zone_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) + assert "zone_value" in http_call[1] + str(body) + str(params) def test_get_rest_flattened_error(): @@ -545,7 +565,8 @@ def test_list_rest_flattened(): assert len(req.mock_calls) == 1 _, http_call, http_params = req.mock_calls[0] body = http_params.get("data") - assert "project_value" in http_call[1] + str(body) + params = http_params.get("params") + assert "project_value" in http_call[1] + str(body) + str(params) def test_list_rest_flattened_error():