Wire USGS_API_KEY for NWIS via Dagster secret#83
Merged
Conversation
The USGS/NWIS water data API is heavily rate-limited without an API key.
Make the key flow from a Dagster+ secret to the NWIS connector:
- definitions.py: DIEConfigResource(usgs_api_key=EnvVar("USGS_API_KEY")) —
resolves the secret at run time (None when unset; API still works,
just throttled).
- die_config.py: get_config exports the key to os.environ so the backend
NWIS connector (reads os.environ["USGS_API_KEY"] at request time) picks
it up. Only sets when provided, never clobbers an ambient value.
- usgs/source.py: DRY the duplicated X-API-Key header logic into a
_usgs_headers() helper used by all three request sites.
- AGENTS.md: document the Dagster+ secrets, including USGS_API_KEY.
Verified defs load with the key set and unset; CLI usgs-api-key tests
pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Your pull request is automatically being deployed to Dagster Cloud.
|
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.
What
Make the USGS/NWIS API key flow from a Dagster+ secret to the NWIS connector. Without a key the USGS water data API is heavily rate-limited.
How it flows
USGS_API_KEY(Dagster+ secret) →dg.EnvVar→DIEConfigResource→os.environ(inget_config) → backend NWIS connector readsos.environ["USGS_API_KEY"]at request time and sendsX-API-Key.This matches the existing ambient-secret pattern (GCS, GeoServer), and works for the CLI too (
--usgs-api-key/USGS_API_KEYenv, already supported).Changes
orchestration/definitions.py:DIEConfigResource(usgs_api_key=dg.EnvVar("USGS_API_KEY"))— resolves at run time;Nonewhen unset (API still works, just throttled).orchestration/resources/die_config.py:get_configexports the key toos.environ(only when provided — never clobbers an ambient value).backend/connectors/usgs/source.py: DRY the duplicatedX-API-Keyheader logic into a_usgs_headers()helper used by all three request sites (health, site fetch, water-level POST).orchestration/AGENTS.md: document the Dagster+ secrets, includingUSGS_API_KEY.Verification
X-API-Keyheader) and unset (EnvVar→None, no error).usgs-api-keytests pass (10).To activate
Set the
USGS_API_KEYDagster+ secret (Deployment → Environment variables), like the other secrets.🤖 Generated with Claude Code