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

add .onLoad() and .onAttach() functions which call use_credentials() … #184

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 18 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,21 @@ flatten_list <- function(x) {
return(x)
}
}

# This function gets called on package load.
.onLoad <- function(libname, pkgname) {
# If credentials are in environment variables, use those.
creds <- aws.signature::locate_credentials()
if (!all(is.null(creds$key), is.null(creds$secret))) {
return(invisible(NULL))
}
# Load default AWS credentials so calls to S3 'just work', allowing
# the package to behave like the AWS CLI
if (file.exists(aws.signature::default_credentials_file())) {
if (nchar(Sys.getenv("AWS_PROFILE"))) {
aws.signature::use_credentials(Sys.getenv("AWS_PROFILE"))
} else {
aws.signature::use_credentials()
}
}
}