Skip to content

Commit a95e60b

Browse files
author
Bart
committed
Make sure there is a fall back on the anonymous key and use the secret in regular checks
1 parent 7e36ba5 commit a95e60b

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

.github/workflows/regular-checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
2323

2424
env:
25+
getRad_nl_api_key: ${{ secrets.GETRAD_NL_API_KEY }}
2526
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2627
R_KEEP_PKG_SOURCE: yes
2728

tests/testthat/test-get_pvol_nl.R

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ test_that("Pvol for the Netherlands can be downloaded", {
22
skip_if(Sys.which("KNMI_vol_h5_to_ODIM_h5") == "")
33
skip_if_offline(host = "api.dataplatform.knmi.nl")
44

5-
# make sure local env is used by keyring so that api key can be set
6-
withr::local_options(list(
7-
"keyring_backend" = "env"
8-
))
9-
# get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
10-
withr::local_envvar(
11-
list(
12-
"getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
5+
# First see if a key can be retrieved if not make sure env is used as a keyring backend
6+
if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) {
7+
withr::local_options(list(
8+
"keyring_backend" = "env"
9+
))
10+
}
11+
# If no key can be retrieved from the current backend set the key to the anonymous key of KNMI
12+
if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) {
13+
# get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
14+
withr::local_envvar(
15+
list(
16+
"getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
17+
)
1318
)
14-
)
19+
}
1520
time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki")
1621
pvol <- expect_s3_class(get_pvol("nlhrw", time, param = "all"), "pvol")
1722
expect_true(bioRad::is.pvol(pvol))
@@ -27,9 +32,24 @@ test_that("Pvol for the Netherlands can be downloaded. Incorrect converter resul
2732

2833
# make sure local env is used by keyring so that api key can be set
2934
withr::local_options(list(
30-
"keyring_backend" = "env",
3135
"getRad.nl_converter" = "ls"
3236
))
37+
38+
# First see if a key can be retrieved if not make sure env is used as a keyring backend
39+
if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) {
40+
withr::local_options(list(
41+
"keyring_backend" = "env"
42+
))
43+
}
44+
# If no key can be retrieved from the current backend set the key to the anonymous key of KNMI
45+
if (rlang::is_error(rlang::catch_cnd(getRad::get_secret("nl_api_key")))) {
46+
# get public key here https://developer.dataplatform.knmi.nl/open-data-api#token
47+
withr::local_envvar(
48+
list(
49+
"getRad_nl_api_key" = "eyJvcmciOiI1ZTU1NGUxOTI3NGE5NjAwMDEyYTNlYjEiLCJpZCI6ImVlNDFjMWI0MjlkODQ2MThiNWI4ZDViZDAyMTM2YTM3IiwiaCI6Im11cm11cjEyOCJ9"
50+
)
51+
)
52+
}
3353
time <- as.POSIXct("2024-4-4 20:00:00", tz = "Europe/Helsinki")
3454
expect_error(
3555
get_pvol("nlhrw", time, param = "all"),

0 commit comments

Comments
 (0)