Development - #70
Merged
Merged
Conversation
Motivating Rationale:
---------------------
Effective Thursday, July 30, 2026, the Environmental Data Initiative (EDI)
repository is transitioning to mandatory authenticated access across all REST
API endpoints. To prevent service disruption for automated pipelines and coded
workflows, this commit adds native support for EDI-API keys to the EDIutils
R package, replacing the reliance on legacy username/password and token-based
(cookie) sessions as the primary authentication method.
Key Changes:
------------
1. Centrally Abstracted Request Wrappers (R/utilities.R):
- Implemented `add_api_key()` to append the private `EDI_API_KEY` value
to request URLs as the query parameter `?key=` (or `&key=`).
- Replaced direct `httr::GET`, `httr::POST`, `httr::PUT`, and `httr::DELETE`
invocations across 67 repository wrapper functions with secure internal
wrappers: `api_get()`, `api_post()`, `api_put()`, and `api_delete()`.
2. Authentication Logic Upgrades (R/login.R & R/logout.R):
- Updated `login()` to support credentials file mapping, interactive console
inputs, or a new direct `key` function argument.
- Fixed `login()`'s return value to return `NULL` (invisibly) and set the
respective environment variables.
- Updated `logout()` to unset the `EDI_API_KEY` environment variable.
3. Testing Enhancements & Security Safeguards:
- Updated `skip_if_logged_out()` to allow running tests when `EDI_API_KEY`
is set, but skipped heavy tests unless `RUN_ALL_TESTS` is set to 'true'.
- Added `is_vcr_replaying()` to detect active cassette playback. This
ensures we skip appending query keys during mock replays, preserving
compatibility with existing cassettes.
- Configured `vcr::vcr_configure` with a dynamic `filter_sensitive_data`
list to automatically scrub the actual `EDI_API_KEY` value and replace it
with `<<edi_api_key>>` before cassettes are saved, preventing accidental
private key exposure on GitHub.
- Refactored `bake_cookie()` to return `httr::config()` when an API key is
present instead of throwing an "Authentication token not found" error,
resolving a critical key-only authentication edge case.
- Added unit test assertions to `tests/testthat/test_utilities.R` verifying
`add_api_key()`, `login(key = "...")`, and `logout()` behavior.
4. Documentation Updates:
- Refreshed Rd help manuals and NAMESPACE exports via `devtools::document()`.
- Updated `README.Rmd` and vignettes (`evaluate_and_upload.Rmd`,
`retrieve_downloads.Rmd`, `tests_requiring_authentication.Rmd`) to detail
API key setup, environmental configuration, and mandatory authentication.
- Documented changes in the version 2.2.0 changelog of `NEWS.md`.
- Refactored bake_cookie() to ignore the fake mock 'foobar' EDI_TOKEN if a valid EDI_API_KEY is present, preventing the server from rejecting live authenticated requests with 401 token validation errors under devtools::test(). - Added unit tests for bake_cookie() under various mock/live variable states.
…sts workflow - Integrated the new EDI_API_KEY secret into both jobs in .github/workflows/check-standard-real-requests.yaml. - Set RUN_ALL_TESTS: true so the live, real-request workflow executes the full package test suite against the live staging repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.