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

simple way to supply token #30

Closed
hansvancalster opened this issue May 25, 2020 · 3 comments
Closed

simple way to supply token #30

hansvancalster opened this issue May 25, 2020 · 3 comments
Assignees
Milestone

Comments

@hansvancalster
Copy link

Hi! At my institution we are using Zenodo more and more to archive data. We are looking for ways to interact with Zenodo from R and this package looks very promising.

One thing I noticed when trying the functions was that a safe way to supply and access a token is missing. I wrote a small function taken from remotes::github_pat(). The idea is to add the token to ZENODO_PAT variable in the .Renviron file. The following function
zenodo_pat() can then be used to get the personal access token:

#' Retrieve Zenodo personal access token.
#'
#' A zenodo personal access token
#' Looks in env var `ZENODO_PAT`
#'
#' @keywords internal
#' @noRd
zenodo_pat <- function(quiet = TRUE) {
  pat <- Sys.getenv("ZENODO_PAT")
  
  if (nzchar(pat)) {
    if (!quiet) {
      message("Using zenodo PAT from envvar ZENODO_PAT")
    }
    return(pat) 
  }
  NULL
}

Usage:

zenodo <- ZenodoManager$new(
  token = zenodo_pat(), 
  logger = "INFO"
)
zenodo

However, when printing zenodo the secret token will be printed as well, which I think should best be avoided.

I will also file another issue with an idea for a function to download a zenodo archive.

@eblondel
Copy link
Owner

eblondel commented May 25, 2020

Thanks @hansvancalster, i'm aware of the printing issue when putting zenodo. At that time, no specific printing has been set, and the default R6 printing displays private fields (including the token). I will see if I can add a default printer that hides it, and let you know.

As for the function you suggest, i don't see direct added value to have it. As it is, user is free to call directly Sys.getenv with the variable name he choses for setting the Zenodo token.

@eblondel eblondel self-assigned this May 25, 2020
@hansvancalster
Copy link
Author

Thanks for looking into this! Regarding the zenodo_pat() function, I had a similar default behaviour for token = zenodo_pat() as in install_github(...., auth_token = github_pat(), ...) in mind, which I think is very user-friendly.

@eblondel eblondel added the enhancement New feature or request label Jul 20, 2020
@eblondel eblondel added new feature and removed enhancement New feature or request labels Aug 5, 2020
@eblondel eblondel added this to the 0.4 milestone Aug 5, 2020
@eblondel
Copy link
Owner

eblondel commented Aug 5, 2020

@hansvancalster i've pushed this into master. For hiding the password, i've resolved it by implementing 'keyring' package at #33.

@eblondel eblondel closed this as completed Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants