Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Nov 7, 2018
1 parent ea7f22a commit e9f5a5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions R/ssh.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
my_ssh_key <- function(host = "github.com", ssh = "ssh", password = askpass){
keyfile <- find_ssh_key(host = host, ssh = ssh)
if(is.null(keyfile)){
if(isTRUE(askYesNo("No ssh key found. Generate one? ", default = FALSE,
prompts = c("Yes", "No", "Cancel")))){
if(interactive() && isTRUE(askYesNo("No ssh key found. Generate one?",
FALSE, c("Yes", "No", "Cancel")))){
keyfile <- ssh_home('id_rsa')
ssh_keygen(keyfile, open_github = FALSE)
} else {
Expand All @@ -38,7 +38,7 @@ my_ssh_key <- function(host = "github.com", ssh = "ssh", password = askpass){
openssl::write_ssh(key$pubkey, pubfile)
}
list(
path = keyfile,
key = keyfile,
pubkey = openssl::write_ssh(openssl::read_pubkey(pubfile))
)
}
Expand All @@ -50,15 +50,15 @@ my_ssh_key <- function(host = "github.com", ssh = "ssh", password = askpass){
#' @param open_github automatically open a browser window to let the user
#' add the key to Github.
#' @importFrom openssl write_ssh write_pem read_key write_pkcs1
ssh_keygen <- function(file = ssh_home('id_rsa'), open_github = TRUE){
ssh_keygen <- function(file = ssh_home('id_rsa'), open_github = interactive()){
private_key <- normalizePath(file, mustWork = FALSE)
if(file.exists(private_key)){
cat(sprintf("Found existing RSA keyspair at: %s\n", private_key), file = stderr())
key <- read_key(file)
} else {
cat(sprintf("Generating new RSA keyspair at: %s\n", private_key), file = stderr())
key <- openssl::rsa_keygen()
dir.create(dirname(private_key))
dir.create(dirname(private_key), showWarnings = FALSE)
write_pkcs1(key, private_key)
write_ssh(key$pubkey, paste0(private_key, '.pub'))
}
Expand All @@ -74,7 +74,7 @@ ssh_keygen <- function(file = ssh_home('id_rsa'), open_github = TRUE){
utils::browseURL('https://github.com/settings/ssh/new')
}
list(
path = private_key,
key = private_key,
pubkey = write_ssh(key$pubkey)
)
}
Expand All @@ -83,9 +83,10 @@ ssh_keygen <- function(file = ssh_home('id_rsa'), open_github = TRUE){
#' @rdname ssh_credentials
ssh_home <- function(file = NULL){
if(length(file)){
return(file.path(normalize_home("~/.ssh"), file))
normalizePath(file.path(normalize_home("~/.ssh"), file), mustWork = FALSE)
} else {
normalize_home("~/.ssh")
}
normalize_home("~/.ssh")
}


Expand Down
2 changes: 1 addition & 1 deletion man/ssh_credentials.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9f5a5b

Please sign in to comment.