Skip to content

fix(client): fix OAuth2 authentication for logs commands#133

Draft
robhughadams wants to merge 1 commit intodatadog-labs:mainfrom
robhughadams:refactor/unified-oauth-middleware
Draft

fix(client): fix OAuth2 authentication for logs commands#133
robhughadams wants to merge 1 commit intodatadog-labs:mainfrom
robhughadams:refactor/unified-oauth-middleware

Conversation

@robhughadams
Copy link
Contributor

Summary

Fix OAuth2 bearer token authentication for logs commands by implementing unified middleware-based token injection in the forked datadog-api-client-rust. Refactors all 34 command modules to use a single make_dd_client() function, eliminating dual-path bearer auth logic and fixing issue #72 ("Can't query logs with OAuth").

Changes

Fork (robhughadams/datadog-api-client-rust):

  • src/datadog/middleware.rs (new): Implements BearerTokenMiddleware to inject bearer tokens at the HTTP middleware layer
  • src/datadog/configuration.rs: Added bearer_token: Option<String> field, set_bearer_token() setter, and DD_ACCESS_TOKEN env var support
  • src/datadog/mod.rs: Exported BearerTokenMiddleware
  • Cargo.toml: Added async-trait and task-local-extensions dependencies

pup refactor (34 command modules):

  • src/client.rs: Removed BearerAuthMiddleware and make_bearer_client(); added make_dd_client() that always returns ClientWithMiddleware with bearer middleware attached when token present; removed 11 endpoints from OAUTH_EXCLUDED_ENDPOINTS (logs endpoints no longer need exclusion)
  • src/commands/logs.rs: Simplified search() and aggregate() by removing raw HTTP bearer fallback; added storage: Option<String> parameter to search/list/query/aggregate commands for Flex Storage support
  • src/main.rs: Updated log command routing to pass storage argument through to all dispatch sites
  • All 34 command modules: Replaced 155 dual-path bearer auth patterns with single make_dd_client() call
  • Cargo.toml: Updated [patch.crates-io] to use remote fork: git = "https://github.com/robhughadams/datadog-api-client-rust", branch = "master"

Build verification:cargo build passes with remote fork dependency

Related Issues

Closes #72


Branch: refactor/unified-oauth-middleware
Fork: https://github.com/robhughadams/datadog-api-client-rust

Fixes OAuth2 authentication for logs search, list, query, and aggregate commands
by moving bearer token injection into a shared middleware layer and removing
the incorrect exclusion of logs endpoints from OAuth support (closes datadog-labs#72).

Implementation:
- Add BearerTokenMiddleware to fork of datadog-api-client-rust for uniform
  bearer token injection across all commands
- Replace 155 dual-path make_bearer_client()/with_config() patterns with
  single with_client_and_config(dd_cfg, make_dd_client(cfg)) call
- Remove logs endpoints from OAUTH_EXCLUDED_ENDPOINTS (52→41 patterns)
- Simplify logs search() and aggregate(): remove raw HTTP bearer fallback
- Add --storage parameter wired to LogsStorageTier enum for all log commands
- Update [patch.crates-io] to point at robhughadams/datadog-api-client-rust fork

Commit Stats:
- 41 files changed, 2973 insertions(+), 807 deletions(-)
- 334 lines net reduction (from 807 deletions - 473 additions)
- All 4 validation checks pass: cargo build, cargo fmt, cargo clippy, binary test

Co-Authored-By: Robert Adams <robhughadams@gmail.com>
@robhughadams
Copy link
Contributor Author

This PR requires DataDog/datadog-api-client-rust#1288 to be merged so that the mainstream DD client can be used before review.

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.

[BUG] Can't query logs with OAuth

1 participant