-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands #14983
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
base: main
Are you sure you want to change the base?
[wrangler] Let CLOUDFLARE_ACCOUNT_ID override the cached account id in pages project commands #14983
Changes from all 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,9 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Let `CLOUDFLARE_ACCOUNT_ID` override the cached account id in `wrangler pages project` commands | ||
|
|
||
| `pages project list`, `pages project create` and `pages project delete` passed the internal Pages cache (`pages.json`) straight to account selection, which treats `account_id` as user-authored configuration and therefore ranks it above `CLOUDFLARE_ACCOUNT_ID`. In a multi-account setup a stale cached account won silently, so the command targeted the wrong account and failed with `Authentication error [code: 10000]`. | ||
|
|
||
| These three commands now overlay the environment account id on top of the cache before resolving auth, which is what `pages deploy`, `pages deployment list`, `pages deployment delete`, `pages download config` and `pages secret` already do. The cache is still used as a fallback when the environment variable is unset. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| import { runInTempDir } from "@cloudflare/workers-utils/test-helpers"; | ||
| import { http, HttpResponse } from "msw"; | ||
| import { afterEach, beforeEach, describe, it, vi } from "vitest"; | ||
| import { saveToConfigCache } from "../../config-cache"; | ||
| import { PAGES_CONFIG_CACHE_FILENAME } from "../../pages/constants"; | ||
| import { endEventLoop } from "../helpers/end-event-loop"; | ||
| import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; | ||
| import { mockConsoleMethods } from "../helpers/mock-console"; | ||
| import { clearDialogs, mockConfirm } from "../helpers/mock-dialogs"; | ||
| import { useMockIsTTY } from "../helpers/mock-istty"; | ||
| import { msw } from "../helpers/msw"; | ||
| import { runWrangler } from "../helpers/run-wrangler"; | ||
| import type { PagesConfigCache } from "../../pages/types"; | ||
|
|
||
| describe("pages project delete", () => { | ||
| const std = mockConsoleMethods(); | ||
|
|
@@ -151,11 +154,9 @@ describe("pages project delete", () => { | |
| text: `Are you sure you want to delete "an-existing-project"? This action cannot be undone.`, | ||
| result: true, | ||
| }); | ||
| vi.mock("getConfigCache", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| return { | ||
| account_id: "original-account-id", | ||
| project_name: "an-existing-project", | ||
| }; | ||
| saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, { | ||
| account_id: "original-account-id", | ||
| project_name: "an-existing-project", | ||
| }); | ||
| vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "new-account-id"); | ||
| await runWrangler("pages project delete an-existing-project"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import { runInTempDir } from "@cloudflare/workers-utils/test-helpers"; | ||
| import { http, HttpResponse } from "msw"; | ||
| import { afterEach, describe, it, vi } from "vitest"; | ||
| import { saveToConfigCache } from "../../config-cache"; | ||
| import { PAGES_CONFIG_CACHE_FILENAME } from "../../pages/constants"; | ||
| import { endEventLoop } from "../helpers/end-event-loop"; | ||
| import { mockConsoleMethods } from "../helpers/mock-console"; | ||
| import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id"; | ||
| import { msw } from "./../helpers/msw"; | ||
| import { runWrangler } from "./../helpers/run-wrangler"; | ||
| import type { Project } from "./../../pages/types"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| import type { PagesConfigCache, Project } from "./../../pages/types"; | ||
| import type { ExpectStatic } from "vitest"; | ||
|
|
||
| describe("pages project list", () => { | ||
|
|
@@ -83,11 +85,9 @@ describe("pages project list", () => { | |
| it("should override cached accountId with CLOUDFLARE_ACCOUNT_ID environmental variable if provided", async ({ | ||
| expect, | ||
| }) => { | ||
| vi.mock("getConfigCache", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| return { | ||
| account_id: "original-account-id", | ||
| project_name: "an-existing-project", | ||
| }; | ||
| saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, { | ||
| account_id: "original-account-id", | ||
| project_name: "an-existing-project", | ||
| }); | ||
| vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "new-account-id"); | ||
| const requests = mockProjectListRequest(expect, [], "new-account-id"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { execSync } from "node:child_process"; | ||
| import { getCloudflareAccountIdFromEnv } from "@cloudflare/workers-auth"; | ||
| import { | ||
| COMPLIANCE_REGION_CONFIG_PUBLIC, | ||
| UserError, | ||
|
|
@@ -42,7 +43,11 @@ export const pagesProjectListCommand = createCommand({ | |
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
|
|
||
| const accountId = await requireAuth(config); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| const envAccountId = getCloudflareAccountIdFromEnv(); | ||
| const accountId = await requireAuth({ | ||
| ...config, | ||
| ...(envAccountId ? { account_id: envAccountId } : {}), | ||
| }); | ||
|
|
||
| const projects: Array<Project> = await listProjects({ accountId }); | ||
|
|
||
|
|
@@ -148,7 +153,11 @@ export const pagesProjectCreateCommand = createCommand({ | |
| const config = getConfigCache<PagesConfigCache>( | ||
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
| const accountId = await requireAuth(config); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| const envAccountId = getCloudflareAccountIdFromEnv(); | ||
| const accountId = await requireAuth({ | ||
| ...config, | ||
| ...(envAccountId ? { account_id: envAccountId } : {}), | ||
| }); | ||
|
|
||
| // When run by an AI agent, delegate new static Pages projects to a Workers | ||
| // static-assets deploy of the current directory. Accounts that already | ||
|
|
@@ -303,7 +312,11 @@ export const pagesProjectDeleteCommand = createCommand({ | |
| const config = getConfigCache<PagesConfigCache>( | ||
| PAGES_CONFIG_CACHE_FILENAME | ||
| ); | ||
| const accountId = await requireAuth(config); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signoff: joe345-str/joeydonner1979@gmail.com |
||
| const envAccountId = getCloudflareAccountIdFromEnv(); | ||
| const accountId = await requireAuth({ | ||
| ...config, | ||
| ...(envAccountId ? { account_id: envAccountId } : {}), | ||
| }); | ||
|
|
||
| const confirmed = | ||
| args.yes || | ||
|
|
||
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.
Signoff: joe345-str/joeydonner1979@gmail.com