-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from fieldse/master
Merge fixes
- Loading branch information
Showing
15 changed files
with
780 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from b2blaze.b2lib import B2 | ||
from b2blaze.b2lib import B2 | ||
from .api import API_VERSION, BASE_URL, API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# api.py | ||
# BackBlaze API endpoints | ||
|
||
API_VERSION = '/b2api/v2' | ||
BASE_URL = 'https://api.backblazeb2.com' + API_VERSION | ||
|
||
|
||
class API(): | ||
authorize = '/b2_authorize_account' | ||
delete_file = '/b2_hide_file' | ||
delete_file_version = '/b2_delete_file_version' | ||
file_info = '/b2_get_file_info' | ||
download_file_by_id = '/b2_download_file_by_id' | ||
list_all_files = '/b2_list_file_names' | ||
list_file_versions = '/b2_list_file_versions' | ||
upload_url = '/b2_get_upload_url' | ||
upload_large = '/b2_start_large_file' | ||
upload_large_part = '/b2_get_upload_part_url' | ||
upload_large_finish = '/b2_finish_large_file' | ||
create_bucket = '/b2_create_bucket' | ||
delete_bucket = '/b2_delete_bucket' | ||
list_all_buckets = '/b2_list_buckets' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,116 @@ | ||
""" | ||
Copyright George Sibble 2018 | ||
""" | ||
class B2ApplicationKeyNotSet(Exception): | ||
""" | ||
|
||
""" | ||
import json | ||
|
||
|
||
class B2ApplicationKeyNotSet(Exception): | ||
""" You must set the B2_KEY_ID environment variable before running the application """ | ||
pass | ||
|
||
|
||
class B2KeyIDNotSet(Exception): | ||
""" | ||
""" You must set the B2_APPLICATION_KEY environment variable before running the application """ | ||
pass | ||
|
||
""" | ||
|
||
class B2Exception(Exception): | ||
""" Base exception class for the Backblaze API """ | ||
|
||
@staticmethod | ||
def parse(response): | ||
""" Parse the response error code and return the related error type. """ | ||
|
||
API_EXCEPTION_CODES = { | ||
400 : B2RequestError, | ||
401 : B2UnauthorizedError, | ||
403 : B2ForbiddenError, | ||
404 : B2FileNotFoundError, | ||
408 : B2RequestTimeoutError, | ||
429 : B2TooManyRequestsError, | ||
500 : B2InternalError, | ||
503 : B2ServiceUnavailableError, | ||
} | ||
|
||
try: | ||
response_json = response.json() | ||
message = response_json['message'] | ||
code = response_json['code'] | ||
status = int(response_json['status']) | ||
|
||
# Return B2Exception if unrecognized status code | ||
if not status in API_EXCEPTION_CODES: | ||
return B2Exception('{} - {}: {}'.format(status, code, message)) | ||
|
||
ErrorClass = API_EXCEPTION_CODES[status] | ||
return ErrorClass('{} - {}: {}'.format(status, code, message)) | ||
|
||
except: | ||
return Exception('error parsing response. status code - {} Response JSON: {}'.format(response.status_code, response_json) ) | ||
|
||
class B2FileNotFoundError(Exception): | ||
""" 404 Not Found """ | ||
pass | ||
|
||
class B2InvalidBucketName(Exception): | ||
""" | ||
|
||
""" | ||
class B2RequestError(Exception): | ||
""" There is a problem with a passed in request parameters. See returned message for details """ | ||
pass | ||
|
||
class B2InvalidBucketConfiguration(Exception): | ||
""" | ||
|
||
class B2UnauthorizedError(Exception): | ||
""" When calling b2_authorize_account, this means that there was something wrong with the accountId/applicationKeyId or with the applicationKey that was provided. The code unauthorized means that the application key is bad. The code unsupported means that the application key is only valid in a later version of the API. | ||
The code unauthorized means that the auth token is valid, but does not allow you to make this call with these parameters. When the code is either bad_auth_token or expired_auth_token you should call b2_authorize_account again to get a new auth token. | ||
""" | ||
pass | ||
|
||
class B2AuthorizationError(Exception): | ||
""" | ||
|
||
class B2ForbiddenError(Exception): | ||
""" You have a reached a storage cap limit, or account access may be impacted in some other way; see the human-readable message. | ||
""" | ||
pass | ||
|
||
class B2BucketCreationError(Exception): | ||
""" | ||
|
||
""" | ||
class B2RequestTimeoutError(Exception): | ||
""" The service timed out trying to read your request. """ | ||
pass | ||
|
||
class B2RequestError(Exception): | ||
""" | ||
class B2OutOfRangeError(Exception): | ||
""" The Range header in the request is outside the size of the file.. """ | ||
pass | ||
|
||
""" | ||
|
||
class B2InvalidRequestType(Exception): | ||
""" | ||
class B2TooManyRequestsError(Exception): | ||
""" B2 may limit API requests on a per-account basis. """ | ||
pass | ||
|
||
""" | ||
|
||
class B2FileNotFound(Exception): | ||
class B2InternalError(Exception): | ||
""" An unexpected error has occurred. """ | ||
pass | ||
|
||
|
||
class B2ServiceUnavailableError(Exception): | ||
""" The service is temporarily unavailable. The human-readable message identifies the nature of the issue, in general we recommend retrying with an exponential backoff between retries in response to this error. | ||
""" | ||
pass | ||
|
||
|
||
""" | ||
class B2InvalidBucketName(Exception): | ||
""" Bucket name must be alphanumeric or '-' """ | ||
pass | ||
|
||
|
||
class B2InvalidBucketConfiguration(Exception): | ||
""" Value error in bucket configuration """ | ||
pass | ||
|
||
class B2AuthorizationError(Exception): | ||
""" An error with the authorization request """ | ||
pass | ||
|
||
class B2InvalidRequestType(Exception): | ||
""" Request type must be get or post """ | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.