Skip to content

Commit

Permalink
Fix auth_token
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Oct 27, 2017
1 parent 0e40642 commit 882dcd0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 <jeroen@berkeley.edu>
License: Apache License 2.0
Expand Down
3 changes: 3 additions & 0 deletions 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
Expand Down
13 changes: 9 additions & 4 deletions R/github.R
Expand Up @@ -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){
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion R/secret.R
Expand Up @@ -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
}

0 comments on commit 882dcd0

Please sign in to comment.