diff --git a/DESCRIPTION b/DESCRIPTION index e7efce62..cad3dc11 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: opencpu Title: Producing and Reproducing Results -Version: 2.0.5 +Version: 2.0.5.9000 Author: Jeroen Ooms Maintainer: Jeroen Ooms License: Apache License 2.0 diff --git a/NEWS b/NEWS index 2fd9a76f..5643dee9 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +2.0.6 + - Fix Github auth in webhook (either use /etc/opencpu/secret.conf or GITHUB_PAT envvar) + 2.0.5 - Fix bug where only the first package would actually get preloaded - The /ocpu/info API shows some additional config/system info diff --git a/R/github.R b/R/github.R index 37327f39..aeded78b 100644 --- a/R/github.R +++ b/R/github.R @@ -21,7 +21,12 @@ github_userlib <- function(gituser, gitrepo){ github_package_info <- function(repo){ tryCatch({ url <- sprintf("https://raw.githubusercontent.com/%s/master/DESCRIPTION", repo) - con <- curl::curl(url) + handle <- curl::new_handle() + token <- github_token() + if(length(token)){ + curl::handle_setheaders(handle, Authorization = paste("token", token)) + } + con <- curl::curl(url, handle = handle) on.exit(close(con)) out <- as.list(as.data.frame(read.dcf(con), stringsAsFactors = FALSE)) }, error = function(e){ @@ -50,9 +55,9 @@ github_install <- function(repo, username, ref, args = NULL, upgrade_dependencie package <- app_info$package #Override auth_token if set in key - mysecret <- gitsecret() - if(length(mysecret) && length(mysecret$auth_token) && nchar(mysecret$auth_token)){ - all_args$auth_token = mysecret$auth_token + token <- github_token() + if(length(token)){ + all_args$auth_token = token } # Create the Rscript call diff --git a/R/secret.R b/R/secret.R index 59d9188a..4383f35d 100644 --- a/R/secret.R +++ b/R/secret.R @@ -4,5 +4,18 @@ gitsecret <- function(){ as.list(fromJSON(secretfile)); }, error=function(e){ return(NULL) - }); + }) +} + +github_token <- function(){ + # Method 1: secret file + token <- gitsecret()$auth_token + if(length(token) && nchar(token)){ + return(token) + } + # Method 2: env var + pat <- Sys.getenv("GITHUB_PAT") + if(nchar(pat)) + return(pat) + NULL }