-
Notifications
You must be signed in to change notification settings - Fork 732
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
fix: respect config.account_id in wrangler dev --remote #6963
Conversation
🦋 Changeset detectedLatest commit: c08ea41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6fd39ba
to
a473b1c
Compare
accountId = await requireAuth({}); | ||
accountId = await requireAuth(config); |
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.
main fix for wrangler dev --remote
} | ||
|
||
return { | ||
accountId: config.account_id ?? (await getAccountId()), |
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.
fix default for startWorker
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.
Does this mean config has a precedent over the env variable?
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.
This should probably use the requireAuth()
helper
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.
This should probably use the
requireAuth()
helper
Does this mean config has a precedent over the env variable?
Yes. Which matches previous behaviour unless I'm mistaken?
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.
Yes. Which matches previous behaviour unless I'm mistaken
So it does, that behaviour is surprising
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.
I don't think it's surprising. IMO order of precedence: cli args > config file > env vars, because env vars can be set across projects, config file per project, cli args per command – the specificity is clear.
I can understand setting an env var inline and expecting that to take precedence (eg CLOUDFLARE_ACCOUNT_ID=1234 npx wrangler deploy
) but instead the cli arg should be used for that use-case (eg. npx wrangler deploy --account-id 1234
) because that env var could've come from the eg ~/.zshrc file
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.
I've never seen --account-id
before - it doesn't seem to be documented 🙃
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.
Huh you're right! We should add one to support per command overrides with higher precedence than the config file
if (input.dev?.auth) { | ||
return unwrapHook(input.dev.auth, config); | ||
} |
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.
provide (wrangler.toml) config to the hook fn as param
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-wrangler-6963 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6963/npm-package-wrangler-6963 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-wrangler-6963 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-create-cloudflare-6963 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-kv-asset-handler-6963 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-miniflare-6963 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-pages-shared-6963 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-vitest-pool-workers-6963 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-workers-editor-shared-6963 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11363964648/npm-package-cloudflare-workers-shared-6963 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
@@ -129,7 +129,7 @@ export interface StartDevWorkerInput { | |||
/** Whether the worker runs on the edge or locally. */ | |||
remote?: boolean; | |||
/** Cloudflare Account credentials. Can be provided upfront or as a function which will be called only when required. */ | |||
auth?: AsyncHook<CfAccount>; | |||
auth?: AsyncHook<CfAccount, [Pick<Config, "account_id">]>; // provide config.account_id as a hook param |
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.
only the ConfigController has access to the wrangler.toml config so enable it as a hook param for StartDevWorkerInput.dev.auth
@@ -187,6 +187,7 @@ export type StartDevWorkerOptions = Omit<StartDevWorkerInput, "assets"> & { | |||
}; | |||
dev: StartDevWorkerInput["dev"] & { | |||
persist: string; | |||
auth?: AsyncHook<CfAccount>; // redefine without config.account_id hook param (can only be provided by ConfigController with access to wrangler.toml, not by other controllers eg RemoteRuntimeContoller) |
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.
Other controllers won't have access to the wrangler.toml config file so redefine this without a hook param on StartDevWorkerOptions.dev.auth
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.
How will this work if e.g. the remote runtime controller unwraps the hook? Will that not fail?
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.
Only the ConfigController unwraps this hook. The ConfigController overwrites this property with a new hook that does not expect a param – this new hook is then unwrapped by the RemoteRuntimeController
}); | ||
const auth = async () => { | ||
if (input.dev?.auth) { | ||
return unwrapHook(input.dev.auth, config); |
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.
I'm not sure this is the same behaviour. This seems to unconditionally unwrap the hook if provided, even if not in remote mode?
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.
It doesn't unconditionally unwrap the hook. It unconditionally sets the auth property with its own hook which will unwrap the original property when itself is unwrapped. Therefore it is still conditionally unwrapped as before
(This diff answers your other question. https://github.com/cloudflare/workers-sdk/pull/6963/files#r1799613869)
@@ -187,6 +187,7 @@ export type StartDevWorkerOptions = Omit<StartDevWorkerInput, "assets"> & { | |||
}; | |||
dev: StartDevWorkerInput["dev"] & { | |||
persist: string; | |||
auth?: AsyncHook<CfAccount>; // redefine without config.account_id hook param (can only be provided by ConfigController with access to wrangler.toml, not by other controllers eg RemoteRuntimeContoller) |
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.
How will this work if e.g. the remote runtime controller unwraps the hook? Will that not fail?
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.
Approved pending https://github.com/cloudflare/workers-sdk/pull/6963/files#r1800710064 and the TODO test
What this PR solves / how to test
Fixes #6947
Author has addressed the following