Skip to content

CRED-2151: Add PAT auth support to Ruby API client#3058

Draft
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2151-ruby-pat-auth
Draft

CRED-2151: Add PAT auth support to Ruby API client#3058
tausman wants to merge 2 commits intomasterfrom
tausman/cred-2151-ruby-pat-auth

Conversation

@tausman
Copy link

@tausman tausman commented Mar 4, 2026

Why

Adds Personal Access Token (PAT) auth support to the Ruby API client. PATs authenticate via the Authorization: Bearer <PAT> header. The OpenAPI spec now defines bearerAuth as a proper security scheme with x-env-name: DD_BEARER_TOKEN, so this change enables the generator to handle it automatically.

Behavior

When DD_BEARER_TOKEN is set (or config.access_token is set programmatically), the Authorization: Bearer <token> header is sent alongside any configured API key and app key headers. Auth methods are not mutually exclusive — all configured headers are sent, and the server uses whichever is valid.

  • DD_BEARER_TOKEN set → sends Authorization: Bearer <token>
  • DD_API_KEY set → sends DD-API-KEY header
  • DD_APP_KEY set → sends DD-APPLICATION-KEY header
  • All three can be sent simultaneously

Summary

Generator templates (.generator/src/generator/templates/):

  • configuration.j2: Uncommented the bearerAuth block so bearer auth is auto-generated from the OpenAPI spec. Added env var loading for http/bearer type security schemes (picks up DD_BEARER_TOKEN from x-env-name).
  • api_client.j2: Added nil/empty value guard to skip auth settings with no configured value. Added Authorization to redacted headers in debug output.

Generated files (matching template output):

  • lib/datadog_api_client/configuration.rb: bearerAuth entry in auth_settings using the existing access_token attribute. Loads DD_BEARER_TOKEN env var into @access_token.
  • lib/datadog_api_client/api_client.rb: Skips auth entries with nil/empty values. Redacts Authorization header in debug logs.

Tests:

  • spec/api_client_spec.rb: Tests that all configured auth headers are sent simultaneously. Tests bearer-only and API+app-key-only scenarios. Tests Authorization header redaction.
  • spec/configuration_spec.rb: Tests access_token defaults, direct setting, DD_BEARER_TOKEN env var loading, and bearerAuth auth_settings entries.

Test plan

  • Unit tests pass (35 examples, 0 failures)
  • Live verification against staging (api.datad0g.com): Bearer auth returns HTTP 200
  • No secrets/credentials in committed files
  • Env var is DD_BEARER_TOKEN matching OpenAPI spec x-env-name

PR Stack

API Client Libraries

OpenAPI Spec Changes

@tausman tausman force-pushed the tausman/cred-2151-ruby-pat-auth branch from 9dfda24 to 027cc15 Compare March 5, 2026 00:12
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