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

renv::restore() fails for packages hosted on a GitHub Enterprise server when gitcreds is installed #1814

Closed
ezraporter opened this issue Feb 8, 2024 · 5 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@ezraporter
Copy link

Steps to recreate the issue

renv::install(c("gitcreds", "remotes"))
remotes::install_github(repo = "REPO/PACKAGE",  host = "GHE_SERVER_URL/api/v3")
renv::snapshot(type="all")
renv::rebuild("PACKAGE")

This fails with an error like:

Error: error downloading 'https://GHE_SERVER_URL/api/v3/repos/REPO/PACKAGE/tarball/COMMIT_SHA' [curl: (22) The requested URL returned error: 401]

Apologies that I can't give a real GHE server to make this fully reproducible.

However if gitcreds is not installed it works.

Possible Solution

It looks like the call to gitcreds::gitcreds_get() is always using the default github.com url:

renv/R/download.R

Lines 546 to 548 in e7c23ea

token <- tryCatch(gitcreds::gitcreds_get(), error = function(cnd) {
warning(conditionMessage(cnd))
NULL

Is there a way to pass down the RemoteHost in renv.lock to give gitcreds a shot at finding the right PAT?

Alternatively, is there a way to shut off authenticating altogether which will be fine as long as I'm using public repos?

@kevinushey kevinushey added the bug an unexpected problem or unintended behavior label Feb 8, 2024
@kevinushey kevinushey added this to the 1.1.0 milestone Feb 8, 2024
@kevinushey
Copy link
Collaborator

Are you able to make use of the existing renv authentication mechanism? See https://rstudio.github.io/renv/articles/package-install.html#authentication for more details.

@kevinushey
Copy link
Collaborator

Should be resolved via 8f99f05; please let me know if that seems sufficient for your use case.

@ezraporter
Copy link
Author

Thanks! Tested the development version and it worked great.

The only issue I hit was that my keychain was using a password rather than PAT to authenticate which didn't work. I guess my GHE server still allows this. Once I switched to a PAT it worked fine. I wouldn't expect you to support authenticating with a password anyways so all good.

The renv.gitcreds.enabled option is great too. I tested that would do the trick without changing my keychain setup and it worked.

@ezraporter
Copy link
Author

Are you able to make use of the existing renv authentication mechanism? See https://rstudio.github.io/renv/articles/package-install.html#authentication for more details.

For anyone not wanting to use the dev version just yet I found this met my needs:

options(renv.auth = function(package, record) {
  if (!is.null(record$RemoteHost) && record$RemoteHost == "GHE_SERVER_URL/api/v3") {
    return(list(GITHUB_PAT = MY_GHE_PAT))
  }
})

@kevinushey
Copy link
Collaborator

Awesome, thanks for confirming! I intend to submit a new version of renv to CRAN soon, so it's good to know this functions as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants