diff --git a/DESCRIPTION b/DESCRIPTION index 6d77274..13317e9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ License: Apache License (>= 2) URL: https://github.com/dominodatalab/DominoDataR Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Imports: arrow, ConfigParser, diff --git a/R/config.R b/R/config.R index 8edb0c9..1698461 100644 --- a/R/config.R +++ b/R/config.R @@ -40,7 +40,8 @@ add_override <- function(..., .override = character()) { add_credentials <- function(auth_type, config = list()) { if (auth_type == "OAuth") { credentials <- load_oauth_credentials( - Sys.getenv("DOMINO_TOKEN_FILE", "/var/lib/domino/home/.api/token") + "DOMINO_API_PROXY", + "/access-token" ) } else if (is.element(auth_type, c("AWSIAMRole", "AWSIAMRoleWithUsername"))) { credentials <- load_aws_credentials( @@ -75,11 +76,24 @@ load_aws_credentials <- function(location, profile = NULL) { #' Load OAuth Credentials #' -#' @param location file path where token is located +#' @param env_var the environment variable name containing the API proxy URL +#' @param path the API endpoint path for retrieving the token #' #' @return named list of override configuration values -load_oauth_credentials <- function(location) { - list( - token = readChar(location, file.info(location)$size) - ) +load_oauth_credentials <- function(env_var, path) { + api_proxy <- Sys.getenv(env_var) + if (api_proxy == "") { + stop(env_var, " environment variable is not set") + } + + url <- paste0(api_proxy, path) + + tryCatch({ + response <- httr::GET(url) + httr::stop_for_status(response) + token <- httr::content(response, "text", encoding = "UTF-8") + list(token = token) + }, error = function(e) { + stop("Failed to retrieve token from ", url, ": ", e$message) + }) } diff --git a/man/datasource_client.Rd b/man/datasource_client.Rd index 1d36047..aef1f11 100644 --- a/man/datasource_client.Rd +++ b/man/datasource_client.Rd @@ -4,7 +4,12 @@ \alias{datasource_client} \title{Create a client to Domino datasources} \usage{ -datasource_client(api_key = NULL, token_file = NULL, token_url = NULL, token = NULL) +datasource_client( + api_key = NULL, + token_file = NULL, + token_url = NULL, + token = NULL +) } \arguments{ \item{api_key}{string key to override the environment variable} diff --git a/man/encode_url_path.Rd b/man/encode_url_path.Rd new file mode 100644 index 0000000..ec25d80 --- /dev/null +++ b/man/encode_url_path.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/http.R +\name{encode_url_path} +\alias{encode_url_path} +\title{Properly escape a URL path} +\usage{ +encode_url_path(url) +} +\arguments{ +\item{url}{URL to properly escape} +} +\value{ +escaped url +} +\description{ +Properly escape a URL path +} +\details{ +Internal only to fix malformed URLs. +} diff --git a/man/load_oauth_credentials.Rd b/man/load_oauth_credentials.Rd index b053ffb..d053994 100644 --- a/man/load_oauth_credentials.Rd +++ b/man/load_oauth_credentials.Rd @@ -4,10 +4,12 @@ \alias{load_oauth_credentials} \title{Load OAuth Credentials} \usage{ -load_oauth_credentials(location) +load_oauth_credentials(env_var, path) } \arguments{ -\item{location}{file path where token is located} +\item{env_var}{the environment variable name containing the API proxy URL} + +\item{path}{the API endpoint path for retrieving the token} } \value{ named list of override configuration values diff --git a/man/make_request.Rd b/man/make_request.Rd new file mode 100644 index 0000000..ca4f55d --- /dev/null +++ b/man/make_request.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/http.R +\name{make_request} +\alias{make_request} +\title{Make the HTTP request} +\usage{ +make_request(verb, url, config, headers, request_body, write_disk) +} +\arguments{ +\item{verb}{A character string containing an HTTP verb} + +\item{url}{Signed URL to download object at.} + +\item{config}{A list of config values for the REST call.} + +\item{headers}{A list of request headers for the REST call.} + +\item{request_body}{A character string containing request body data.} + +\item{write_disk}{An argument like \code{\link[httr]{write_disk}} to +write the result directly to disk.} +} +\value{ +a \code{\link[httr]{response}} object. +} +\description{ +Make the HTTP request +} +\details{ +Internal only to enable retry for malformed URLs. +} diff --git a/man/query.Rd b/man/query.Rd index 72a581f..13c93da 100644 --- a/man/query.Rd +++ b/man/query.Rd @@ -16,7 +16,7 @@ query(client, datasource, query, override = list()) \item{override}{Configuration values to override (\code{\link[=add_override]{add_override()}})} } \value{ -An \link[arrow:Table]{arrow::Table} +An \link[arrow:Table-class]{arrow::Table} } \description{ Query a datasource and returns an arrow Table