Verified Commit 5ca40e18 authored by Victor's avatar Victor
Browse files

[feature] client implementation for upstream

-- Resolves #8773
parent 91da9991
......@@ -41,6 +41,7 @@ from leap.soledad.client._crypto import InvalidBlob
from leap.soledad.client._crypto import BlobEncryptor
from leap.soledad.client._crypto import BlobDecryptor
from leap.soledad.client._crypto import EncryptionSchemeNotImplementedException
from leap.soledad.client._crypto import get_unarmored_ciphertext_size
from leap.soledad.client._http import HTTPClient
from leap.soledad.client._pipes import TruncatedTailPipe
from leap.soledad.client._pipes import PreamblePipe
......@@ -495,6 +496,29 @@ class BlobManager(BlobsSynchronizer):
yield defer.gatherResults(deferreds, consumeErrors=True)
def _upstream(self, blobs_id_list, namespace=''):
uri = urljoin(self.remote_stream, self.user)
params = {'namespace': namespace} if namespace else None
sizes = yield self.local.get_size_list(blobs_id_list, namespace)
convert = get_unarmored_ciphertext_size
sizes = map(lambda (x, y): (x, convert(y)), sizes)
data = BytesIO() # TODO: stream from db
data.write(json.dumps(sizes) + '\n')
for blob_id in blobs_id_list:
blob_fd = yield self.local.get(blob_id, namespace=namespace)
doc_info = DocInfo(blob_id, FIXED_REV)
crypter = BlobEncryptor(doc_info, blob_fd, secret=self.secret,
fd = yield crypter.encrypt()
params = {'namespace': namespace} if namespace else {}
params['direction'] = 'upload'
response = yield, data=data, params=params)
check_http_status(response.code, blob_id)"Finished stream up: %s" % (blobs_id_list,))
def _download_and_decrypt(self, blob_id, namespace=''):"Staring download of blob: %s" % blob_id)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment