コード例 #1
0
ファイル: crud.py プロジェクト: rohan-bajaj/osf.io
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)
    }
コード例 #2
0
def create_new_bucket(node_addon, **kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    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',
        }, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {'buckets': utils.get_bucket_drop_down(user_settings)}
    except S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, http.NOT_ACCEPTABLE
    except S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, http.NOT_ACCEPTABLE
    except BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, http.NOT_ACCEPTABLE
コード例 #3
0
ファイル: crud.py プロジェクト: GageGaskins/osf.io
def create_new_bucket(node_addon, **kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    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',
        }, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {
            'buckets': utils.get_bucket_drop_down(user_settings)
        }
    except S3ResponseError as e:
        return {
            'message': e.message,
            'title': 'Problem connecting to S3',
        }, http.NOT_ACCEPTABLE
    except S3CreateError as e:
        return {
            'message': e.message,
            'title': "Problem creating bucket '{0}'".format(bucket_name),
        }, http.NOT_ACCEPTABLE
    except BotoClientError as e:  # Base class catchall
        return {
            'message': e.message,
            'title': 'Error connecting to S3',
        }, http.NOT_ACCEPTABLE
コード例 #4
0
 def test_names(self):
     assert_true(validate_bucket_name('imagoodname'))
     assert_true(validate_bucket_name('still.passing'))
     assert_true(validate_bucket_name('can-have-dashes'))
     assert_true(validate_bucket_name('kinda.name.spaced'))
     assert_true(validate_bucket_name('a-o.valid'))
     assert_true(validate_bucket_name('11.12.m'))
     assert_true(validate_bucket_name('a--------a'))
     assert_true(validate_bucket_name('a' * 63))
コード例 #5
0
ファイル: test_view.py プロジェクト: atelic/osf.io
 def test_names(self):
     assert_true(validate_bucket_name('imagoodname'))
     assert_true(validate_bucket_name('still.passing'))
     assert_true(validate_bucket_name('can-have-dashes'))
     assert_true(validate_bucket_name('kinda.name.spaced'))
     assert_true(validate_bucket_name('a-o.valid'))
     assert_true(validate_bucket_name('11.12.m'))
     assert_true(validate_bucket_name('a--------a'))
     assert_true(validate_bucket_name('a' * 63))
コード例 #6
0
ファイル: test_view.py プロジェクト: KAsante95/osf.io
 def test_names(self):
     assert_true(validate_bucket_name("imagoodname"))
     assert_true(validate_bucket_name("still.passing"))
     assert_true(validate_bucket_name("can-have-dashes"))
     assert_true(validate_bucket_name("kinda.name.spaced"))
     assert_true(validate_bucket_name("a-o.valid"))
     assert_true(validate_bucket_name("11.12.m"))
     assert_true(validate_bucket_name("a--------a"))
     assert_true(validate_bucket_name("a" * 63))
コード例 #7
0
ファイル: test_view.py プロジェクト: XTech2K/osf.io
 def test_bad_names(self):
     assert_false(validate_bucket_name('bogus naMe'))
     assert_false(validate_bucket_name(''))
     assert_false(validate_bucket_name('no'))
     assert_false(validate_bucket_name('.cantstartwithp'))
     assert_false(validate_bucket_name('or.endwith.'))
     assert_false(validate_bucket_name('..nodoubles'))
     assert_false(validate_bucket_name('no_unders_in'))
コード例 #8
0
ファイル: test_view.py プロジェクト: pazthor/osf.io
 def test_bad_names(self):
     assert_false(validate_bucket_name('bogus naMe'))
     assert_false(validate_bucket_name(''))
     assert_false(validate_bucket_name('no'))
     assert_false(validate_bucket_name('.cantstartwithp'))
     assert_false(validate_bucket_name('or.endwith.'))
     assert_false(validate_bucket_name('..nodoubles'))
     assert_false(validate_bucket_name('no_unders_in'))
コード例 #9
0
ファイル: crud.py プロジェクト: fabianvf/osf.io
def create_new_bucket(**kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    bucket_name = request.json.get('bucket_name')

    if not validate_bucket_name(bucket_name):
        return {'message': 'That bucket name is not valid.'}, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {}
    except BotoClientError as e:
        return {'message': e.message}, http.NOT_ACCEPTABLE
    except S3ResponseError as e:
        return {'message': e.message}, http.NOT_ACCEPTABLE
コード例 #10
0
def create_new_bucket(**kwargs):
    user = kwargs['auth'].user
    user_settings = user.get_addon('s3')
    bucket_name = request.json.get('bucket_name')

    if not validate_bucket_name(bucket_name):
        return {
            'message': 'That bucket name is not valid.'
        }, http.NOT_ACCEPTABLE
    try:
        create_bucket(user_settings, request.json.get('bucket_name'))
        return {}
    except BotoClientError as e:
        return {'message': e.message}, http.NOT_ACCEPTABLE
    except S3ResponseError as e:
        return {'message': e.message}, http.NOT_ACCEPTABLE
コード例 #11
0
ファイル: views.py プロジェクト: 545zhou/osf.io
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)
    }
コード例 #12
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)}
コード例 #13
0
 def test_bad_names(self):
     assert_false(validate_bucket_name(''))
     assert_false(validate_bucket_name('no'))
     assert_false(validate_bucket_name('a' * 64))
     assert_false(validate_bucket_name(' leadingspace'))
     assert_false(validate_bucket_name('trailingspace '))
     assert_false(validate_bucket_name('bogus naMe'))
     assert_false(validate_bucket_name('.cantstartwithp'))
     assert_false(validate_bucket_name('or.endwith.'))
     assert_false(validate_bucket_name('..nodoubles'))
     assert_false(validate_bucket_name('no_unders_in'))
     assert_false(validate_bucket_name('-leadinghyphen'))
     assert_false(validate_bucket_name('trailinghyphen-'))
     assert_false(validate_bucket_name('Mixedcase'))
     assert_false(validate_bucket_name('empty..label'))
     assert_false(validate_bucket_name('label-.trailinghyphen'))
     assert_false(validate_bucket_name('label.-leadinghyphen'))
     assert_false(validate_bucket_name('8.8.8.8'))
     assert_false(validate_bucket_name('600.9000.0.28'))
     assert_false(validate_bucket_name('no_underscore'))
     assert_false(validate_bucket_name('_nounderscoreinfront'))
     assert_false(validate_bucket_name('no-underscore-in-back_'))
     assert_false(
         validate_bucket_name('no-underscore-in_the_middle_either'))
コード例 #14
0
ファイル: test_view.py プロジェクト: atelic/osf.io
 def test_bad_names(self):
     assert_false(validate_bucket_name(''))
     assert_false(validate_bucket_name('no'))
     assert_false(validate_bucket_name('a' * 64))
     assert_false(validate_bucket_name(' leadingspace'))
     assert_false(validate_bucket_name('trailingspace '))
     assert_false(validate_bucket_name('bogus naMe'))
     assert_false(validate_bucket_name('.cantstartwithp'))
     assert_false(validate_bucket_name('or.endwith.'))
     assert_false(validate_bucket_name('..nodoubles'))
     assert_false(validate_bucket_name('no_unders_in'))
     assert_false(validate_bucket_name('-leadinghyphen'))
     assert_false(validate_bucket_name('trailinghyphen-'))
     assert_false(validate_bucket_name('Mixedcase'))
     assert_false(validate_bucket_name('empty..label'))
     assert_false(validate_bucket_name('label-.trailinghyphen'))
     assert_false(validate_bucket_name('label.-leadinghyphen'))
     assert_false(validate_bucket_name('8.8.8.8'))
     assert_false(validate_bucket_name('600.9000.0.28'))
     assert_false(validate_bucket_name('no_underscore'))
     assert_false(validate_bucket_name('_nounderscoreinfront'))
     assert_false(validate_bucket_name('no-underscore-in-back_'))
     assert_false(validate_bucket_name('no-underscore-in_the_middle_either'))
コード例 #15
0
ファイル: test_view.py プロジェクト: KAsante95/osf.io
 def test_bad_names(self):
     assert_false(validate_bucket_name(""))
     assert_false(validate_bucket_name("no"))
     assert_false(validate_bucket_name("a" * 64))
     assert_false(validate_bucket_name(" leadingspace"))
     assert_false(validate_bucket_name("trailingspace "))
     assert_false(validate_bucket_name("bogus naMe"))
     assert_false(validate_bucket_name(".cantstartwithp"))
     assert_false(validate_bucket_name("or.endwith."))
     assert_false(validate_bucket_name("..nodoubles"))
     assert_false(validate_bucket_name("no_unders_in"))
     assert_false(validate_bucket_name("-leadinghyphen"))
     assert_false(validate_bucket_name("trailinghyphen-"))
     assert_false(validate_bucket_name("Mixedcase"))
     assert_false(validate_bucket_name("empty..label"))
     assert_false(validate_bucket_name("label-.trailinghyphen"))
     assert_false(validate_bucket_name("label.-leadinghyphen"))
     assert_false(validate_bucket_name("8.8.8.8"))
     assert_false(validate_bucket_name("600.9000.0.28"))
     assert_false(validate_bucket_name("no_underscore"))
     assert_false(validate_bucket_name("_nounderscoreinfront"))
     assert_false(validate_bucket_name("no-underscore-in-back_"))
     assert_false(validate_bucket_name("no-underscore-in_the_middle_either"))