Skip to content
Open
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
28 changes: 2 additions & 26 deletions sendsafely/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
import json
import os
import secrets
import time

import requests
from .pgpy import PGPMessage, PGPKey
from .pgpy.constants import HashAlgorithm, SymmetricKeyAlgorithm, CompressionAlgorithm, KeyFlags

_S3_UPLOAD_MAX_RETRIES = 6
_S3_UPLOAD_TIMEOUT_SECONDS = 120
_S3_UPLOAD_RETRY_STATUS_CODES = [408, 429, 500, 502, 503, 504]


def _encrypt_file_part(file, server_secret, client_secret, path=True):
"""
Expand Down Expand Up @@ -198,28 +193,9 @@ def _upload_file_part_to_s3(encrypted_file_part, url):
Content-Type must NOT be specified
:param encrypted_file_part: Part of a file to upload to S3. Must not exceed 2621440 Bytes.
:param url: The S3 URL we're uploading to
:return: The response from S3 once the part has been accepted.
:raises requests.exceptions.RequestException: If the part still cannot be uploaded after retries.
:return: The JSON response from S3.
"""
last_exception = None
for retries in range(_S3_UPLOAD_MAX_RETRIES):
try:
response = requests.put(url=url, data=encrypted_file_part, timeout=_S3_UPLOAD_TIMEOUT_SECONDS)
except requests.exceptions.RequestException as e:
last_exception = e
else:
if response.status_code not in _S3_UPLOAD_RETRY_STATUS_CODES:
response.raise_for_status()
return response
last_exception = requests.exceptions.HTTPError(
"S3 returned retryable failure status %d" % response.status_code, response=response
)

if retries == _S3_UPLOAD_MAX_RETRIES - 1:
break
time.sleep(2 ** retries)

raise last_exception
return requests.put(url=url, data=encrypted_file_part)


def _calculate_package_checksum(package_code, keycode):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='sendsafely',
version='1.0.10',
version='1.0.9.6',
packages=['sendsafely', 'sendsafely/pgpy', 'sendsafely/pgpy/packet/subpackets'],
description='The SendSafely Client API allows programmatic access to SendSafely and provides a layer of abstraction from our REST API, which requires developers to perform several complex tasks in a correct manner.',
long_description_content_type="text/markdown",
Expand Down