Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve behaviour with restricted application keys #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion b2blaze/b2lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def buckets(self):

:return:
"""
return B2Buckets(connector=self.connector)
return B2Buckets(connector=self.connector, single_bucket=self.connector.bucket_id)

3 changes: 3 additions & 0 deletions b2blaze/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, key_id, application_key):
self.download_url = None
self.recommended_part_size = None
self.api_session = None
self.bucket_id = None
#TODO: Part Size
self._authorize()

Expand Down Expand Up @@ -63,6 +64,8 @@ def _authorize(self):
self.api_url = result_json['apiUrl'] + API_VERSION
self.download_url = result_json['downloadUrl'] + API_VERSION + API.download_file_by_id
self.recommended_part_size = result_json['recommendedPartSize']
if result_json.get('allowed'):
self.bucket_id = result_json['allowed'].get('bucketId', None)
self.api_session = requests.Session()
self.api_session.headers.update({
'Authorization': self.auth_token
Expand Down
9 changes: 7 additions & 2 deletions b2blaze/models/bucket_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class B2Buckets(object):
public = 'allPublic'
private = 'allPrivate'

def __init__(self, connector):
def __init__(self, connector, single_bucket=None):
"""

:param connector:
:param str single_bucket: If any, the ID of the single bucket that we can list.
"""
self.connector = connector
self._single_bucket = single_bucket
self._buckets_by_name = {}
self._buckets_by_id = {}

Expand All @@ -37,7 +39,10 @@ def _update_bucket_list(self, retrieve=False):
:return:
"""
path = API.list_all_buckets
response = self.connector.make_request(path=path, method='post', account_id_required=True)
params = {}
if self._single_bucket:
params['bucketId'] = self._single_bucket
response = self.connector.make_request(path=path, method='post', account_id_required=True, params=params)
if response.status_code == 200:
response_json = response.json()
buckets = []
Expand Down