Skip to content

Commit

Permalink
SDK updates for streaming changes (now works!)
Browse files Browse the repository at this point in the history
  • Loading branch information
legoktm committed Jan 18, 2024
1 parent 31fdf38 commit f537079
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions client/securedrop_client/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit f537079

Please sign in to comment.