Minio Schnittstelle hinzugefügt

This commit is contained in:
Markus Clauß 2023-02-07 16:03:59 +01:00
parent 05a16fa980
commit 04fe4e3a83

View File

@ -0,0 +1,54 @@
from minio import Minio
from minio.commonconfig import Tags
class MinioClient():
def __init__(self, url, access_key, secret_key, secure=True):
"""
return minio client
"""
self.client = Minio(url, access_key, secret_key, secure=secure)
def create_bucket(self, name):
"""
check bucket exits and create
"""
found = self.client.bucket_exists(name)
if not found:
self.client.make_bucket(name)
""" FIX: Add Tags
tag_obj = Tags.new_bucket_tags()
for key, i in tags.items():
tag_obj[key] = i
self.client.set_bucket_tags(name)
"""
def upload_file(
self,
bucket,
filename: str,
outfilename,
outpath='',
content_type="application/csv",
metadata: dict = {},
):
"""
upload file to bucket
"""
if len(outpath) > 0:
if not outpath[-1] == '/':
outpath += '/'
self.client.fput_object(
bucket,
outpath + outfilename,
filename,
content_type=content_type,
metadata=metadata,
)