diff --git a/R/DataConnection.R b/R/DataConnection.R index 821bcdc0b..600a7b2f6 100644 --- a/R/DataConnection.R +++ b/R/DataConnection.R @@ -904,6 +904,7 @@ teradata_connection <- function(open_args = list(), close_args = list(), ping_ar #' @param server the `Snowflake`server to connect to. #' @param port the port to connect to the `Snowflake` instance. #' @param driver the driver to use to connect to the `Snowflake` instance. +#' @param token_provider location of the auth token provider needed to access `Snowflake`. #' @export snowflake_connection_function <- function(username = askpass::askpass("Please enter your username"), password = askpass::askpass("Please enter your password"), @@ -911,11 +912,12 @@ snowflake_connection_function <- function(username = askpass::askpass("Please en database, schema, warehouse, - server = "roche_pd.eu-central-1.snowflakecomputing.com", + server, port = 443, - driver = "SnowflakeDSIIDriver") { + driver = "SnowflakeDSIIDriver", + token_provider) { - res <- httr::POST("https://wam.roche.com/as/token.oauth2", + res <- httr::POST(token_provider, body = list( client_id = "snowflake", grant_type = "password", @@ -948,7 +950,7 @@ snowflake_connection_function <- function(username = askpass::askpass("Please en Warehouse = warehouse, role = role, authenticator = \"oauth\", - token = token")), + token = token)")), error = function(cond){ stop(paste("Unable to connect to snowflake. Error message:", cond$message), call. = FALSE) } @@ -988,6 +990,14 @@ snowflake_connection <- function(open_args = list(), close_args = list(), ping_a stopifnot(is_fully_named_list(close_args)) stopifnot(is_fully_named_list(ping_args)) + if (!all(c("server", "token_provider") %in% names(open_args))) { + stop("When using a snowflake connection function + you must give the location of the snowflake server and auth token provider. + See 'help(snowflake_data)' for an example. + Please consult your internal documentation/support team for your server and token provider locations.") + } + + open_fun <- callable_function("teal::snowflake_connection_function") open_fun$set_args(open_args) diff --git a/R/RelationalDataConnector_constructors.R b/R/RelationalDataConnector_constructors.R index 2d38f8244..c1cd59c3e 100644 --- a/R/RelationalDataConnector_constructors.R +++ b/R/RelationalDataConnector_constructors.R @@ -372,6 +372,9 @@ teradata_data <- function(..., connection = teradata_connection()) { #' #' @return An object of class \code{RelationalDataConnector} #' +#' @details Note the server location and token_provider must be provided as arguments to +#' the snowflake_connection function, see example below. +#' #' @examples #' \dontrun{ #' library(magrittr) @@ -382,6 +385,8 @@ teradata_data <- function(..., connection = teradata_connection()) { #' ) %>% mutate_dataset("any mutations required, e.g. to convert data types"), #' connection = snowflake_connection( #' open_args = list( +#' server = "<>", +#' token_provider = "<>", #' role = "role", #' database = "database", #' schema = "schema", diff --git a/man/snowflake_connection_function.Rd b/man/snowflake_connection_function.Rd index 24a24ab78..fa262f2f7 100644 --- a/man/snowflake_connection_function.Rd +++ b/man/snowflake_connection_function.Rd @@ -11,9 +11,10 @@ snowflake_connection_function( database, schema, warehouse, - server = "roche_pd.eu-central-1.snowflakecomputing.com", + server, port = 443, - driver = "SnowflakeDSIIDriver" + driver = "SnowflakeDSIIDriver", + token_provider ) } \arguments{ @@ -34,6 +35,8 @@ snowflake_connection_function( \item{port}{the port to connect to the \code{Snowflake} instance.} \item{driver}{the driver to use to connect to the \code{Snowflake} instance.} + +\item{token_provider}{location of the auth token provider needed to access \code{Snowflake}.} } \description{ This is used by \code{snowflake_connection} and does not need to be called directly diff --git a/man/snowflake_data.Rd b/man/snowflake_data.Rd index 612f64a60..6b9625c30 100644 --- a/man/snowflake_data.Rd +++ b/man/snowflake_data.Rd @@ -18,6 +18,10 @@ An object of class \code{RelationalDataConnector} \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} Build data connector for \code{SNOWFLAKE} functions or datasets } +\details{ +Note the server location and token_provider must be provided as arguments to +the snowflake_connection function, see example below. +} \examples{ \dontrun{ library(magrittr) @@ -28,6 +32,8 @@ data <- snowflake_data( ) \%>\% mutate_dataset("any mutations required, e.g. to convert data types"), connection = snowflake_connection( open_args = list( + server = "<>", + token_provider = "<>", role = "role", database = "database", schema = "schema",