Skip to content

Commit

Permalink
change setup for getting proof auth token getwilds/proofr#2
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 31, 2024
1 parent efa1b07 commit d14d157
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions R/http.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#' @keywords internal
#' @author Scott Chamberlain
http_get <- function(url, as = NULL, ...) {
result <- httr::GET(url, ...)
result <- httr::GET(url, try_proof_header(), ...)
httr::stop_for_status(result)
httr::content(result, as = as)
}

http_post <- function(url, as = NULL, ...) {
result <- httr::POST(url, ...)
result <- httr::POST(url, try_proof_header(), ...)
httr::stop_for_status(result)
httr::content(result, as = as)
}
Expand All @@ -24,8 +24,20 @@ check_url <- function() {
x <- Sys.getenv("CROMWELLURL")
if (identical(x, "")) {
stop("Set the env var `CROMWELLURL`. ",
"See ?cromwellSettings",
"See ?cromwell_settings",
call. = FALSE
)
}
}

#' Get header for PROOF API calls
#'
#' @keywords internal
#' @return A `request` S3 class with the HTTP header that can be passed
#' to `httr::GET()`, `httr::POST()`, etc.
try_proof_header <- function() {
token <- Sys.getenv("PROOF_TOKEN", "")
if (nzchar(token) && nchar(token) > 30) {
httr::add_headers(Authorization = paste0("Bearer ", token))
}
}
16 changes: 16 additions & 0 deletions man/try_proof_header.Rd

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

0 comments on commit d14d157

Please sign in to comment.