From f537079d2a0c36354e2fcd018ed21a3827e70bda Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 18 Jan 2024 14:43:34 -0500 Subject: [PATCH] SDK updates for streaming changes (now works!) --- client/securedrop_client/sdk/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/client/securedrop_client/sdk/__init__.py b/client/securedrop_client/sdk/__init__.py index 276f4b3717..35e00980e9 100644 --- a/client/securedrop_client/sdk/__init__.py +++ b/client/securedrop_client/sdk/__init__.py @@ -166,20 +166,16 @@ def _send_json_request( if timeout: data["timeout"] = timeout - data_str = json.dumps(data) - print(data_str) + data_str = json.dumps(data).encode() try: env = {} if self.development_mode: env["SD_PROXY_ORIGIN"] = self.server - print(self._rpc_target()) response = subprocess.run( [self._rpc_target()], capture_output=True, timeout=timeout, input=data_str, env=env ) - print('here') except subprocess.TimeoutExpired as err: - print(err) raise RequestTimeoutError from err print('>>> exit') @@ -203,9 +199,9 @@ def _send_json_request( if stream and response.stdout[0] != b"{": try: stderr = json.loads(response.stderr.decode()) - sha256sum = stderr["sha256sum"] - filename = stderr["filename"] - except (json.decoder.JSONDecodeError, ValueError) as err: + sha256sum = stderr["headers"]["etag"] + filename = stderr["headers"]["content-disposition"] + except (json.decoder.JSONDecodeError, KeyError) as err: raise BaseError("Unable to parse header metadata from response") from err # Get the checksum out of stderr return StreamedResponse( @@ -619,6 +615,7 @@ def download_submission( response = self._send_json_request( method, path_query, + stream=True, headers=self.req_headers, timeout=timeout or self.default_download_timeout, ) @@ -833,6 +830,7 @@ def download_reply(self, reply: Reply, path: str = "") -> Tuple[str, str]: response = self._send_json_request( method, path_query, + stream=True, headers=self.req_headers, timeout=self.default_request_timeout, )