face-recognition-app/face_recognition/app/app.py

54 lines
1.4 KiB
Python
Raw Normal View History

2019-06-08 17:25:13 +00:00
from flask import Flask
2019-06-08 19:08:20 +00:00
from minio import Minio
2019-06-10 09:59:39 +00:00
from minio.error import (ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists)
2019-06-08 18:59:15 +00:00
import os
2019-06-10 10:31:07 +00:00
import uuid
2019-06-08 17:11:05 +00:00
app = Flask(__name__)
@app.route('/')
def hello_docker():
return 'Hello, I run in a docker container'
2019-06-08 18:59:15 +00:00
@app.route('/acces_minio')
def access_minio():
2019-06-10 09:46:47 +00:00
for bucket in minioClient.list_buckets():
2019-06-10 10:35:09 +00:00
print(bucket.name, bucket.creation_date, flush=True)
2019-06-10 09:41:07 +00:00
return('Connection Succesfull')
2019-06-11 09:24:06 +00:00
@app.route('/new_user_id')
def new_user_id():
id = None
for limited_try in range(0,5):
2019-06-11 09:41:28 +00:00
id = str(uuid.uuid4())
2019-06-11 09:38:30 +00:00
if check_id(id) == False:
2019-06-11 09:24:06 +00:00
break
#funktionalität implementieres s3 Platzhalterdatei anlegen für user,
return(id)
def check_id(id):
#return True -> id bereits verwendet
#return False -> id noch nicht verwendet
users = minioClient.list_objects('users')
known = False
for user in users:
if id == user.object_name.encode('utf-8'):
known = True
else:
pass
return known
2019-06-10 10:31:07 +00:00
2019-06-10 09:59:39 +00:00
def setup():
minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False)
try:
minioClient.make_bucket("users")
2019-06-10 10:37:12 +00:00
except BucketAlreadyOwnedByYou as err:
2019-06-10 09:59:39 +00:00
pass
2019-06-10 10:37:12 +00:00
except BucketAlreadyExists as err:
2019-06-10 09:59:39 +00:00
pass
2019-06-10 10:37:12 +00:00
except ResponseError as err:
2019-06-10 09:59:39 +00:00
raise
2019-06-08 17:11:05 +00:00
if __name__ == '__main__':
2019-06-11 09:07:04 +00:00
setup()
2019-06-08 17:11:05 +00:00
app.run(host='0.0.0.0')