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

Conversation

dtenenba
Copy link

@dtenenba dtenenba commented Dec 7, 2017

…if necessary, closes #182

Added a hook at package startup/attach time which (if creds have not been supplied via environment variables) runs aws.signature::use_credentials() so that users with
aws profiles (in ~/.aws) do not have to manually type that command before they can use S3.

@dtenenba
Copy link
Author

dtenenba commented Dec 8, 2017

I can't reproduce the test failure in Travis. I don't think I introduced any issues. I checked it locally with the same command as used in Travis (R CMD check aws.s3_0.3.8.tar.gz --ignore-vignettes --no-examples) and it passed.

In the travis logs I see two issues that could have caused the failure, both in this snippet:

** testing if installed package can be loaded
Error: package or namespace load failed for ‘aws.s3’:
 .onLoad failed in loadNamespace() for 'aws.s3', details:
  call: read_credentials(file)
  error: File '/home/travis/.aws/credentials' does not exist.
Error: loading failed

The first is that it looks like the name of the package is mangled, or those are just non-ascii quotes around it that are being rendered funny.
The second issue is that the credentials file cannot be found, but that's not something that I can help with.

Any chance this can be fixed, so that Travis will be happy and the PR can be considered for merging?

Thanks.

Copy link
Member

@leeper leeper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix these two things? Then I can merge. Cheers!

R/utils.R Outdated
# If credentials are in environment variables, use those.
creds <- aws.signature::locate_credentials()
if (!all(is.null(creds$key), is.null(creds$secret))) {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be something other than just the return function. Do you mean return(NULL) or return(invisible(NULL) perhaps?

R/utils.R Outdated
}
}

# Handle when package is attached (invoked with pkg::function()) not loaded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this function. .onLoad() is called when a package namespace is loaded, which occurs either at library("aws.s3") or aws.s3::{anything}(). .onAttach() is called only when library() or require() is used and is discouraged: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#index-_002eonAttach

.onLoad() is not meant to return anything, it's called for its side
effect of finding the credentials. But to be explicit, it now
returns invisible(NULL) if the credentials cannot be found.

Also, the .onAttach() function has been removed.
@codecov-io
Copy link

codecov-io commented Feb 23, 2018

Codecov Report

Merging #184 into master will increase coverage by 0.02%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #184      +/-   ##
==========================================
+ Coverage   20.72%   20.74%   +0.02%     
==========================================
  Files          32       32              
  Lines        1110     1128      +18     
==========================================
+ Hits          230      234       +4     
- Misses        880      894      +14
Impacted Files Coverage Δ
R/utils.R 30.68% <9.09%> (-5.32%) ⬇️
R/s3HTTP.R 66.52% <0%> (+0.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c28925d...b9f2f5c. Read the comment docs.

@dtenenba
Copy link
Author

OK, the changes have been made. It looks like the earlier build error was my fault, I fixed it by checking for the existence of aws.signature::default_credentials_file() before calling aws.signature::use_credentials().

@leeper
Copy link
Member

leeper commented Mar 19, 2018

Thanks. I've introduced this functionality into aws.signature so that it is consistent across cloudyr packages. cloudyr/aws.signature@7c44c5e

@leeper leeper closed this in 61a265c Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bucketlist() fails
3 participants