Fixed checking fails with missing bucket

This commit is contained in:
Pünkösd Marcell 2020-04-29 22:01:45 +02:00
parent e1b4b87cc2
commit 8d6e34bd21

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from flask import jsonify, request, abort, current_app, Response from flask import jsonify, request, abort, current_app, Response
from flask_classful import FlaskView from flask_classful import FlaskView
from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey, NoSuchBucket
from marshmallow import ValidationError from marshmallow import ValidationError
from utils import storage from utils import storage
from schemas import DescriptionSchema from schemas import DescriptionSchema
@ -16,6 +16,8 @@ class ObjectView(FlaskView):
storage.connection.stat_object(current_app.config['MINIO_BUCKET_NAME'], tag) storage.connection.stat_object(current_app.config['MINIO_BUCKET_NAME'], tag)
except NoSuchKey: except NoSuchKey:
return False return False
except NoSuchBucket:
return False
return True return True
@ -26,10 +28,6 @@ class ObjectView(FlaskView):
except ValidationError as e: except ValidationError as e:
abort(400, str(e)) abort(400, str(e))
# check for conflict
if self._check_existance(description['tag']):
abort(409)
# get and validate file # get and validate file
file = request.files['soundFile'] file = request.files['soundFile']
@ -49,6 +47,10 @@ class ObjectView(FlaskView):
pass pass
# Everything else should be raised # Everything else should be raised
# check for conflict
if self._check_existance(description['tag']):
abort(409)
# poot file into bucket # poot file into bucket
try: try:
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file, storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,