Ejemplo n.º 1
0
def create_bucket(auth, node_addon, **kwargs):
    bucket_name = request.json.get('bucket_name', '')

    if not utils.validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.',
            'title': 'Invalid bucket name',
        }, httplib.NOT_ACCEPTABLE

    try:
        utils.create_bucket(node_addon.user_settings, bucket_name)
    except exception.S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, httplib.NOT_ACCEPTABLE
    except exception.S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, httplib.NOT_ACCEPTABLE
    except exception.BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, httplib.NOT_ACCEPTABLE

    return {
        'buckets': utils.get_bucket_names(node_addon.user_settings)
    }
Ejemplo n.º 2
0
    def get_folders(self, **kwargs):
        # This really gets only buckets, not subfolders,
        # as that's all we want to be linkable on a node.
        try:
            buckets = get_bucket_names(self)
        except:
            raise exceptions.InvalidAuthError()

        return [
            {
                'addon': 's3',
                'kind': 'folder',
                'id': bucket,
                'name': bucket,
                'path': bucket,
                'urls': {
                    'folders': ''
                }
            }
            for bucket in buckets
        ]
Ejemplo n.º 3
0
def create_bucket(auth, node_addon, **kwargs):
    bucket_name = request.json.get('bucket_name', '')
    bucket_location = request.json.get('bucket_location', '')

    if not utils.validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.',
            'title': 'Invalid bucket name',
        }, httplib.BAD_REQUEST

    # Get location and verify it is valid
    if not utils.validate_bucket_location(bucket_location):
        return {
            'message': 'That bucket location is not valid.',
            'title': 'Invalid bucket location',
        }, httplib.BAD_REQUEST

    try:
        utils.create_bucket(node_addon, bucket_name, bucket_location)
    except exception.S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, httplib.BAD_REQUEST
    except exception.S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, httplib.BAD_REQUEST
    except exception.BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, httplib.BAD_REQUEST

    return {
        'buckets': utils.get_bucket_names(node_addon)
    }
Ejemplo n.º 4
0
def create_bucket(auth, node_addon, **kwargs):
    bucket_name = request.json.get('bucket_name', '')
    bucket_location = request.json.get('bucket_location', '')

    if not utils.validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.',
            'title': 'Invalid bucket name',
        }, httplib.NOT_ACCEPTABLE

    # Get location and verify it is valid
    if not utils.validate_bucket_location(bucket_location):
        return {
            'message': 'That bucket location is not valid.',
            'title': 'Invalid bucket location',
        }, httplib.NOT_ACCEPTABLE

    try:
        utils.create_bucket(node_addon.user_settings, bucket_name,
                            bucket_location)
    except exception.S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, httplib.NOT_ACCEPTABLE
    except exception.S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, httplib.NOT_ACCEPTABLE
    except exception.BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, httplib.NOT_ACCEPTABLE

    return {'buckets': utils.get_bucket_names(node_addon.user_settings)}
Ejemplo n.º 5
0
def _get_buckets(node_addon, folder_id=None):
    """Used by generic_view `folder_list` to fetch a list of buckets.
    `folder_id` required by generic, but not actually used"""
    return {'buckets': utils.get_bucket_names(node_addon)}
Ejemplo n.º 6
0
def s3_get_bucket_list(auth, node_addon, user_addon, **kwargs):
    return {
        'buckets': utils.get_bucket_names(user_addon)
    }
Ejemplo n.º 7
0
def _get_buckets(node_addon, folder_id=None):
    """Used by generic_view `folder_list` to fetch a list of buckets.
    `folder_id` required by generic, but not actually used"""
    return {
        'buckets': utils.get_bucket_names(node_addon)
    }
Ejemplo n.º 8
0
def s3_get_bucket_list(auth, node_addon, user_addon, **kwargs):
    return {'buckets': utils.get_bucket_names(user_addon)}