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) }
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
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
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))
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))
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'))
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
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
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) }
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)}
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'))
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'))
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"))