-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove dummy auth & add trace header #10678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Remove dummy auth from SDK setup |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Add `WRANGLER_TRACE_ID` environment variable to support internal testing |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,10 @@ import assert from "node:assert"; | |||||||||||||||
| import Cloudflare from "cloudflare"; | ||||||||||||||||
| import { fetch, FormData, Headers, Request, Response } from "undici"; | ||||||||||||||||
| import { version as wranglerVersion } from "../../package.json"; | ||||||||||||||||
| import { getCloudflareApiBaseUrl } from "../environment-variables/misc-variables"; | ||||||||||||||||
| import { | ||||||||||||||||
| getCloudflareApiBaseUrl, | ||||||||||||||||
| getTraceHeader, | ||||||||||||||||
| } from "../environment-variables/misc-variables"; | ||||||||||||||||
| import { UserError } from "../errors"; | ||||||||||||||||
| import { logger } from "../logger"; | ||||||||||||||||
| import { APIError, parseJSON } from "../parse"; | ||||||||||||||||
|
|
@@ -73,10 +76,6 @@ export function createCloudflareClient(complianceConfig: ComplianceConfig) { | |||||||||||||||
| await logResponse(response); | ||||||||||||||||
| return response; | ||||||||||||||||
| }, | ||||||||||||||||
| // We inject authentication using Wrangler's existing auth setup and a custom fetcher (see above for the custom fetch) | ||||||||||||||||
| // However, `cloudflare` doesn't like not being given an API token, so we provide a dummy one | ||||||||||||||||
| // Otherwise, errors like "Could not resolve authentication method." are thrown. | ||||||||||||||||
| apiToken: "dummy", | ||||||||||||||||
| baseURL: getCloudflareApiBaseUrl(complianceConfig), | ||||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -104,6 +103,7 @@ export async function performApiFetch( | |||||||||||||||
| const headers = cloneHeaders(new Headers(init.headers)); | ||||||||||||||||
| addAuthorizationHeader(headers, apiToken); | ||||||||||||||||
| addUserAgent(headers); | ||||||||||||||||
| addTraceHeader(headers); | ||||||||||||||||
|
|
||||||||||||||||
| const queryString = queryParams ? `?${queryParams.toString()}` : ""; | ||||||||||||||||
| logger.debug( | ||||||||||||||||
|
|
@@ -243,6 +243,12 @@ export function addUserAgent(headers: Headers): void { | |||||||||||||||
| headers.set("User-Agent", `wrangler/${wranglerVersion}`); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export function addTraceHeader(headers: Headers): void { | ||||||||||||||||
| if (getTraceHeader()) { | ||||||||||||||||
| headers.set("Cf-Trace-Id", getTraceHeader() as string); | ||||||||||||||||
| } | ||||||||||||||||
|
||||||||||||||||
| if (getTraceHeader()) { | |
| headers.set("Cf-Trace-Id", getTraceHeader() as string); | |
| } | |
| const traceHeader = getTraceHeader(); | |
| if (traceHeader) { | |
| headers.set("Cf-Trace-Id", traceHeader); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,8 @@ type VariableNames = | |
| /** Docker host configuration (handled separately from environment variable factory). */ | ||
| | "WRANGLER_DOCKER_HOST" | ||
| /** Docker host configuration (handled separately from environment variable factory). */ | ||
| | "DOCKER_HOST"; | ||
| | "DOCKER_HOST" | ||
| | "WRANGLER_TRACE_ID"; | ||
|
||
|
|
||
| type DeprecatedNames = | ||
| | "CF_ACCOUNT_ID" | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe update the name to indicate that it might not add anything?
i.e.
addTraceHeaderWhenNeededormaybeAddTraceHeader