60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from flask import Flask
|
|
from minio import Minio
|
|
from minio.error import (ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists)
|
|
import os
|
|
import uuid
|
|
import pickle
|
|
app = Flask(__name__)
|
|
minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False)
|
|
|
|
@app.route('/')
|
|
def hello_docker():
|
|
return 'Hello, I run in a docker container'
|
|
|
|
@app.route('/acces_minio')
|
|
def access_minio():
|
|
for bucket in minioClient.list_buckets():
|
|
print(bucket.name, bucket.creation_date, flush=True)
|
|
return('Connection Succesfull')
|
|
|
|
@app.route('/new_user_id')
|
|
def new_user_id():
|
|
id = None
|
|
for limited_try in range(0,5):
|
|
id = str(uuid.uuid4())
|
|
if check_id(id) == False:
|
|
break
|
|
demo_object = ['test']
|
|
with open('demo_object.temp', 'wb') as f:
|
|
pickle.dump(demo_object, f)
|
|
with open('demo_object.temp', 'rb') as demo_object:
|
|
minioClient.put_object('users', str(id), demo_object, os.stat('demo_object').st_size)
|
|
#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
|
|
|
|
def setup():
|
|
try:
|
|
minioClient.make_bucket("users")
|
|
except BucketAlreadyOwnedByYou as err:
|
|
pass
|
|
except BucketAlreadyExists as err:
|
|
pass
|
|
except ResponseError as err:
|
|
raise
|
|
|
|
|
|
if __name__ == '__main__':
|
|
setup()
|
|
app.run(host='0.0.0.0') |