Skip to content
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: disallow setting account_id in named service environments #814

Merged
merged 1 commit into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/little-roses-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: disallow setting account_id in named service environments

Much like https://github.com/cloudflare/wrangler2/pull/641, we don't want to allow setting account_id with named service environments. This is so that we use the same account_id for multiple environments, and have them group together in the dashboard.
55 changes: 55 additions & 0 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,61 @@ describe("normalizeAndValidateConfig()", () => {
});
});

it("should error if named environment contains a `account_id` field, even if there is no top-level name", () => {
const rawConfig: RawConfig = {
legacy_env: false,
env: {
DEV: {
account_id: "some_account_id",
},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
{ env: "DEV" }
);

expect(config.account_id).toBeUndefined();
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:

- \\"env.DEV\\" environment configuration
- The \\"account_id\\" field is not allowed in named service environments.
Please remove the field from this environment."
`);
expect(diagnostics.hasWarnings()).toBe(false);
});

it("should error if top-level config and a named environment both contain a `account_id` field", () => {
const rawConfig: RawConfig = {
account_id: "ACCOUNT_ID",
legacy_env: false,
env: {
DEV: {
account_id: "ENV_ACCOUNT_ID",
},
},
};

const { config, diagnostics } = normalizeAndValidateConfig(
rawConfig,
undefined,
{ env: "DEV" }
);

expect(config.account_id).toEqual("ACCOUNT_ID");
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:

- \\"env.DEV\\" environment configuration
- The \\"account_id\\" field is not allowed in named service environments.
Please remove the field from this environment."
`);
expect(diagnostics.hasWarnings()).toBe(false);
});

it("should warn for non-inherited fields that are missing in environments", () => {
const vars: RawConfig["vars"] = {
FOO: "foo",
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/config/validation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function inheritableInLegacyEnvironments<K extends keyof Environment>(
rawEnv: RawEnvironment,
field: K,
validate: ValidatorFn,
transformFn: TransformFn<Environment[K]>,
transformFn: TransformFn<Environment[K]> = (v) => v,
defaultValue: Environment[K]
): Environment[K] {
return topLevelEnv === undefined || isLegacyEnv === true
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,14 @@ function normalizeAndValidateEnvironment(

const environment: Environment = {
// Inherited fields
account_id: inheritable(
account_id: inheritableInLegacyEnvironments(
diagnostics,
isLegacyEnv,
topLevelEnv,
rawEnv,
"account_id",
isString,
undefined,
undefined
),
compatibility_date: inheritable(
Expand Down