Skip to content

Commit 70fe9f2

Browse files
authored
Merge pull request #137 from Kaggle/feat-iap
Pass IAP token if present for requests from R container
2 parents cedb363 + 517d54e commit 70fe9f2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

kaggle/kaggle_bigquery.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
KAGGLE_USER_SECRETS_TOKEN <- Sys.getenv("KAGGLE_USER_SECRETS_TOKEN")
1212
KAGGLE_BASE_URL <- Sys.getenv("KAGGLE_URL_BASE")
13+
KAGGLE_IAP_TOKEN <- Sys.getenv("KAGGLE_IAP_TOKEN")
1314
GET_USER_SECRET_ENDPOINT = "/requests/GetUserSecretRequest"
1415

1516
# We create a Token2.0 Credential object (from httr library) and use bigrquery's set_access_cred
@@ -29,7 +30,12 @@ TokenBigQueryKernel <- R6::R6Class("TokenBigQueryKernel", inherit = Token2.0, li
2930
}
3031
request_body <- list(Target = 1)
3132
auth_header <- paste0("Bearer ", KAGGLE_USER_SECRETS_TOKEN)
32-
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header))
33+
if (KAGGLE_IAP_TOKEN != '') {
34+
iap_auth_header <- paste0("Bearer ", KAGGLE_IAP_TOKEN)
35+
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header, "Authorization" = iap_auth_header))
36+
} else {
37+
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header))
38+
}
3339
response <- POST(paste0(KAGGLE_BASE_URL, GET_USER_SECRET_ENDPOINT),
3440
headers,
3541
# Reset the cookies on each request, since the server expects none.

kaggle/kaggle_secrets.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
get_user_secret <- function(label) {
99
KAGGLE_USER_SECRETS_TOKEN <- Sys.getenv("KAGGLE_USER_SECRETS_TOKEN")
1010
KAGGLE_BASE_URL <- Sys.getenv("KAGGLE_URL_BASE")
11+
KAGGLE_IAP_TOKEN <- Sys.getenv("KAGGLE_IAP_TOKEN")
1112
GET_USER_SECRET_BY_LABEL_ENDPOINT = "/requests/GetUserSecretByLabelRequest"
1213

1314
if (KAGGLE_USER_SECRETS_TOKEN == '') {
1415
stop("Expected KAGGLE_USER_SECRETS_TOKEN environment variable to be present.", call. = FALSE)
1516
}
1617
request_body <- list(Label = label)
1718
auth_header <- paste0("Bearer ", KAGGLE_USER_SECRETS_TOKEN)
18-
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header))
19+
if (KAGGLE_IAP_TOKEN != '') {
20+
iap_auth_header <- paste0("Bearer ", KAGGLE_IAP_TOKEN)
21+
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header, "Authorization" = iap_auth_header))
22+
} else {
23+
headers <- add_headers(c("X-Kaggle-Authorization" = auth_header))
24+
}
1925
response <- POST(
2026
paste0(KAGGLE_BASE_URL, GET_USER_SECRET_BY_LABEL_ENDPOINT),
2127
headers,
@@ -31,4 +37,4 @@ get_user_secret <- function(label) {
3137
}
3238
response_body <- content(response)
3339
return(response_body$result$secret)
34-
}
40+
}

0 commit comments

Comments
 (0)