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

Adds parameter profile_name to be used instead of credentials. #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ Here's how you specify credentials with the constructor::
aws_secret_access_key=<secret key>
)


.. note::

Amazon recommends against specifying credentials explicitly like
this in production.

Another posibility is using `profile_name`, which will read the credentials
for said profile from the standard configuration files::

s3fs = S3FS(
'mybucket'
profile_name=<profile_name>
)


S3 Info
=======
Expand Down
14 changes: 14 additions & 0 deletions fs_s3fs/_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class S3FS(FS):
:param str endpoint_url: Alternative endpoint url (``None`` to use
default).
:param str aws_session_token:
:param str profile_name: The name of the profile_name from which credentials
should be taken (read from standard configuration files). Can be used instead
of passing access key id and secret access key for non-default profiles.
:param str region: Optional S3 region.
:param str delimiter: The delimiter to separate folders, defaults to
a forward slash.
Expand Down Expand Up @@ -269,6 +272,8 @@ def __init__(
aws_access_key_id=None,
aws_secret_access_key=None,
aws_session_token=None,
profile_name
profile_name=None,
endpoint_url=None,
region=None,
delimiter="/",
Expand All @@ -279,11 +284,20 @@ def __init__(
download_args=None,
):
_creds = (aws_access_key_id, aws_secret_access_key)
if any(_creds) and profile_name
profile_name:
raise ValueError(
"profile_name
"profile_name and aws_access_key/secret cannot be used together"
)
if any(_creds) and not all(_creds):
raise ValueError(
"aws_access_key_id and aws_secret_access_key "
"must be set together if specified"
)
if profile_name:
credentials = boto3.session.Session(profile_name=profile_name).get_credentials()
aws_access_key_id, aws_secret_access_key = credentials.access_key, credentials.secret_key
self._bucket_name = bucket_name
self.dir_path = dir_path
self._prefix = relpath(normpath(dir_path)).rstrip("/")
Expand Down