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

Use cached gitcreds, if available #106

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -25,6 +25,7 @@ Imports:
rstudioapi (>= 0.11),
zip (>= 2.1.0)
Suggests:
gitcreds,
spelling,
knitr,
rmarkdown,
Expand Down
9 changes: 9 additions & 0 deletions R/credentials.R
Expand Up @@ -48,6 +48,15 @@ make_cred_cb <- function(password = askpass, verbose = TRUE){
if(nchar(github_pat) > 0 && grepl('^https?://([^/]*@)?github.com', url)){
return(c("git", github_pat))
}

# Try looking for (cached) gitcreds, mainly to support GHE
# This should never cause a prompt! It either returns creds or errors.
if(requireNamespace('gitcreds', quietly = TRUE)){
creds <- tryCatch(gitcreds::gitcreds_get(url, set_cache = FALSE), error = function(e){})
Copy link
Member

Choose a reason for hiding this comment

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

Seems like allowing set_cache = TRUE (the default) would be OK or maybe even desirable?

Copy link
Member Author

@jeroen jeroen Nov 21, 2020

Choose a reason for hiding this comment

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

I'm a bit worried about saving any password found in the store as plain text env-var, as a side effect of pushing to git. My intention was just to use the GITHUB_PAT_BERKELEY_EDU variable if it exists.

if(length(creds) && length(creds$username)){
return(c(creds$username, creds$password))
}
}
}

# Retrieve a password from the credential manager
Expand Down