Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): Ensure AWS credential provider sources AWS_PROFILE from environment after deserialization #21121

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions py-polars/polars/io/cloud/credential_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ def __call__(self) -> CredentialProviderFunctionReturn:
"""Fetch the credentials for the configured profile name."""
import boto3

# Note: boto3 automatically sources the AWS_PROFILE env var
session = boto3.Session(
profile_name=self.profile_name, region_name=self.region_name
profile_name=self.profile_name,
region_name=self.region_name,
)

if self.assume_role is not None:
Expand Down Expand Up @@ -186,7 +188,6 @@ def __init__(
tenant_id: str | None = None,
credentials: Any | None = None,
_storage_account: str | None = None,
_verbose: bool = False,
) -> None:
"""
Initialize a credential provider for Microsoft Azure.
Expand All @@ -213,7 +214,6 @@ def __init__(
)
self.tenant_id = tenant_id
self.credentials = credentials
self._verbose = _verbose

if credentials is not None:
# If the user passes a credentials class, we just need to ensure it
Expand All @@ -230,7 +230,7 @@ def __init__(
elif self._try_get_azure_storage_account_credentials_if_permitted() is None:
self._ensure_module_availability()

if self._verbose:
if os.getenv("POLARS_VERBOSE") == "1":
print(
(
"[CredentialProviderAzure]: "
Expand Down Expand Up @@ -268,7 +268,9 @@ def _try_get_azure_storage_account_credentials_if_permitted(
"POLARS_AUTO_USE_AZURE_STORAGE_ACCOUNT_KEY"
)

if self._verbose:
verbose = os.getenv("POLARS_VERBOSE") == "1"

if verbose:
print(
"[CredentialProviderAzure]: "
f"{self.account_name = } "
Expand All @@ -287,13 +289,13 @@ def _try_get_azure_storage_account_credentials_if_permitted(
)
}

if self._verbose:
if verbose:
print(
"[CredentialProviderAzure]: Retrieved account key from Azure CLI",
file=sys.stderr,
)
except Exception as e:
if self._verbose:
if verbose:
print(
f"[CredentialProviderAzure]: Could not retrieve account key from Azure CLI: {e}",
file=sys.stderr,
Expand Down Expand Up @@ -519,12 +521,11 @@ def _maybe_init_credential_provider(

provider = CredentialProviderAzure(
tenant_id=tenant_id,
_verbose=verbose,
_storage_account=storage_account,
)
elif _is_aws_cloud(scheme):
region = None
profile = os.getenv("AWS_PROFILE")
profile = None
default_region = None
unhandled_key = None

Expand All @@ -547,8 +548,7 @@ def _maybe_init_credential_provider(
unhandled_key = k

to_silence_this_warning = (
"To silence this warning, pass 'aws_profile': None in "
"storage_options, or unset the AWS_PROFILE environment flag."
"To silence this warning, pass 'aws_profile': None in storage_options."
)

if unhandled_key is not None:
Expand Down
Loading