Skip to content

CRED-2150: Add PAT auth support to Rust API client#1310

Open
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2150-rust-pat-auth
Open

CRED-2150: Add PAT auth support to Rust API client#1310
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2150-rust-pat-auth

Conversation

@tausman
Copy link

@tausman tausman commented Mar 4, 2026

Why

Add Personal Access Token (PAT) authentication support to the Rust API client (CRED-2150). PATs allow authenticating via an Authorization: Bearer <PAT> header, providing an alternative to the traditional DD-API-KEY + DD-APPLICATION-KEY header pair.

Behavior

  • When DD_BEARER_TOKEN is set (or set_pat() is called), the Authorization: Bearer <token> header is sent alongside any configured API key and app key headers.
  • Auth methods are NOT mutually exclusive — all configured credentials are sent, and the server uses whichever is valid.
  • DD_BEARER_TOKEN aligns with the OpenAPI spec's bearerAuth security scheme (x-env-name: DD_BEARER_TOKEN).

Commit structure

This PR has 2 commits for easier review:

  1. CRED-2150: Add PAT auth support - templates and tests — Template changes (.generator/src/generator/templates/*.j2) + integration tests (tests/configuration_test.rs). Review this commit.
  2. CRED-2150: Regenerated client code from templates — All generated files in src/ (132 files). Large diff produced by the generator — can skip review.

Summary of changes

  • Generator templates (api.j2, configuration.j2): Bearer auth support is spec-driven — conditioned on bearerAuth being present in the OpenAPI securitySchemes, with the env var name read from x-env-name. No hardcoded env var names.
  • Configuration struct (src/datadog/configuration.rs): Added pat: Option<String> field, set_pat() method, and auth_headers() method that returns all configured auth headers (bearer + API key + app key).
  • All generated API files (131 files): Replaced inline per-scheme auth header insertion with a centralized configuration.auth_headers() call.
  • DD_BEARER_TOKEN env var: When set to a non-empty value, the bearer token is included in requests. An empty value is ignored.
  • Tests moved from generated configuration.rs to tests/configuration_test.rs so they survive regeneration.

Test plan

  • 6 integration tests covering set_pat(), auth_headers(), env var handling, and coexistence of bearer + API key auth
  • Live verification against staging (api.datad0g.com) using Authorization: Bearer with a real PAT
  • Template changes are spec-driven (no hardcoded env var names)

PR Stack

API Client Libraries

OpenAPI Spec Changes

@tausman tausman force-pushed the tausman/cred-2150-rust-pat-auth branch from 5605e45 to 844fd9c Compare March 5, 2026 16:56
@tausman tausman marked this pull request as ready for review March 5, 2026 18:43
@tausman tausman requested review from a team as code owners March 5, 2026 18:43
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