Open Jiefei-Wang opened 5 years ago
If you are using auto-auth (recommended) then the file location is available in R for googleCloudStorageR via Sys.getenv("GCS_AUTH_FILE")
which will work if set via normal environment arguments by any language (so os.environ["GCS_AUTH_FILE"]
in python)
Thank you @MarkEdmondson1234 . Currently, my package is using the system environment, which is exactly the same as your suggestion, but the issue would be that if a user sets/resets the authentification later, the change will not be propagated to my package. For example, here is an exported function in googleCloudStorageR
:
gcs_auth <- function (json_file)
{
set_scopes()
gar_auth_service(json_file = json_file)
}
To propagate the change, I have to export an extra authentification function and document it, which is not quite an elegant solution. I will appreciate it if you can export a function to get the file location. Thanks.
I don’t understand your issue, could you show some code to explain what you mean?
From: Jiefei Wang notifications@github.com Sent: Monday, November 25, 2019 7:11 PM To: MarkEdmondson1234/googleAuthR Cc: Mark; Mention Subject: Re: [MarkEdmondson1234/googleAuthR] Retrieve the JASON file location (#167)
Thank you @MarkEdmondson1234https://github.com/MarkEdmondson1234 . Currently, my package is using the system environment, which is exactly the same as your suggestion, but the issue would be that if a user resets the authentification via a function in googleAuthR later, the change will not be propagated to my package. I have to export an extra authentification function and document it, which is not quite an elegant solution. I will appreciate it if you can export a function to get the file location. Thanks.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/MarkEdmondson1234/googleAuthR/issues/167?email_source=notifications&email_token=AAYCPLC3C4I3MTM5BM5FTJ3QVQIL3A5CNFSM4JRKW2U2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFDJSAY#issuecomment-558274819, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAYCPLFQCSHJOYCPXOKD2Z3QVQIL3ANCNFSM4JRKW2UQ.
Sure, here is a simple example code:
pkg_private <- new.env()
.onLoad <- function(libname,pkgname){
creds <- Sys.getenv("GCS_AUTH_FILE")
if(creds!="")
set_credentials(creds)
}
set_credentials <- function(creds){
pkg_private$credentials <- creds
}
Ideally when users load the package and the environment variable can be found, the json file will be located. However, if a user does not set the environment variable, or wants to use a different json file, he needs to call set_credentials
to set the location manually. You can clearly see that the package reinvents the wheel since there is already a gar_auth_service
function in googleAuthR
. Without the ability to retrieve the file location from googleAuthR
, it is users' responsibility to set the credentials correctly, so if the package googleAuthR
is loaded, the code will become:
creds <- "someFile.json"
set_credentials(creds)
gar_auth_service(creds)
Though two packages target on the same cloud, they work independently.
Best, Jiefei
Hi, I'm working on a google cloud storage package and would like to make it compatible with the existing packages, specifically
googleCloudStorageR
. The main issue is that my package uses a python library which requires a JASON credential file.googleCloudStorageR
does use the JASON file but I cannot find a way to retrieve the file location from neithergoogleCloudStorageR
norgoogleAuthR
. SincegoogleCloudStorageR
depends ongoogleAuthR
to do the authentification, I think this might be a good place to ask. Is there any way to get the location of the JASON file? If not, is it possible to store the file location in a place for the other package to use?Best, Jiefei