From 99bd6b97d9818320611409b9c79afb7daf7938fe Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 24 Dec 2024 11:16:49 -0600 Subject: [PATCH] Look for secrets in keyring too * [ ] Update vignette Fixes #346 --- DESCRIPTION | 1 + R/secret.R | 7 +++++++ tests/testthat/test-curl.R | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a6d4cd51..150c75d19 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,6 +36,7 @@ Suggests: httpuv, jose, jsonlite, + keyring, knitr, later (>= 1.4.0), paws.common, diff --git a/R/secret.R b/R/secret.R index e0f9cf95e..4a41e21c4 100644 --- a/R/secret.R +++ b/R/secret.R @@ -160,6 +160,13 @@ secret_has_key <- function(key) { } secret_get_key <- function(envvar, call = caller_env()) { + if (is_installed("keyring")) { + key <- tryCatch(keyring::key_get(envvar), error = function(e) NULL) + if (!is.null(key)) { + return(key) + } + } + key <- Sys.getenv(envvar) if (identical(key, "")) { diff --git a/tests/testthat/test-curl.R b/tests/testthat/test-curl.R index 225983a41..53355ed00 100644 --- a/tests/testthat/test-curl.R +++ b/tests/testthat/test-curl.R @@ -134,7 +134,7 @@ test_that("can translate data", { expect_snapshot({ curl_translate("curl http://example.com --data abcdef") - curl_translate("curl http://example.com --data abcdef -H Content-Type:text/plain") + curl_translate("curl http://example.com --data abcdef -H Content-Type:text/plain") |> }) })