Skip to content

Wire USGS_API_KEY for NWIS via Dagster secret#83

Merged
jirhiker merged 1 commit into
mainfrom
feature/nwis-api-key
Jun 26, 2026
Merged

Wire USGS_API_KEY for NWIS via Dagster secret#83
jirhiker merged 1 commit into
mainfrom
feature/nwis-api-key

Conversation

@jirhiker

Copy link
Copy Markdown
Member

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.EnvVarDIEConfigResourceos.environ (in get_config) → backend NWIS connector reads os.environ["USGS_API_KEY"] at request time and sends X-API-Key.

This matches the existing ambient-secret pattern (GCS, GeoServer), and works for the CLI too (--usgs-api-key / USGS_API_KEY env, already supported).

Changes

  • orchestration/definitions.py: DIEConfigResource(usgs_api_key=dg.EnvVar("USGS_API_KEY")) — resolves at run time; None when unset (API still works, just throttled).
  • orchestration/resources/die_config.py: get_config exports the key to os.environ (only when provided — never clobbers an ambient value).
  • backend/connectors/usgs/source.py: DRY the duplicated X-API-Key header 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, including USGS_API_KEY.

Verification

  • Defs load with the key set (flows to env → X-API-Key header) and unset (EnvVarNone, no error).
  • CLI usgs-api-key tests pass (10).

To activate

Set the USGS_API_KEY Dagster+ secret (Deployment → Environment variables), like the other secrets.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
die-orchestration View in Cloud Jun 26, 2026 at 03:44 PM (UTC)

@jirhiker jirhiker merged commit 78e55ca into main Jun 26, 2026
2 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