Skip to content

Commit

Permalink
refactor: update gargle functions (#265)
Browse files Browse the repository at this point in the history
* bump version, add to NEWS

* replace with exported functions from gargle

* use base warning() for now

* use BOXR_KEY

* update workflow
  • Loading branch information
ijlyttle authored Feb 3, 2024
1 parent 19e6cf7 commit d75d99a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
# these are the only local adaptations needed
BOXR_PASSWORD: ${{ secrets.BOXR_PASSWORD }}
BOXR_KEY: ${{ secrets.BOXR_KEY }}
BOXR_USE_TOKEN: ${{ matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release' }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: boxr
Type: Package
Title: Interface for the 'Box.com API'
Version: 0.3.6.9009
Version: 0.3.6.9010
Authors@R: c(
person("Brendan", "Rocks", email = "foss@brendanrocks.com",
role = c("aut")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

## Internal

* update superseded function-calls from gargle, used in testing. (#251)

* default branch switched from `master` to `main`. (#252)

* refactor to use withr functions to handle temp files. (#183)
Expand Down
Binary file modified inst/secret/boxr-testing.json
Binary file not shown.
23 changes: 20 additions & 3 deletions tests/testthat/setup_auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@
#
use_token <- identical(Sys.getenv("BOXR_USE_TOKEN"), "true")

if (use_token && gargle:::secret_can_decrypt("boxr")) {
raw <- gargle:::secret_read("boxr", "boxr-testing.json")
text <- rawToChar(raw)
path_secret <- system.file("secret", "boxr-testing.json", package = "boxr")
env_secret <- "BOXR_KEY"

# NOTE 2024-01-07:
# - the key used with the deprecated gargle functions had 50 characters
# - the new gargle functions can accept a key max 32 characters
# - if you have an old "BOXR_PASSWORD", truncate it to use the first 32 chars

if (gargle::secret_has_key("BOXR_PASSWORD")) {
# TODO: replace with cli::cli_alert_warning()
warning(
paste(
"You are using an obselete credential `BOXR_PASSWORD`.",
"Truncate to use the first 32 characters, and rename as `BOXR_KEY`."
)
)
}

if (use_token && gargle::secret_has_key(env_secret)) {
text <- gargle::secret_decrypt_json(path_secret, env_secret)
box_auth_service(token_text = text)
}

11 changes: 7 additions & 4 deletions tests/testthat/test_01_oauth.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ context("OAuth2.0 via JWT")
# these two tests are useful for debugging gargle and its relation to the Travis CI environment
# they are not relevant to boxr beyond that

# path_secret <- system.file("secret", "boxr-testing.json", package = "boxr")
# env_secret <- "BOXR_KEY"
#
# test_that("gargle can find secret", {
# expect_true(gargle:::secret_can_decrypt("boxr"))
# expect_true(gargle::secret_has_key(env_secret))
# })
#
# test_that("gargle can read secret", {
# json <- gargle:::secret_read("boxr", "boxr-testing.json")
# expect_type(json, "raw")
# expect_true(length(json) > 50)
# text <- gargle::secret_decrypt_json(path_secret, env_secret)
# expect_true(inherits("x", "character"))
# expect_true(nchar(text) > 50)
# })


Expand Down

0 comments on commit d75d99a

Please sign in to comment.