From 04fe4e3a8349ef97785b4e27ef460d36b6ee4c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Clau=C3=9F?= Date: Tue, 7 Feb 2023 16:03:59 +0100 Subject: [PATCH] =?UTF-8?q?Minio=20Schnittstelle=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pytestpavement/io/minio.py | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/pytestpavement/io/minio.py diff --git a/src/pytestpavement/io/minio.py b/src/pytestpavement/io/minio.py new file mode 100644 index 0000000..a303e7d --- /dev/null +++ b/src/pytestpavement/io/minio.py @@ -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, + )