Skip to content

Development - #70

Merged
clnsmth merged 6 commits into
mainfrom
development
Jul 28, 2026
Merged

Development#70
clnsmth merged 6 commits into
mainfrom
development

Conversation

@clnsmth

@clnsmth clnsmth commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

No description provided.

clnsmth added 6 commits July 27, 2026 14:48
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.
@clnsmth
clnsmth merged commit 0a69599 into main Jul 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant