2020
2121from gcloud .exceptions import NotFound
2222from gcloud .storage ._implicit_environ import get_default_connection
23+ from gcloud .storage ._implicit_environ import get_default_project
2324from gcloud .storage .bucket import Bucket
2425from gcloud .storage .iterator import Iterator
2526
@@ -59,7 +60,7 @@ def lookup_bucket(bucket_name, connection=None):
5960 return None
6061
6162
62- def get_all_buckets (connection = None ):
63+ def get_all_buckets (project = None , connection = None ):
6364 """Get all buckets in the project.
6465
6566 This will not populate the list of blobs available in each
@@ -71,6 +72,10 @@ def get_all_buckets(connection=None):
7172
7273 This implements "storage.buckets.list".
7374
75+ :type project: string
76+ :param project: Optional. The project to use when listing all buckets.
77+ If not provided, falls back to default.
78+
7479 :type connection: :class:`gcloud.storage.connection.Connection` or
7580 ``NoneType``
7681 :param connection: Optional. The connection to use when sending requests.
@@ -81,7 +86,11 @@ def get_all_buckets(connection=None):
8186 """
8287 if connection is None :
8388 connection = get_default_connection ()
84- return iter (_BucketIterator (connection = connection ))
89+ if project is None :
90+ project = get_default_project ()
91+ extra_params = {'project' : project }
92+ return iter (_BucketIterator (connection = connection ,
93+ extra_params = extra_params ))
8594
8695
8796def get_bucket (bucket_name , connection = None ):
@@ -121,7 +130,7 @@ def get_bucket(bucket_name, connection=None):
121130 return Bucket (properties = response , connection = connection )
122131
123132
124- def create_bucket (bucket_name , connection = None ):
133+ def create_bucket (bucket_name , project = None , connection = None ):
125134 """Create a new bucket.
126135
127136 For example::
@@ -134,6 +143,10 @@ def create_bucket(bucket_name, connection=None):
134143
135144 This implements "storage.buckets.insert".
136145
146+ :type project: string
147+ :param project: Optional. The project to use when creating bucket.
148+ If not provided, falls back to default.
149+
137150 :type bucket_name: string
138151 :param bucket_name: The bucket name to create.
139152
@@ -149,8 +162,12 @@ def create_bucket(bucket_name, connection=None):
149162 """
150163 if connection is None :
151164 connection = get_default_connection ()
165+ if project is None :
166+ project = get_default_project ()
152167
168+ query_params = {'project' : project }
153169 response = connection .api_request (method = 'POST' , path = '/b' ,
170+ query_params = query_params ,
154171 data = {'name' : bucket_name })
155172 return Bucket (properties = response , connection = connection )
156173
@@ -166,8 +183,9 @@ class _BucketIterator(Iterator):
166183 :param connection: The connection to use for querying the list of buckets.
167184 """
168185
169- def __init__ (self , connection ):
170- super (_BucketIterator , self ).__init__ (connection = connection , path = '/b' )
186+ def __init__ (self , connection , extra_params = None ):
187+ super (_BucketIterator , self ).__init__ (connection = connection , path = '/b' ,
188+ extra_params = extra_params )
171189
172190 def get_items_from_response (self , response ):
173191 """Factory method which yields :class:`.Bucket` items from a response.
0 commit comments