Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/syft-enclave/src/syft_enclaves/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ def request_stderr(
"""Ask the enclave to share the job's stderr, or only its first ``n_chars`` chars.

Only a data owner can ask. The enclave shares it once every data owner
made the same request. ``readers`` None means the data owners this
enclave is configured with.
made the same request: the same readers and the same ``n_chars``.
``readers`` None means the data owners this enclave is configured with.
"""
self._request_log(job, "stderr.txt", readers, n_chars)

Expand Down
20 changes: 16 additions & 4 deletions packages/syft-enclave/src/syft_enclaves/enclave_job_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ def request_log(
) -> None:
"""Ask the enclave to share ``log_file``, or only its first ``n_chars`` chars.

The enclave shares it once every data owner made the same request.
``readers`` None means the data owners the enclave is configured with.
The enclave shares it once every data owner made the same request: the
same readers and the same ``n_chars``. ``readers`` None means the data
owners the enclave is configured with.

Raises:
PermissionError: If the caller is not a data owner of this job.
Expand All @@ -342,8 +343,19 @@ def request_log(
log_request_warning(log_file, request.readers), UserWarning, stacklevel=2
)
self._save_own_log_request(log_file, request)
who = request.readers or "the enclave's data owners"
print(f"Requested {log_file} of job '{self.name}' for {who}.")
if request.n_chars is None:
what = f"all of {log_file} (n_chars=None)"
else:
what = (
f"the first {request.n_chars:,} characters of {log_file} "
f"(n_chars={request.n_chars})"
)
who = ", ".join(request.readers or []) or "the enclave's data owners"
print(f"Requested {what} of job '{self.name}' for {who}.")
print(
" The enclave shares it once every data owner makes the same "
"request: the same readers and the same n_chars."
)

def _save_own_log_request(self, log_file: str, request: LogRequest) -> None:
"""Replace this party's request for ``log_file``, and push the file."""
Expand Down
21 changes: 21 additions & 0 deletions packages/syft-enclave/tests/test_read_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,24 @@ def test_submitter_cannot_request_logs():
enclave, do1, do2, ds = run_crash_sharing_nothing()
with pytest.raises(PermissionError, match="Only a data owner"):
ds.request_stderr(ds.jobs["j"])


def test_log_request_says_length_and_rule(capsys):
enclave, do1, do2, ds = run_crash_sharing_nothing()
capsys.readouterr()

with pytest.warns(UserWarning):
do1.request_stderr(do1.jobs["j"], readers=ds.email, n_chars=1000)
assert (
"Requested the first 1,000 characters of stderr.txt (n_chars=1000) "
f"of job 'j' for {ds.email}.\n"
" The enclave shares it once every data owner makes the same "
"request: the same readers and the same n_chars.\n"
) in capsys.readouterr().out

with pytest.warns(UserWarning):
do1.request_stdout(do1.jobs["j"])
assert (
"Requested all of stdout.txt (n_chars=None) of job 'j' for the "
"enclave's data owners."
) in capsys.readouterr().out
Loading