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

[wrangler] Allow empty strings in secret:bulk #4860

Merged
merged 4 commits into from
Jan 30, 2024
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/eleven-carrots-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: allow empty strings in secret:bulk upload

Previously, the `secret:bulk` command would fail if any of the secrets in the secret.json file were empty strings and they already existed remotely.
6 changes: 5 additions & 1 deletion packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ describe("wrangler secret", () => {
JSON.stringify({
"secret-name-2": "secret_text",
"secret-name-3": "secret_text",
"secret-name-4": "",
})
);

Expand All @@ -761,6 +762,7 @@ describe("wrangler secret", () => {
},
{ type: "secret_text", name: "secret-name-1" },
{ type: "secret_text", name: "secret-name-2" },
{ type: "secret_text", name: "secret-name-4" },
],
})
)
Expand Down Expand Up @@ -795,6 +797,7 @@ describe("wrangler secret", () => {
name: "secret-name-3",
text: "secret_text",
},
{ type: "secret_text", name: "secret-name-4", text: "" },
],
});
expect(parsedSettings).not.toHaveProperty(["bindings", 0, "text"]);
Expand All @@ -811,9 +814,10 @@ describe("wrangler secret", () => {
"🌀 Creating the secrets for the Worker \\"script-name\\"
✨ Successfully created secret for key: secret-name-2
✨ Successfully created secret for key: secret-name-3
✨ Successfully created secret for key: secret-name-4

Finished processing secrets JSON file:
2 secrets successfully uploaded"
3 secrets successfully uploaded"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ export const secretBulkHandler = async (secretBulkArgs: SecretBulkArgs) => {
.filter((binding) => {
// secrets that currently exist for the worker but are not provided for bulk update
// are inherited over with other binding types
return binding.type !== "secret_text" || !content[binding.name];
return (
binding.type !== "secret_text" || content[binding.name] === undefined
);
})
.map((binding) => ({ type: binding.type, name: binding.name }));
// secrets to upload are provided as bindings in their full form
Expand Down
Loading