From b3fed56c00d03599b4a8479e5de0a36c696c7a97 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 5 May 2022 12:11:09 -0400 Subject: [PATCH] Move Foolscap compatibility to a better place. --- src/allmydata/storage/http_client.py | 6 ------ src/allmydata/storage_client.py | 16 +++++++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/allmydata/storage/http_client.py b/src/allmydata/storage/http_client.py index 0229bef03..2db28dc72 100644 --- a/src/allmydata/storage/http_client.py +++ b/src/allmydata/storage/http_client.py @@ -706,12 +706,6 @@ class StorageClientMutables: if response.code == http.OK: result = await _decode_cbor(response, _SCHEMAS["mutable_read_test_write"]) return ReadTestWriteResult(success=result["success"], reads=result["data"]) - elif response.code == http.UNAUTHORIZED: - # TODO mabye we can fix this to be nicer at some point? Custom - # exception? - from foolscap.api import RemoteException - - raise RemoteException("Authorization failed") else: raise ClientException(response.code, (await response.content())) diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 8b2f68a9e..cd489a307 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -50,6 +50,7 @@ from zope.interface import ( Interface, implementer, ) +from twisted.web import http from twisted.internet import defer from twisted.application import service from twisted.plugin import ( @@ -78,7 +79,7 @@ from allmydata.util.dictutil import BytesKeyDict, UnicodeKeyDict from allmydata.storage.http_client import ( StorageClient, StorageClientImmutables, StorageClientGeneral, ClientException as HTTPClientException, StorageClientMutables, - ReadVector, TestWriteVectors, WriteVector, TestVector + ReadVector, TestWriteVectors, WriteVector, TestVector, ClientException ) @@ -1247,8 +1248,13 @@ class _HTTPStorageServer(object): ReadVector(offset=offset, size=size) for (offset, size) in r_vector ] - client_result = yield mutable_client.read_test_write_chunks( - storage_index, we_secret, lr_secret, lc_secret, client_tw_vectors, - client_read_vectors, - ) + try: + client_result = yield mutable_client.read_test_write_chunks( + storage_index, we_secret, lr_secret, lc_secret, client_tw_vectors, + client_read_vectors, + ) + except ClientException as e: + if e.code == http.UNAUTHORIZED: + raise RemoteException("Unauthorized write, possibly you passed the wrong write enabler?") + raise return (client_result.success, client_result.reads)