paws-r / paws

Paws, a package for Amazon Web Services in R
https://www.paws-r-sdk.com
Other
314 stars 37 forks source link

Possible issue with sso_credential_process on Windows #640

Closed karen5780 closed 1 year ago

karen5780 commented 1 year ago

Hi - I'm not a developer and am not really sure what I'm doing. As in I created a github account just now to make this post. But I've run into a possible bug that I think has an easy fix.

I'm running R 4.2.2 on Windows 10 and am using paws 0.2.0 to get AWS S3 data. The code I'm using (pasted below) works for me, and some but not all of the other users.

I've narrowed the issue to within sso_credential_process(): root <- ifelse(Sys.info()[[1]] == "Windows", Sys.getenv("HOMEPATH"), "~") sso_cache <- file.path(root, ".aws", "sso", "cache", json_file) if (!file.exists(sso_cache))

R is not finding the sso_cache file for some of my fellow users with only the HOMEPATH variable being specified. I don't know enough about how to figure out what file.exists is doing behind the scenes, but for them, the HOMEDRIVE also needs to be specified. As in, the root assignment line root <- ifelse(Sys.info()[[1]] == "Windows", paste0(Sys.getenv("HOMEDRIVE"), Sys.getenv("HOMEPATH"), "~") fixes the problem.

FYI, here's the code I'm using to read in from S3 with SSO.

library(paws) config_path <- paste(Root_Folder,"config", sep = "/") sso_profile <- "profile-name" Sys.setenv(AWS_CONFIG_FILE = config_path, AWS_PROFILE = sso_profile) system(paste("aws sso login --profile", sso_profile)) s3 <- paws::s3(config = list(region = "ca-central-1")) file <- s3$get_object(Bucket = bucket_name, Key = "File.csv")

DyfanJones commented 1 year ago

Ah thanks for this. I dont have windows computer to test this out fully. I will raise a PR. Are you or colleagues able to test this out for me?

karen5780 commented 1 year ago

Sure can

On Fri, Jun 30, 2023 at 1:51 PM Larefly @.***> wrote:

Ah thanks for this. I dont have windows computer to test this out fully. I will raise a PR. Are you or colleagues able to test this out for me?

— Reply to this email directly, view it on GitHub https://github.com/paws-r/paws/issues/640#issuecomment-1615068726, or unsubscribe https://github.com/notifications/unsubscribe-auth/BA6YAFDN5FM47J6Q272JS6TXN4N2TANCNFSM6AAAAAAZ2F7DE4 . You are receiving this because you authored the thread.Message ID: @.***>

DyfanJones commented 1 year ago

I have found this: https://stackoverflow.com/questions/606483/what-is-the-meaning-of-these-windows-environment-variables-homedrive-homepath#:~:text=HOMEDRIVE%20%2F%20HOMEPATH%20is%20where%20the,configuration%20files%20and%20personalization%20settings.

Am I right in thinking we will need to check 3 locations:

DyfanJones commented 1 year ago

@karen5780 Please try:

remotes::install_github("dyfanjones/paws/paws.common", ref = "sso_win_path")

It is basically the solution you proposed

karen5780 commented 1 year ago

Hi - I'm unfortunately probably not a good person to test this as I don't know much about R. When running the line, I got the following message: Package paws.common has compiled code, but no suitable compiler(s) were found. Installation will likely fail. And it did fail.

I don't have RTools and have no idea how to install anything that doesn't have a binary. Also FYI, this may perhaps be an issue with another package as I got messages prompted me to update other packages. I couldn't update jsonlite to 1.8.7 from 1.8.5 or digest from 0.6.32 from 0.6.31 as the binaries weren't available.

If you have any quick suggestions as to how I can test this out, I'd be happy to try.

karen5780 commented 1 year ago

I don't know enough about Windows either to know anything about the environment variables. It's my first time ever explicitly looking at either HOMEPATH or HOMEDRIVE - and only got HOMEDRIVE from a google search. I'm just an actuary who's proud of herself for getting this far. :)

DyfanJones commented 1 year ago

No worries I believe I can build the binary for you :)

paws.common_0.5.8.zip

paws_common_download_path <- "paws.common_0.5.8.zip"
install.packages(paws_common_download_path , repos = NULL)

If you want to install Rtools for building R packages from source, heres the link to Rtools for 4.2 version of R :)

Website link: https://cran.r-project.org/bin/windows/Rtools/rtools42/rtools.html Rtools42 exe: https://cran.r-project.org/bin/windows/Rtools/rtools42/files/rtools42-5355-5357.exe

karen5780 commented 1 year ago

Hi @DyfanJones, this works for me, thanks! I'll check on Tuesday to see if it works for my coworker - tomorrow is a stat holiday for us in Canada. I imagine this should work.

One thing that seems a little strange to me is how the root variable looks on my computer. Sys.getenv("HOMEDRIVE") lists "C:" for me and Sys.getenv("HOMEPATH") is "\Users\username". Using file.path to paste them together gives "C:/\Users\username" - I thought this would be one slash too many, but it's fine with file.exists().

karen5780 commented 1 year ago

Hi @DyfanJones, this worked for my coworker as well. The production version didn't work for her, so I believe the fix worked. Thanks!

DyfanJones commented 1 year ago

@karen5780 That is great news. paws.common 0.5.8 will be getting released to the cran shortly.

DyfanJones commented 1 year ago

Paws.common 0.5.8 has been released to the cran. I will close this ticket. Please re-open if problem persists.