diff --git a/dvc/fs/s3.py b/dvc/fs/s3.py index b5cc9bf69..b24e67d31 100644 --- a/dvc/fs/s3.py +++ b/dvc/fs/s3.py @@ -124,6 +124,14 @@ class BaseS3FileSystem(FSSpecWrapper): login_info["profile"] ) + shared_creds = config.get("credentialpath") + if shared_creds: + os.environ.setdefault("AWS_SHARED_CREDENTIALS_FILE", shared_creds) + + config_path = config.get("configpath") + if config_path: + os.environ.setdefault("AWS_CONFIG_FILE", config_path) + return unflatten( { key: value diff --git a/tests/unit/fs/test_s3.py b/tests/unit/fs/test_s3.py index 938c239b0..ad9c11ef6 100644 --- a/tests/unit/fs/test_s3.py +++ b/tests/unit/fs/test_s3.py @@ -1,4 +1,5 @@ import importlib +import os import sys import textwrap @@ -41,6 +42,31 @@ def test_verify_ssl_default_param(dvc): assert fs.fs_args["client_kwargs"]["verify"] +def test_s3_config_credentialpath(dvc, monkeypatch): + environment = {} + monkeypatch.setattr(os, "environ", environment) + + config = {"url": url, "credentialpath": "somewhere"} + S3FileSystem(dvc, config) + assert environment["AWS_SHARED_CREDENTIALS_FILE"] == "somewhere" + environment.clear() + + config = {"url": url, "configpath": "somewhere"} + S3FileSystem(dvc, config) + assert environment["AWS_CONFIG_FILE"] == "somewhere" + environment.clear() + + config = { + "url": url, + "credentialpath": "somewhere", + "configpath": "elsewhere", + } + S3FileSystem(dvc, config) + assert environment["AWS_SHARED_CREDENTIALS_FILE"] == "somewhere" + assert environment["AWS_CONFIG_FILE"] == "elsewhere" + environment.clear() + + def test_ssl_verify_bool_param(dvc): config = {"url": url, "ssl_verify": False} fs = S3FileSystem(dvc, config)