From 58d31662291b037efeb3ab0f5e751f1b3b69484a Mon Sep 17 00:00:00 2001 From: Tianhao-Gu Date: Thu, 6 Jun 2024 12:47:29 -0500 Subject: [PATCH] add minio client helper --- src/minio_utils/minio_utils.py | 21 +++++++++++++++++++++ src/notebook/startup.py | 1 + test/src/minio_utils/minio_utils_test.py | 1 + 3 files changed, 23 insertions(+) create mode 100644 src/minio_utils/minio_utils.py create mode 100644 test/src/minio_utils/minio_utils_test.py diff --git a/src/minio_utils/minio_utils.py b/src/minio_utils/minio_utils.py new file mode 100644 index 0000000..142c8f4 --- /dev/null +++ b/src/minio_utils/minio_utils.py @@ -0,0 +1,21 @@ +""" +This module contains utility functions to interact with Minio. +""" + +import os + +from minio import Minio + + +def get_minio_client() -> Minio: + """ + Helper function to get the Minio client. + + :return: A Minio client object + """ + return Minio( + os.environ['MINIO_URL'].replace("http://", ""), + access_key=os.environ['MINIO_ACCESS_KEY'], + secret_key=os.environ['MINIO_SECRET_KEY'], + secure=False + ) diff --git a/src/notebook/startup.py b/src/notebook/startup.py index f05e645..2c7435e 100644 --- a/src/notebook/startup.py +++ b/src/notebook/startup.py @@ -7,3 +7,4 @@ from spark.utils import get_spark_session from db_ops.spark_db_utils import create_namespace_if_not_exists, table_exists, remove_table +from minio_utils.minio_utils import get_minio_client \ No newline at end of file diff --git a/test/src/minio_utils/minio_utils_test.py b/test/src/minio_utils/minio_utils_test.py new file mode 100644 index 0000000..19f6431 --- /dev/null +++ b/test/src/minio_utils/minio_utils_test.py @@ -0,0 +1 @@ +from src.minio_utils.minio_utils import * \ No newline at end of file