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
from flask import jsonify, request, abort, current_app, Response
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 utils import storage
from schemas import DescriptionSchema
@ -16,6 +16,8 @@ class ObjectView(FlaskView):
storage.connection.stat_object(current_app.config['MINIO_BUCKET_NAME'], tag)
except NoSuchKey:
return False
except NoSuchBucket:
return False
return True
@ -26,10 +28,6 @@ class ObjectView(FlaskView):
except ValidationError as e:
abort(400, str(e))
# check for conflict
if self._check_existance(description['tag']):
abort(409)
# get and validate file
file = request.files['soundFile']
@ -49,6 +47,10 @@ class ObjectView(FlaskView):
pass
# Everything else should be raised
# check for conflict
if self._check_existance(description['tag']):
abort(409)
# poot file into bucket
try:
storage.connection.put_object(current_app.config['MINIO_BUCKET_NAME'], description['tag'], file,