def get_or_create(cls, bucket_name, client=None):
"""
If the bucket exists with this name, get it. Else, create it
:param cls: :class:`gstorage.bucket.Bucket`
:type bucket_name: string
:param bucket_name: name of the bucket
:type client: gcloud.client.Client
:param client: (optional) instance of client to use
:return: :class:`Bucket <Bucket>` object
:raises gcloud.exceptions.BadRequest (400): not a valid bucket name
:raises gcloud.exceptions.Forbidden (403): The credentials are invalid
"""
if not client:
credentials = GoogleCredentials.get_application_default()
client = Client(credentials=credentials)
bucket = cls(client, name=bucket_name)
if not bucket.exists():
bucket.create()
return bucket
评论列表
文章目录