buckets.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:appscale-cloud-storage 作者: AppScale 项目源码 文件源码
def insert_bucket(project, conn):
    """ Creates a new bucket.

    Args:
        project: A string specifying a project ID.
        conn: An S3Connection instance.
    Returns:
        A JSON string representing a bucket.
    """
    bucket_info = request.get_json()
    # TODO: Do the following lookup and create under a lock.
    if conn.lookup(bucket_info['name']) is not None:
        return error('Sorry, that name is not available. '
                     'Please try a different one.', HTTP_CONFLICT)

    index_bucket(bucket_info['name'], project)

    conn.create_bucket(bucket_info['name'])

    # The HEAD bucket request does not return creation_date. This is an
    # inefficient way of retrieving it.
    try:
        bucket = next(bucket for bucket in conn.get_all_buckets()
                      if bucket.name == bucket_info['name'])
    except StopIteration:
        return error('Unable to find bucket after creating it.')

    bucket_url = url_for('get_bucket', bucket_name=bucket.name)
    response = {
        'kind': 'storage#bucket',
        'id': bucket.name,
        'selfLink': request.url_root[:-1] + bucket_url,
        'name': bucket.name,
        'timeCreated': bucket.creation_date,
        'updated': bucket.creation_date
    }
    return Response(json.dumps(response), mimetype='application/json')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号