diff --git a/.gitignore b/.gitignore index a723f3b..c025b7c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .RData test.R .httr-oauth -secret.json \ No newline at end of file +service_account\.json +client_secret\.json \ No newline at end of file diff --git a/R/k8s_auth.R b/R/k8s_auth.R index b78eac5..89c1fad 100644 --- a/R/k8s_auth.R +++ b/R/k8s_auth.R @@ -2,17 +2,28 @@ #' #' Calls googleAuthR to authenticate with the Google Cloud Platform #' @keywords k8s_auth -#' @param json Path to your json client_secret credentials. +#' @param json OPTIONAL Path to your JSON client_secret credentials. +#' @param service_account_json OPTIONAL Path to your JSON service account credentials #' @importFrom googleAuthR gar_auth #' @export #' @examples #' k8s_auth() #' k8s_auth(json = "client_secret.json") +#' k8s_auth(service_account_json = "service_account.json") -k8s_auth <- function(json = NULL) { - if(is.null(json)) { +k8s_auth <- function(json = NULL, service_account_json = NULL) { + + if(!is.null(json)) { + # If json client ID credentials are provided, use gar_set_client() to set the credentials + googleAuthR::gar_set_client(json) + } + + if(is.null(service_account_json)) { + # If no service token provided, use gar_auth() googleAuthR::gar_auth() } else { - googleAuthR::gar_set_client(json) + # Else use gar_auth_service() + googleAuthR::gar_auth_service(service_account_json) } + } diff --git a/man/k8s_auth.Rd b/man/k8s_auth.Rd index 73f4639..5692fa8 100644 --- a/man/k8s_auth.Rd +++ b/man/k8s_auth.Rd @@ -4,10 +4,12 @@ \alias{k8s_auth} \title{k8s_auth} \usage{ -k8s_auth(json = NULL) +k8s_auth(json = NULL, service_account_json = NULL) } \arguments{ -\item{json}{Path to your json client_secret credentials.} +\item{json}{OPTIONAL Path to your JSON client_secret credentials.} + +\item{service_account_json}{OPTIONAL Path to your JSON service account credentials} } \description{ Calls googleAuthR to authenticate with the Google Cloud Platform @@ -15,5 +17,6 @@ Calls googleAuthR to authenticate with the Google Cloud Platform \examples{ k8s_auth() k8s_auth(json = "client_secret.json") +k8s_auth(service_account_json = "service_account.json") } \keyword{k8s_auth}