def test_import_ssh_public_key(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = oslogin_pb2.ImportSshPublicKeyResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = oslogin_v1.OsLoginServiceClient()

        # Setup Request
        parent = client.user_path("[USER]")
        ssh_public_key = {}

        response = client.import_ssh_public_key(parent, ssh_public_key)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = oslogin_pb2.ImportSshPublicKeyRequest(
            parent=parent, ssh_public_key=ssh_public_key)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def import_ssh_public_key(self,
                              parent,
                              ssh_public_key,
                              project_id=None,
                              retry=google.api_core.gapic_v1.method.DEFAULT,
                              timeout=google.api_core.gapic_v1.method.DEFAULT,
                              metadata=None):
        """
        Adds an SSH public key and returns the profile information. Default POSIX
        account information is set when no username and UID exist as part of the
        login profile.

        Example:
            >>> from google.cloud import oslogin_v1
            >>>
            >>> client = oslogin_v1.OsLoginServiceClient()
            >>>
            >>> parent = client.user_path('[USER]')
            >>> ssh_public_key = {}
            >>>
            >>> response = client.import_ssh_public_key(parent, ssh_public_key)

        Args:
            parent (str): The unique ID for the user in format ``users/{user}``.
            ssh_public_key (Union[dict, ~google.cloud.oslogin_v1.types.SshPublicKey]): The SSH public key and expiration time.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.oslogin_v1.types.SshPublicKey`
            project_id (str): The project ID of the Google Cloud Platform project.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        request = oslogin_pb2.ImportSshPublicKeyRequest(
            parent=parent,
            ssh_public_key=ssh_public_key,
            project_id=project_id,
        )
        return self._import_ssh_public_key(request,
                                           retry=retry,
                                           timeout=timeout,
                                           metadata=metadata)
    def test_import_ssh_public_key(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = oslogin_pb2.ImportSshPublicKeyResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = oslogin_v1.OsLoginServiceClient(channel=channel)

        # Setup Request
        parent = client.user_path('[USER]')
        ssh_public_key = {}

        response = client.import_ssh_public_key(parent, ssh_public_key)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = oslogin_pb2.ImportSshPublicKeyRequest(
            parent=parent, ssh_public_key=ssh_public_key)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #4
0
    def import_ssh_public_key(
        self,
        parent,
        ssh_public_key=None,
        project_id=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Adds an SSH public key and returns the profile information. Default POSIX
        account information is set when no username and UID exist as part of the
        login profile.

        Example:
            >>> from google.cloud import oslogin_v1
            >>>
            >>> client = oslogin_v1.OsLoginServiceClient()
            >>>
            >>> parent = client.user_path('[USER]')
            >>>
            >>> response = client.import_ssh_public_key(parent)

        Args:
            parent (str): Required. The unique ID for the user in format ``users/{user}``.
            ssh_public_key (Union[dict, ~google.cloud.oslogin_v1.types.SshPublicKey]): Optional. The SSH public key and expiration time.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.oslogin_v1.types.SshPublicKey`
            project_id (str): The project ID of the Google Cloud Platform project.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will
                be retried using a default configuration.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.oslogin_v1.types.ImportSshPublicKeyResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "import_ssh_public_key" not in self._inner_api_calls:
            self._inner_api_calls[
                "import_ssh_public_key"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.import_ssh_public_key,
                    default_retry=self._method_configs["ImportSshPublicKey"].
                    retry,
                    default_timeout=self._method_configs["ImportSshPublicKey"].
                    timeout,
                    client_info=self._client_info,
                )

        request = oslogin_pb2.ImportSshPublicKeyRequest(
            parent=parent,
            ssh_public_key=ssh_public_key,
            project_id=project_id)
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("parent", parent)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        return self._inner_api_calls["import_ssh_public_key"](
            request, retry=retry, timeout=timeout, metadata=metadata)