From 527d28d7148294c8ed4e03690ffb77ac04a4640f Mon Sep 17 00:00:00 2001 From: bpenteado <33378855+bpenteado@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:59:00 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=82=20Make=20`get=5Fstat=5Fdir=5Fs3`?= =?UTF-8?q?=20read=20from=20UPath=20credentials=20(#664)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit :passport_control: Make get_stat_dir_s3 read from UPath credentials --- lamindb_setup/core/upath.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lamindb_setup/core/upath.py b/lamindb_setup/core/upath.py index 0d0441cfb..2e807a513 100644 --- a/lamindb_setup/core/upath.py +++ b/lamindb_setup/core/upath.py @@ -507,7 +507,17 @@ def get_stat_file_cloud(stat: Dict) -> Tuple[int, str, str]: def get_stat_dir_s3(path: UPath) -> Tuple[int, str, str, int]: import boto3 - if not AWS_CREDENTIALS_PRESENT: + if ( + path.fs.key is not None + and path.fs.secret is not None + and path.fs.token is not None + ): + s3 = boto3.session.Session( + aws_access_key_id=path.fs.key, + aws_secret_access_key=path.fs.secret, + aws_session_token=path.fs.token, + ).resource("s3") + elif not AWS_CREDENTIALS_PRESENT: # passing the following param directly to Session() doesn't # work, unfortunately: botocore_session=path.fs.session from botocore import UNSIGNED