diff --git a/CHANGELOG.md b/CHANGELOG.md index af93fa8..b71717b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ [1]: https://pypi.org/project/google-cloud-redis/#history +## [2.8.0](https://github.com/googleapis/python-redis/compare/v2.7.1...v2.8.0) (2022-03-15) + + +### Features + +* add secondary_ip_range field ([d08e3b5](https://github.com/googleapis/python-redis/commit/d08e3b5c7c6c635b7dc7277b0a455b088e94dd19)) +* add support for AUTH functionality ([d08e3b5](https://github.com/googleapis/python-redis/commit/d08e3b5c7c6c635b7dc7277b0a455b088e94dd19)) +* add support for TLS functionality ([d08e3b5](https://github.com/googleapis/python-redis/commit/d08e3b5c7c6c635b7dc7277b0a455b088e94dd19)) +* add Support Maintenance Window ([#172](https://github.com/googleapis/python-redis/issues/172)) ([d08e3b5](https://github.com/googleapis/python-redis/commit/d08e3b5c7c6c635b7dc7277b0a455b088e94dd19)) + ### [2.7.1](https://github.com/googleapis/python-redis/compare/v2.7.0...v2.7.1) (2022-03-05) diff --git a/google/cloud/redis/__init__.py b/google/cloud/redis/__init__.py index 97b18e0..ab063e6 100644 --- a/google/cloud/redis/__init__.py +++ b/google/cloud/redis/__init__.py @@ -25,18 +25,25 @@ from google.cloud.redis_v1.types.cloud_redis import FailoverInstanceRequest from google.cloud.redis_v1.types.cloud_redis import GcsDestination from google.cloud.redis_v1.types.cloud_redis import GcsSource +from google.cloud.redis_v1.types.cloud_redis import GetInstanceAuthStringRequest from google.cloud.redis_v1.types.cloud_redis import GetInstanceRequest from google.cloud.redis_v1.types.cloud_redis import ImportInstanceRequest from google.cloud.redis_v1.types.cloud_redis import InputConfig from google.cloud.redis_v1.types.cloud_redis import Instance +from google.cloud.redis_v1.types.cloud_redis import InstanceAuthString from google.cloud.redis_v1.types.cloud_redis import ListInstancesRequest from google.cloud.redis_v1.types.cloud_redis import ListInstancesResponse from google.cloud.redis_v1.types.cloud_redis import LocationMetadata +from google.cloud.redis_v1.types.cloud_redis import MaintenancePolicy +from google.cloud.redis_v1.types.cloud_redis import MaintenanceSchedule from google.cloud.redis_v1.types.cloud_redis import NodeInfo from google.cloud.redis_v1.types.cloud_redis import OperationMetadata from google.cloud.redis_v1.types.cloud_redis import OutputConfig +from google.cloud.redis_v1.types.cloud_redis import RescheduleMaintenanceRequest +from google.cloud.redis_v1.types.cloud_redis import TlsCertificate from google.cloud.redis_v1.types.cloud_redis import UpdateInstanceRequest from google.cloud.redis_v1.types.cloud_redis import UpgradeInstanceRequest +from google.cloud.redis_v1.types.cloud_redis import WeeklyMaintenanceWindow from google.cloud.redis_v1.types.cloud_redis import ZoneMetadata __all__ = ( @@ -48,17 +55,24 @@ "FailoverInstanceRequest", "GcsDestination", "GcsSource", + "GetInstanceAuthStringRequest", "GetInstanceRequest", "ImportInstanceRequest", "InputConfig", "Instance", + "InstanceAuthString", "ListInstancesRequest", "ListInstancesResponse", "LocationMetadata", + "MaintenancePolicy", + "MaintenanceSchedule", "NodeInfo", "OperationMetadata", "OutputConfig", + "RescheduleMaintenanceRequest", + "TlsCertificate", "UpdateInstanceRequest", "UpgradeInstanceRequest", + "WeeklyMaintenanceWindow", "ZoneMetadata", ) diff --git a/google/cloud/redis_v1/__init__.py b/google/cloud/redis_v1/__init__.py index 37dd59c..da4acd5 100644 --- a/google/cloud/redis_v1/__init__.py +++ b/google/cloud/redis_v1/__init__.py @@ -23,18 +23,25 @@ from .types.cloud_redis import FailoverInstanceRequest from .types.cloud_redis import GcsDestination from .types.cloud_redis import GcsSource +from .types.cloud_redis import GetInstanceAuthStringRequest from .types.cloud_redis import GetInstanceRequest from .types.cloud_redis import ImportInstanceRequest from .types.cloud_redis import InputConfig from .types.cloud_redis import Instance +from .types.cloud_redis import InstanceAuthString from .types.cloud_redis import ListInstancesRequest from .types.cloud_redis import ListInstancesResponse from .types.cloud_redis import LocationMetadata +from .types.cloud_redis import MaintenancePolicy +from .types.cloud_redis import MaintenanceSchedule from .types.cloud_redis import NodeInfo from .types.cloud_redis import OperationMetadata from .types.cloud_redis import OutputConfig +from .types.cloud_redis import RescheduleMaintenanceRequest +from .types.cloud_redis import TlsCertificate from .types.cloud_redis import UpdateInstanceRequest from .types.cloud_redis import UpgradeInstanceRequest +from .types.cloud_redis import WeeklyMaintenanceWindow from .types.cloud_redis import ZoneMetadata __all__ = ( @@ -46,17 +53,24 @@ "FailoverInstanceRequest", "GcsDestination", "GcsSource", + "GetInstanceAuthStringRequest", "GetInstanceRequest", "ImportInstanceRequest", "InputConfig", "Instance", + "InstanceAuthString", "ListInstancesRequest", "ListInstancesResponse", "LocationMetadata", + "MaintenancePolicy", + "MaintenanceSchedule", "NodeInfo", "OperationMetadata", "OutputConfig", + "RescheduleMaintenanceRequest", + "TlsCertificate", "UpdateInstanceRequest", "UpgradeInstanceRequest", + "WeeklyMaintenanceWindow", "ZoneMetadata", ) diff --git a/google/cloud/redis_v1/gapic_metadata.json b/google/cloud/redis_v1/gapic_metadata.json index 038bb99..3a1f492 100644 --- a/google/cloud/redis_v1/gapic_metadata.json +++ b/google/cloud/redis_v1/gapic_metadata.json @@ -35,6 +35,11 @@ "get_instance" ] }, + "GetInstanceAuthString": { + "methods": [ + "get_instance_auth_string" + ] + }, "ImportInstance": { "methods": [ "import_instance" @@ -45,6 +50,11 @@ "list_instances" ] }, + "RescheduleMaintenance": { + "methods": [ + "reschedule_maintenance" + ] + }, "UpdateInstance": { "methods": [ "update_instance" @@ -85,6 +95,11 @@ "get_instance" ] }, + "GetInstanceAuthString": { + "methods": [ + "get_instance_auth_string" + ] + }, "ImportInstance": { "methods": [ "import_instance" @@ -95,6 +110,11 @@ "list_instances" ] }, + "RescheduleMaintenance": { + "methods": [ + "reschedule_maintenance" + ] + }, "UpdateInstance": { "methods": [ "update_instance" diff --git a/google/cloud/redis_v1/services/cloud_redis/async_client.py b/google/cloud/redis_v1/services/cloud_redis/async_client.py index 0421746..d5e9982 100644 --- a/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -384,7 +384,7 @@ def sample_get_instance(): Returns: google.cloud.redis_v1.types.Instance: - A Google Cloud Redis instance. + A Memorystore for Redis instance. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -423,6 +423,99 @@ def sample_get_instance(): # Done; return the response. return response + async def get_instance_auth_string( + self, + request: Union[cloud_redis.GetInstanceAuthStringRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_redis.InstanceAuthString: + r"""Gets the AUTH string for a Redis instance. If AUTH is + not enabled for the instance the response will be empty. + This information is not included in the details returned + to GetInstance. + + + .. code-block:: python + + from google.cloud import redis_v1 + + def sample_get_instance_auth_string(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.GetInstanceAuthStringRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_auth_string(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.redis_v1.types.GetInstanceAuthStringRequest, dict]): + The request object. Request for + [GetInstanceAuthString][google.cloud.redis.v1.CloudRedis.GetInstanceAuthString]. + name (:class:`str`): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.redis_v1.types.InstanceAuthString: + Instance AUTH string details. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = cloud_redis.GetInstanceAuthStringRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_instance_auth_string, + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def create_instance( self, request: Union[cloud_redis.CreateInstanceRequest, dict] = None, @@ -523,8 +616,8 @@ def sample_create_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -659,8 +752,8 @@ def sample_update_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -780,8 +873,8 @@ def sample_upgrade_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -909,8 +1002,8 @@ def sample_import_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1034,8 +1127,8 @@ def sample_export_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1154,8 +1247,8 @@ def sample_failover_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1323,6 +1416,136 @@ def sample_delete_instance(): # Done; return the response. return response + async def reschedule_maintenance( + self, + request: Union[cloud_redis.RescheduleMaintenanceRequest, dict] = None, + *, + name: str = None, + reschedule_type: cloud_redis.RescheduleMaintenanceRequest.RescheduleType = None, + schedule_time: timestamp_pb2.Timestamp = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Reschedule maintenance for a given instance in a + given project and location. + + + .. code-block:: python + + from google.cloud import redis_v1 + + def sample_reschedule_maintenance(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.RescheduleMaintenanceRequest( + name="name_value", + reschedule_type="SPECIFIC_TIME", + ) + + # Make the request + operation = client.reschedule_maintenance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.redis_v1.types.RescheduleMaintenanceRequest, dict]): + The request object. Request for + [RescheduleMaintenance][google.cloud.redis.v1.CloudRedis.RescheduleMaintenance]. + name (:class:`str`): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reschedule_type (:class:`google.cloud.redis_v1.types.RescheduleMaintenanceRequest.RescheduleType`): + Required. If reschedule type is SPECIFIC_TIME, must set + up schedule_time as well. + + This corresponds to the ``reschedule_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + schedule_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): + Optional. Timestamp when the maintenance shall be + rescheduled to if reschedule_type=SPECIFIC_TIME, in RFC + 3339 format, for example ``2012-11-15T16:19:00.094Z``. + + This corresponds to the ``schedule_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, reschedule_type, schedule_time]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = cloud_redis.RescheduleMaintenanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if reschedule_type is not None: + request.reschedule_type = reschedule_type + if schedule_time is not None: + request.schedule_time = schedule_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.reschedule_maintenance, + default_timeout=600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + cloud_redis.Instance, + metadata_type=cloud_redis.OperationMetadata, + ) + + # Done; return the response. + return response + async def __aenter__(self): return self diff --git a/google/cloud/redis_v1/services/cloud_redis/client.py b/google/cloud/redis_v1/services/cloud_redis/client.py index 019d882..9175adf 100644 --- a/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/google/cloud/redis_v1/services/cloud_redis/client.py @@ -585,7 +585,7 @@ def sample_get_instance(): Returns: google.cloud.redis_v1.types.Instance: - A Google Cloud Redis instance. + A Memorystore for Redis instance. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have @@ -624,6 +624,99 @@ def sample_get_instance(): # Done; return the response. return response + def get_instance_auth_string( + self, + request: Union[cloud_redis.GetInstanceAuthStringRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> cloud_redis.InstanceAuthString: + r"""Gets the AUTH string for a Redis instance. If AUTH is + not enabled for the instance the response will be empty. + This information is not included in the details returned + to GetInstance. + + + .. code-block:: python + + from google.cloud import redis_v1 + + def sample_get_instance_auth_string(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.GetInstanceAuthStringRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_auth_string(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.redis_v1.types.GetInstanceAuthStringRequest, dict]): + The request object. Request for + [GetInstanceAuthString][google.cloud.redis.v1.CloudRedis.GetInstanceAuthString]. + name (str): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.redis_v1.types.InstanceAuthString: + Instance AUTH string details. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a cloud_redis.GetInstanceAuthStringRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_redis.GetInstanceAuthStringRequest): + request = cloud_redis.GetInstanceAuthStringRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_instance_auth_string] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def create_instance( self, request: Union[cloud_redis.CreateInstanceRequest, dict] = None, @@ -724,8 +817,8 @@ def sample_create_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -860,8 +953,8 @@ def sample_update_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -981,8 +1074,8 @@ def sample_upgrade_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1110,8 +1203,8 @@ def sample_import_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1235,8 +1328,8 @@ def sample_export_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1355,8 +1448,8 @@ def sample_failover_instance(): An object representing a long-running operation. The result type for the operation will be - :class:`google.cloud.redis_v1.types.Instance` A Google - Cloud Redis instance. + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. """ # Create or coerce a protobuf request object. @@ -1524,6 +1617,136 @@ def sample_delete_instance(): # Done; return the response. return response + def reschedule_maintenance( + self, + request: Union[cloud_redis.RescheduleMaintenanceRequest, dict] = None, + *, + name: str = None, + reschedule_type: cloud_redis.RescheduleMaintenanceRequest.RescheduleType = None, + schedule_time: timestamp_pb2.Timestamp = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Reschedule maintenance for a given instance in a + given project and location. + + + .. code-block:: python + + from google.cloud import redis_v1 + + def sample_reschedule_maintenance(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.RescheduleMaintenanceRequest( + name="name_value", + reschedule_type="SPECIFIC_TIME", + ) + + # Make the request + operation = client.reschedule_maintenance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.redis_v1.types.RescheduleMaintenanceRequest, dict]): + The request object. Request for + [RescheduleMaintenance][google.cloud.redis.v1.CloudRedis.RescheduleMaintenance]. + name (str): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reschedule_type (google.cloud.redis_v1.types.RescheduleMaintenanceRequest.RescheduleType): + Required. If reschedule type is SPECIFIC_TIME, must set + up schedule_time as well. + + This corresponds to the ``reschedule_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + schedule_time (google.protobuf.timestamp_pb2.Timestamp): + Optional. Timestamp when the maintenance shall be + rescheduled to if reschedule_type=SPECIFIC_TIME, in RFC + 3339 format, for example ``2012-11-15T16:19:00.094Z``. + + This corresponds to the ``schedule_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.redis_v1.types.Instance` A + Memorystore for Redis instance. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, reschedule_type, schedule_time]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a cloud_redis.RescheduleMaintenanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, cloud_redis.RescheduleMaintenanceRequest): + request = cloud_redis.RescheduleMaintenanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if reschedule_type is not None: + request.reschedule_type = reschedule_type + if schedule_time is not None: + request.schedule_time = schedule_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.reschedule_maintenance] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + cloud_redis.Instance, + metadata_type=cloud_redis.OperationMetadata, + ) + + # Done; return the response. + return response + def __enter__(self): return self diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/base.py b/google/cloud/redis_v1/services/cloud_redis/transports/base.py index b800d99..f76bb6f 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/base.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/base.py @@ -126,6 +126,11 @@ def _prep_wrapped_messages(self, client_info): self.get_instance: gapic_v1.method.wrap_method( self.get_instance, default_timeout=600.0, client_info=client_info, ), + self.get_instance_auth_string: gapic_v1.method.wrap_method( + self.get_instance_auth_string, + default_timeout=600.0, + client_info=client_info, + ), self.create_instance: gapic_v1.method.wrap_method( self.create_instance, default_timeout=600.0, client_info=client_info, ), @@ -147,6 +152,11 @@ def _prep_wrapped_messages(self, client_info): self.delete_instance: gapic_v1.method.wrap_method( self.delete_instance, default_timeout=600.0, client_info=client_info, ), + self.reschedule_maintenance: gapic_v1.method.wrap_method( + self.reschedule_maintenance, + default_timeout=600.0, + client_info=client_info, + ), } def close(self): @@ -184,6 +194,17 @@ def get_instance( ]: raise NotImplementedError() + @property + def get_instance_auth_string( + self, + ) -> Callable[ + [cloud_redis.GetInstanceAuthStringRequest], + Union[ + cloud_redis.InstanceAuthString, Awaitable[cloud_redis.InstanceAuthString] + ], + ]: + raise NotImplementedError() + @property def create_instance( self, @@ -247,5 +268,14 @@ def delete_instance( ]: raise NotImplementedError() + @property + def reschedule_maintenance( + self, + ) -> Callable[ + [cloud_redis.RescheduleMaintenanceRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + __all__ = ("CloudRedisTransport",) diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index ade6e11..6479abd 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -328,6 +328,37 @@ def get_instance( ) return self._stubs["get_instance"] + @property + def get_instance_auth_string( + self, + ) -> Callable[ + [cloud_redis.GetInstanceAuthStringRequest], cloud_redis.InstanceAuthString + ]: + r"""Return a callable for the get instance auth string method over gRPC. + + Gets the AUTH string for a Redis instance. If AUTH is + not enabled for the instance the response will be empty. + This information is not included in the details returned + to GetInstance. + + Returns: + Callable[[~.GetInstanceAuthStringRequest], + ~.InstanceAuthString]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_instance_auth_string" not in self._stubs: + self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + "/google.cloud.redis.v1.CloudRedis/GetInstanceAuthString", + request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, + response_deserializer=cloud_redis.InstanceAuthString.deserialize, + ) + return self._stubs["get_instance_auth_string"] + @property def create_instance( self, @@ -544,6 +575,33 @@ def delete_instance( ) return self._stubs["delete_instance"] + @property + def reschedule_maintenance( + self, + ) -> Callable[[cloud_redis.RescheduleMaintenanceRequest], operations_pb2.Operation]: + r"""Return a callable for the reschedule maintenance method over gRPC. + + Reschedule maintenance for a given instance in a + given project and location. + + Returns: + Callable[[~.RescheduleMaintenanceRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "reschedule_maintenance" not in self._stubs: + self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + "/google.cloud.redis.v1.CloudRedis/RescheduleMaintenance", + request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["reschedule_maintenance"] + def close(self): self.grpc_channel.close() diff --git a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index 0ad80df..dec34dd 100644 --- a/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -332,6 +332,38 @@ def get_instance( ) return self._stubs["get_instance"] + @property + def get_instance_auth_string( + self, + ) -> Callable[ + [cloud_redis.GetInstanceAuthStringRequest], + Awaitable[cloud_redis.InstanceAuthString], + ]: + r"""Return a callable for the get instance auth string method over gRPC. + + Gets the AUTH string for a Redis instance. If AUTH is + not enabled for the instance the response will be empty. + This information is not included in the details returned + to GetInstance. + + Returns: + Callable[[~.GetInstanceAuthStringRequest], + Awaitable[~.InstanceAuthString]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_instance_auth_string" not in self._stubs: + self._stubs["get_instance_auth_string"] = self.grpc_channel.unary_unary( + "/google.cloud.redis.v1.CloudRedis/GetInstanceAuthString", + request_serializer=cloud_redis.GetInstanceAuthStringRequest.serialize, + response_deserializer=cloud_redis.InstanceAuthString.deserialize, + ) + return self._stubs["get_instance_auth_string"] + @property def create_instance( self, @@ -562,6 +594,35 @@ def delete_instance( ) return self._stubs["delete_instance"] + @property + def reschedule_maintenance( + self, + ) -> Callable[ + [cloud_redis.RescheduleMaintenanceRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the reschedule maintenance method over gRPC. + + Reschedule maintenance for a given instance in a + given project and location. + + Returns: + Callable[[~.RescheduleMaintenanceRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "reschedule_maintenance" not in self._stubs: + self._stubs["reschedule_maintenance"] = self.grpc_channel.unary_unary( + "/google.cloud.redis.v1.CloudRedis/RescheduleMaintenance", + request_serializer=cloud_redis.RescheduleMaintenanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["reschedule_maintenance"] + def close(self): return self.grpc_channel.close() diff --git a/google/cloud/redis_v1/types/__init__.py b/google/cloud/redis_v1/types/__init__.py index 0e38cdf..08aa65b 100644 --- a/google/cloud/redis_v1/types/__init__.py +++ b/google/cloud/redis_v1/types/__init__.py @@ -20,18 +20,25 @@ FailoverInstanceRequest, GcsDestination, GcsSource, + GetInstanceAuthStringRequest, GetInstanceRequest, ImportInstanceRequest, InputConfig, Instance, + InstanceAuthString, ListInstancesRequest, ListInstancesResponse, LocationMetadata, + MaintenancePolicy, + MaintenanceSchedule, NodeInfo, OperationMetadata, OutputConfig, + RescheduleMaintenanceRequest, + TlsCertificate, UpdateInstanceRequest, UpgradeInstanceRequest, + WeeklyMaintenanceWindow, ZoneMetadata, ) @@ -42,17 +49,24 @@ "FailoverInstanceRequest", "GcsDestination", "GcsSource", + "GetInstanceAuthStringRequest", "GetInstanceRequest", "ImportInstanceRequest", "InputConfig", "Instance", + "InstanceAuthString", "ListInstancesRequest", "ListInstancesResponse", "LocationMetadata", + "MaintenancePolicy", + "MaintenanceSchedule", "NodeInfo", "OperationMetadata", "OutputConfig", + "RescheduleMaintenanceRequest", + "TlsCertificate", "UpdateInstanceRequest", "UpgradeInstanceRequest", + "WeeklyMaintenanceWindow", "ZoneMetadata", ) diff --git a/google/cloud/redis_v1/types/cloud_redis.py b/google/cloud/redis_v1/types/cloud_redis.py index 9d796fb..ba5cb4f 100644 --- a/google/cloud/redis_v1/types/cloud_redis.py +++ b/google/cloud/redis_v1/types/cloud_redis.py @@ -15,8 +15,11 @@ # import proto # type: ignore +from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore +from google.type import dayofweek_pb2 # type: ignore +from google.type import timeofday_pb2 # type: ignore __protobuf__ = proto.module( @@ -24,9 +27,15 @@ manifest={ "NodeInfo", "Instance", + "RescheduleMaintenanceRequest", + "MaintenancePolicy", + "WeeklyMaintenanceWindow", + "MaintenanceSchedule", "ListInstancesRequest", "ListInstancesResponse", "GetInstanceRequest", + "GetInstanceAuthStringRequest", + "InstanceAuthString", "CreateInstanceRequest", "UpdateInstanceRequest", "UpgradeInstanceRequest", @@ -41,6 +50,7 @@ "OperationMetadata", "LocationMetadata", "ZoneMetadata", + "TlsCertificate", }, ) @@ -61,7 +71,7 @@ class NodeInfo(proto.Message): class Instance(proto.Message): - r"""A Google Cloud Redis instance. + r"""A Memorystore for Redis instance. Attributes: name (str): @@ -119,6 +129,13 @@ class Instance(proto.Message): provided, the service will choose an unused /29 block, for example, 10.0.0.0/29 or 192.168.0.0/29. For READ_REPLICAS_ENABLED the default block size is /28. + secondary_ip_range (str): + Optional. Additional IP range for node placement. Required + when enabling read replicas on an existing instance. For + DIRECT_PEERING mode value must be a CIDR range of size /28, + or "auto". For PRIVATE_SERVICE_ACCESS mode value must be the + name of an allocated address range associated with the + private service access connection, or "auto". host (str): Output only. Hostname or IP address of the exposed Redis endpoint used by clients to @@ -179,10 +196,32 @@ class Instance(proto.Message): connect_mode (google.cloud.redis_v1.types.Instance.ConnectMode): Optional. The network connect mode of the Redis instance. If not provided, the connect mode defaults to DIRECT_PEERING. + auth_enabled (bool): + Optional. Indicates whether OSS Redis AUTH is + enabled for the instance. If set to "true" AUTH + is enabled on the instance. Default value is + "false" meaning AUTH is disabled. + server_ca_certs (Sequence[google.cloud.redis_v1.types.TlsCertificate]): + Output only. List of server CA certificates + for the instance. + transit_encryption_mode (google.cloud.redis_v1.types.Instance.TransitEncryptionMode): + Optional. The TLS mode of the Redis instance. + If not provided, TLS is disabled for the + instance. + maintenance_policy (google.cloud.redis_v1.types.MaintenancePolicy): + Optional. The maintenance policy for the + instance. If not provided, maintenance events + can be performed at any time. + maintenance_schedule (google.cloud.redis_v1.types.MaintenanceSchedule): + Output only. Date and time of upcoming + maintenance events which have been scheduled. replica_count (int): - Optional. The number of replica nodes. Valid range for - standard tier is [1-5] and defaults to 1. Valid value for - basic tier is 0 and defaults to 0. + Optional. The number of replica nodes. The valid range for + the Standard Tier with read replicas enabled is [1-5] and + defaults to 2. If read replicas are not enabled for a + Standard Tier instance, the only valid value is 1 and the + default is 1. The valid value for basic tier is 0 and the + default is also 0. nodes (Sequence[google.cloud.redis_v1.types.NodeInfo]): Output only. Info per node. read_endpoint (str): @@ -197,7 +236,8 @@ class Instance(proto.Message): readonly redis endpoint. Standard tier only. Write requests should target 'port'. read_replicas_mode (google.cloud.redis_v1.types.Instance.ReadReplicasMode): - Optional. Read replica mode. + Optional. Read replicas mode for the instance. Defaults to + READ_REPLICAS_DISABLED. """ class State(proto.Enum): @@ -224,6 +264,12 @@ class ConnectMode(proto.Enum): DIRECT_PEERING = 1 PRIVATE_SERVICE_ACCESS = 2 + class TransitEncryptionMode(proto.Enum): + r"""Available TLS modes.""" + TRANSIT_ENCRYPTION_MODE_UNSPECIFIED = 0 + SERVER_AUTHENTICATION = 1 + DISABLED = 2 + class ReadReplicasMode(proto.Enum): r"""Read replicas mode.""" READ_REPLICAS_MODE_UNSPECIFIED = 0 @@ -237,6 +283,7 @@ class ReadReplicasMode(proto.Enum): alternative_location_id = proto.Field(proto.STRING, number=5,) redis_version = proto.Field(proto.STRING, number=7,) reserved_ip_range = proto.Field(proto.STRING, number=9,) + secondary_ip_range = proto.Field(proto.STRING, number=30,) host = proto.Field(proto.STRING, number=10,) port = proto.Field(proto.INT32, number=11,) current_location_id = proto.Field(proto.STRING, number=12,) @@ -251,6 +298,19 @@ class ReadReplicasMode(proto.Enum): authorized_network = proto.Field(proto.STRING, number=20,) persistence_iam_identity = proto.Field(proto.STRING, number=21,) connect_mode = proto.Field(proto.ENUM, number=22, enum=ConnectMode,) + auth_enabled = proto.Field(proto.BOOL, number=23,) + server_ca_certs = proto.RepeatedField( + proto.MESSAGE, number=25, message="TlsCertificate", + ) + transit_encryption_mode = proto.Field( + proto.ENUM, number=26, enum=TransitEncryptionMode, + ) + maintenance_policy = proto.Field( + proto.MESSAGE, number=27, message="MaintenancePolicy", + ) + maintenance_schedule = proto.Field( + proto.MESSAGE, number=28, message="MaintenanceSchedule", + ) replica_count = proto.Field(proto.INT32, number=31,) nodes = proto.RepeatedField(proto.MESSAGE, number=32, message="NodeInfo",) read_endpoint = proto.Field(proto.STRING, number=33,) @@ -258,6 +318,115 @@ class ReadReplicasMode(proto.Enum): read_replicas_mode = proto.Field(proto.ENUM, number=35, enum=ReadReplicasMode,) +class RescheduleMaintenanceRequest(proto.Message): + r"""Request for + [RescheduleMaintenance][google.cloud.redis.v1.CloudRedis.RescheduleMaintenance]. + + Attributes: + name (str): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + reschedule_type (google.cloud.redis_v1.types.RescheduleMaintenanceRequest.RescheduleType): + Required. If reschedule type is SPECIFIC_TIME, must set up + schedule_time as well. + schedule_time (google.protobuf.timestamp_pb2.Timestamp): + Optional. Timestamp when the maintenance shall be + rescheduled to if reschedule_type=SPECIFIC_TIME, in RFC 3339 + format, for example ``2012-11-15T16:19:00.094Z``. + """ + + class RescheduleType(proto.Enum): + r"""Reschedule options.""" + RESCHEDULE_TYPE_UNSPECIFIED = 0 + IMMEDIATE = 1 + NEXT_AVAILABLE_WINDOW = 2 + SPECIFIC_TIME = 3 + + name = proto.Field(proto.STRING, number=1,) + reschedule_type = proto.Field(proto.ENUM, number=2, enum=RescheduleType,) + schedule_time = proto.Field( + proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + ) + + +class MaintenancePolicy(proto.Message): + r"""Maintenance policy for an instance. + + Attributes: + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when the policy was + created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when the policy was + last updated. + description (str): + Optional. Description of what this policy is for. + Create/Update methods return INVALID_ARGUMENT if the length + is greater than 512. + weekly_maintenance_window (Sequence[google.cloud.redis_v1.types.WeeklyMaintenanceWindow]): + Optional. Maintenance window that is applied to resources + covered by this policy. Minimum 1. For the current version, + the maximum number of weekly_window is expected to be one. + """ + + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + description = proto.Field(proto.STRING, number=3,) + weekly_maintenance_window = proto.RepeatedField( + proto.MESSAGE, number=4, message="WeeklyMaintenanceWindow", + ) + + +class WeeklyMaintenanceWindow(proto.Message): + r"""Time window in which disruptive maintenance updates occur. + Non-disruptive updates can occur inside or outside this window. + + Attributes: + day (google.type.dayofweek_pb2.DayOfWeek): + Required. The day of week that maintenance + updates occur. + start_time (google.type.timeofday_pb2.TimeOfDay): + Required. Start time of the window in UTC + time. + duration (google.protobuf.duration_pb2.Duration): + Output only. Duration of the maintenance + window. The current window is fixed at 1 hour. + """ + + day = proto.Field(proto.ENUM, number=1, enum=dayofweek_pb2.DayOfWeek,) + start_time = proto.Field(proto.MESSAGE, number=2, message=timeofday_pb2.TimeOfDay,) + duration = proto.Field(proto.MESSAGE, number=3, message=duration_pb2.Duration,) + + +class MaintenanceSchedule(proto.Message): + r"""Upcoming maintenance schedule. If no maintenance is + scheduled, fields are not populated. + + Attributes: + start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The start time of any upcoming + scheduled maintenance for this instance. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The end time of any upcoming + scheduled maintenance for this instance. + can_reschedule (bool): + If the scheduled maintenance can be + rescheduled, default is true. + schedule_deadline_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The deadline that the + maintenance schedule start time can not go + beyond, including reschedule. + """ + + start_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + can_reschedule = proto.Field(proto.BOOL, number=3,) + schedule_deadline_time = proto.Field( + proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, + ) + + class ListInstancesRequest(proto.Message): r"""Request for [ListInstances][google.cloud.redis.v1.CloudRedis.ListInstances]. @@ -336,6 +505,31 @@ class GetInstanceRequest(proto.Message): name = proto.Field(proto.STRING, number=1,) +class GetInstanceAuthStringRequest(proto.Message): + r"""Request for + [GetInstanceAuthString][google.cloud.redis.v1.CloudRedis.GetInstanceAuthString]. + + Attributes: + name (str): + Required. Redis instance resource name using the form: + ``projects/{project_id}/locations/{location_id}/instances/{instance_id}`` + where ``location_id`` refers to a GCP region. + """ + + name = proto.Field(proto.STRING, number=1,) + + +class InstanceAuthString(proto.Message): + r"""Instance AUTH string details. + + Attributes: + auth_string (str): + AUTH string set on the instance. + """ + + auth_string = proto.Field(proto.STRING, number=1,) + + class CreateInstanceRequest(proto.Message): r"""Request for [CreateInstance][google.cloud.redis.v1.CloudRedis.CreateInstance]. @@ -602,4 +796,32 @@ class ZoneMetadata(proto.Message): """ +class TlsCertificate(proto.Message): + r"""TlsCertificate Resource + + Attributes: + serial_number (str): + Serial number, as extracted from the + certificate. + cert (str): + PEM representation. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when the certificate was created in + `RFC 3339 `__ format, + for example ``2020-05-18T00:00:00.094Z``. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time when the certificate expires in `RFC + 3339 `__ format, for + example ``2020-05-18T00:00:00.094Z``. + sha1_fingerprint (str): + Sha1 Fingerprint of the certificate. + """ + + serial_number = proto.Field(proto.STRING, number=1,) + cert = proto.Field(proto.STRING, number=2,) + create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + expire_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + sha1_fingerprint = proto.Field(proto.STRING, number=5,) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_async.py b/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_async.py new file mode 100644 index 0000000..26973ab --- /dev/null +++ b/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceAuthString +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-redis + + +# [START redis_v1_generated_CloudRedis_GetInstanceAuthString_async] +from google.cloud import redis_v1 + + +async def sample_get_instance_auth_string(): + # Create a client + client = redis_v1.CloudRedisAsyncClient() + + # Initialize request argument(s) + request = redis_v1.GetInstanceAuthStringRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance_auth_string(request=request) + + # Handle the response + print(response) + +# [END redis_v1_generated_CloudRedis_GetInstanceAuthString_async] diff --git a/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_sync.py b/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_sync.py new file mode 100644 index 0000000..e69b442 --- /dev/null +++ b/samples/generated_samples/redis_v1_generated_cloud_redis_get_instance_auth_string_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceAuthString +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-redis + + +# [START redis_v1_generated_CloudRedis_GetInstanceAuthString_sync] +from google.cloud import redis_v1 + + +def sample_get_instance_auth_string(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.GetInstanceAuthStringRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_auth_string(request=request) + + # Handle the response + print(response) + +# [END redis_v1_generated_CloudRedis_GetInstanceAuthString_sync] diff --git a/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_async.py b/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_async.py new file mode 100644 index 0000000..4ed38d0 --- /dev/null +++ b/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RescheduleMaintenance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-redis + + +# [START redis_v1_generated_CloudRedis_RescheduleMaintenance_async] +from google.cloud import redis_v1 + + +async def sample_reschedule_maintenance(): + # Create a client + client = redis_v1.CloudRedisAsyncClient() + + # Initialize request argument(s) + request = redis_v1.RescheduleMaintenanceRequest( + name="name_value", + reschedule_type="SPECIFIC_TIME", + ) + + # Make the request + operation = client.reschedule_maintenance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END redis_v1_generated_CloudRedis_RescheduleMaintenance_async] diff --git a/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_sync.py b/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_sync.py new file mode 100644 index 0000000..270eff4 --- /dev/null +++ b/samples/generated_samples/redis_v1_generated_cloud_redis_reschedule_maintenance_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RescheduleMaintenance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-redis + + +# [START redis_v1_generated_CloudRedis_RescheduleMaintenance_sync] +from google.cloud import redis_v1 + + +def sample_reschedule_maintenance(): + # Create a client + client = redis_v1.CloudRedisClient() + + # Initialize request argument(s) + request = redis_v1.RescheduleMaintenanceRequest( + name="name_value", + reschedule_type="SPECIFIC_TIME", + ) + + # Make the request + operation = client.reschedule_maintenance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END redis_v1_generated_CloudRedis_RescheduleMaintenance_sync] diff --git a/samples/generated_samples/snippet_metadata_redis_v1.json b/samples/generated_samples/snippet_metadata_redis_v1.json index 1718e17..096fdb4 100644 --- a/samples/generated_samples/snippet_metadata_redis_v1.json +++ b/samples/generated_samples/snippet_metadata_redis_v1.json @@ -356,6 +356,95 @@ } ] }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudRedis" + }, + "shortName": "GetInstanceAuthString" + } + }, + "file": "redis_v1_generated_cloud_redis_get_instance_auth_string_async.py", + "regionTag": "redis_v1_generated_CloudRedis_GetInstanceAuthString_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudRedis" + }, + "shortName": "GetInstanceAuthString" + } + }, + "file": "redis_v1_generated_cloud_redis_get_instance_auth_string_sync.py", + "regionTag": "redis_v1_generated_CloudRedis_GetInstanceAuthString_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, { "clientMethod": { "async": true, @@ -623,6 +712,95 @@ } ] }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "CloudRedis" + }, + "shortName": "RescheduleMaintenance" + } + }, + "file": "redis_v1_generated_cloud_redis_reschedule_maintenance_async.py", + "regionTag": "redis_v1_generated_CloudRedis_RescheduleMaintenance_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "CloudRedis" + }, + "shortName": "RescheduleMaintenance" + } + }, + "file": "redis_v1_generated_cloud_redis_reschedule_maintenance_sync.py", + "regionTag": "redis_v1_generated_CloudRedis_RescheduleMaintenance_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, { "clientMethod": { "async": true, diff --git a/scripts/fixup_redis_v1_keywords.py b/scripts/fixup_redis_v1_keywords.py index 6df6945..506da0c 100644 --- a/scripts/fixup_redis_v1_keywords.py +++ b/scripts/fixup_redis_v1_keywords.py @@ -44,8 +44,10 @@ class redisCallTransformer(cst.CSTTransformer): 'export_instance': ('name', 'output_config', ), 'failover_instance': ('name', 'data_protection_mode', ), 'get_instance': ('name', ), + 'get_instance_auth_string': ('name', ), 'import_instance': ('name', 'input_config', ), 'list_instances': ('parent', 'page_size', 'page_token', ), + 'reschedule_maintenance': ('name', 'reschedule_type', 'schedule_time', ), 'update_instance': ('update_mask', 'instance', ), 'upgrade_instance': ('name', 'redis_version', ), } diff --git a/setup.py b/setup.py index 5ed3adf..a676d5f 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-redis" description = "Google Cloud Memorystore for Redis API client library" -version = "2.7.1" +version = "2.8.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta' diff --git a/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/unit/gapic/redis_v1/test_cloud_redis.py index c5fffc2..34a2e6b 100644 --- a/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -42,8 +42,11 @@ from google.cloud.redis_v1.types import cloud_redis from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore +from google.type import dayofweek_pb2 # type: ignore +from google.type import timeofday_pb2 # type: ignore import google.auth @@ -975,6 +978,7 @@ def test_get_instance(request_type, transport: str = "grpc"): alternative_location_id="alternative_location_id_value", redis_version="redis_version_value", reserved_ip_range="reserved_ip_range_value", + secondary_ip_range="secondary_ip_range_value", host="host_value", port=453, current_location_id="current_location_id_value", @@ -985,6 +989,8 @@ def test_get_instance(request_type, transport: str = "grpc"): authorized_network="authorized_network_value", persistence_iam_identity="persistence_iam_identity_value", connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, + auth_enabled=True, + transit_encryption_mode=cloud_redis.Instance.TransitEncryptionMode.SERVER_AUTHENTICATION, replica_count=1384, read_endpoint="read_endpoint_value", read_endpoint_port=1920, @@ -1005,6 +1011,7 @@ def test_get_instance(request_type, transport: str = "grpc"): assert response.alternative_location_id == "alternative_location_id_value" assert response.redis_version == "redis_version_value" assert response.reserved_ip_range == "reserved_ip_range_value" + assert response.secondary_ip_range == "secondary_ip_range_value" assert response.host == "host_value" assert response.port == 453 assert response.current_location_id == "current_location_id_value" @@ -1015,6 +1022,11 @@ def test_get_instance(request_type, transport: str = "grpc"): assert response.authorized_network == "authorized_network_value" assert response.persistence_iam_identity == "persistence_iam_identity_value" assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING + assert response.auth_enabled is True + assert ( + response.transit_encryption_mode + == cloud_redis.Instance.TransitEncryptionMode.SERVER_AUTHENTICATION + ) assert response.replica_count == 1384 assert response.read_endpoint == "read_endpoint_value" assert response.read_endpoint_port == 1920 @@ -1062,6 +1074,7 @@ async def test_get_instance_async( alternative_location_id="alternative_location_id_value", redis_version="redis_version_value", reserved_ip_range="reserved_ip_range_value", + secondary_ip_range="secondary_ip_range_value", host="host_value", port=453, current_location_id="current_location_id_value", @@ -1072,6 +1085,8 @@ async def test_get_instance_async( authorized_network="authorized_network_value", persistence_iam_identity="persistence_iam_identity_value", connect_mode=cloud_redis.Instance.ConnectMode.DIRECT_PEERING, + auth_enabled=True, + transit_encryption_mode=cloud_redis.Instance.TransitEncryptionMode.SERVER_AUTHENTICATION, replica_count=1384, read_endpoint="read_endpoint_value", read_endpoint_port=1920, @@ -1093,6 +1108,7 @@ async def test_get_instance_async( assert response.alternative_location_id == "alternative_location_id_value" assert response.redis_version == "redis_version_value" assert response.reserved_ip_range == "reserved_ip_range_value" + assert response.secondary_ip_range == "secondary_ip_range_value" assert response.host == "host_value" assert response.port == 453 assert response.current_location_id == "current_location_id_value" @@ -1103,6 +1119,11 @@ async def test_get_instance_async( assert response.authorized_network == "authorized_network_value" assert response.persistence_iam_identity == "persistence_iam_identity_value" assert response.connect_mode == cloud_redis.Instance.ConnectMode.DIRECT_PEERING + assert response.auth_enabled is True + assert ( + response.transit_encryption_mode + == cloud_redis.Instance.TransitEncryptionMode.SERVER_AUTHENTICATION + ) assert response.replica_count == 1384 assert response.read_endpoint == "read_endpoint_value" assert response.read_endpoint_port == 1920 @@ -1236,6 +1257,220 @@ async def test_get_instance_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", [cloud_redis.GetInstanceAuthStringRequest, dict,] +) +def test_get_instance_auth_string(request_type, transport: str = "grpc"): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_redis.InstanceAuthString( + auth_string="auth_string_value", + ) + response = client.get_instance_auth_string(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.GetInstanceAuthStringRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, cloud_redis.InstanceAuthString) + assert response.auth_string == "auth_string_value" + + +def test_get_instance_auth_string_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + client.get_instance_auth_string() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.GetInstanceAuthStringRequest() + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_async( + transport: str = "grpc_asyncio", + request_type=cloud_redis.GetInstanceAuthStringRequest, +): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_redis.InstanceAuthString(auth_string="auth_string_value",) + ) + response = await client.get_instance_auth_string(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.GetInstanceAuthStringRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, cloud_redis.InstanceAuthString) + assert response.auth_string == "auth_string_value" + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_async_from_dict(): + await test_get_instance_auth_string_async(request_type=dict) + + +def test_get_instance_auth_string_field_headers(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceAuthStringRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + call.return_value = cloud_redis.InstanceAuthString() + client.get_instance_auth_string(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_field_headers_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.GetInstanceAuthStringRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_redis.InstanceAuthString() + ) + await client.get_instance_auth_string(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_get_instance_auth_string_flattened(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_redis.InstanceAuthString() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_instance_auth_string(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_instance_auth_string_flattened_error(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance_auth_string( + cloud_redis.GetInstanceAuthStringRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_flattened_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_auth_string), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = cloud_redis.InstanceAuthString() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cloud_redis.InstanceAuthString() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_instance_auth_string(name="name_value",) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_instance_auth_string_flattened_error_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_instance_auth_string( + cloud_redis.GetInstanceAuthStringRequest(), name="name_value", + ) + + @pytest.mark.parametrize("request_type", [cloud_redis.CreateInstanceRequest, dict,]) def test_create_instance(request_type, transport: str = "grpc"): client = CloudRedisClient( @@ -2737,6 +2972,242 @@ async def test_delete_instance_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", [cloud_redis.RescheduleMaintenanceRequest, dict,] +) +def test_reschedule_maintenance(request_type, transport: str = "grpc"): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.reschedule_maintenance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.RescheduleMaintenanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_reschedule_maintenance_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + client.reschedule_maintenance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.RescheduleMaintenanceRequest() + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_async( + transport: str = "grpc_asyncio", + request_type=cloud_redis.RescheduleMaintenanceRequest, +): + client = CloudRedisAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.reschedule_maintenance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == cloud_redis.RescheduleMaintenanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_async_from_dict(): + await test_reschedule_maintenance_async(request_type=dict) + + +def test_reschedule_maintenance_field_headers(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.RescheduleMaintenanceRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.reschedule_maintenance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_field_headers_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = cloud_redis.RescheduleMaintenanceRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.reschedule_maintenance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + + +def test_reschedule_maintenance_flattened(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.reschedule_maintenance( + name="name_value", + reschedule_type=cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE, + schedule_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].reschedule_type + mock_val = cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE + assert arg == mock_val + assert TimestampRule().to_proto( + args[0].schedule_time + ) == timestamp_pb2.Timestamp(seconds=751) + + +def test_reschedule_maintenance_flattened_error(): + client = CloudRedisClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.reschedule_maintenance( + cloud_redis.RescheduleMaintenanceRequest(), + name="name_value", + reschedule_type=cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE, + schedule_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_flattened_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.reschedule_maintenance), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.reschedule_maintenance( + name="name_value", + reschedule_type=cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE, + schedule_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].reschedule_type + mock_val = cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE + assert arg == mock_val + assert TimestampRule().to_proto( + args[0].schedule_time + ) == timestamp_pb2.Timestamp(seconds=751) + + +@pytest.mark.asyncio +async def test_reschedule_maintenance_flattened_error_async(): + client = CloudRedisAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.reschedule_maintenance( + cloud_redis.RescheduleMaintenanceRequest(), + name="name_value", + reschedule_type=cloud_redis.RescheduleMaintenanceRequest.RescheduleType.IMMEDIATE, + schedule_time=timestamp_pb2.Timestamp(seconds=751), + ) + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudRedisGrpcTransport( @@ -2850,6 +3321,7 @@ def test_cloud_redis_base_transport(): methods = ( "list_instances", "get_instance", + "get_instance_auth_string", "create_instance", "update_instance", "upgrade_instance", @@ -2857,6 +3329,7 @@ def test_cloud_redis_base_transport(): "export_instance", "failover_instance", "delete_instance", + "reschedule_maintenance", ) for method in methods: with pytest.raises(NotImplementedError):