Skip to content

Commit 1f80d69

Browse files
Inherit bindings in versions secret put (#8058)
1 parent 07db54c commit 1f80d69

File tree

6 files changed

+67
-12
lines changed

6 files changed

+67
-12
lines changed

.changeset/kind-sloths-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Bugfix: Modified versions secret put to inherit all known bindings, which circumvents a limitation in the API which does not return all fields for all bindings.

packages/wrangler/src/__tests__/versions/secrets/bulk.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe("versions secret bulk", () => {
4949
mockSetupApiCalls();
5050
mockPostVersion((metadata) => {
5151
expect(metadata.bindings).toStrictEqual([
52+
{ type: "inherit", name: "do-binding" },
5253
{ type: "secret_text", name: "SECRET_1", text: "secret-1" },
5354
{ type: "secret_text", name: "SECRET_2", text: "secret-2" },
5455
{ type: "secret_text", name: "SECRET_3", text: "secret-3" },
@@ -119,6 +120,7 @@ describe("versions secret bulk", () => {
119120
mockSetupApiCalls();
120121
mockPostVersion((metadata) => {
121122
expect(metadata.bindings).toStrictEqual([
123+
{ type: "inherit", name: "do-binding" },
122124
{ type: "secret_text", name: "SECRET_1", text: "secret-1" },
123125
{ type: "secret_text", name: "SECRET_2", text: "secret-2" },
124126
{ type: "secret_text", name: "SECRET_3", text: "secret-3" },
@@ -164,6 +166,7 @@ describe("versions secret bulk", () => {
164166
mockSetupApiCalls();
165167
mockPostVersion((metadata) => {
166168
expect(metadata.bindings).toStrictEqual([
169+
{ type: "inherit", name: "do-binding" },
167170
{ type: "secret_text", name: "SECRET_1", text: "secret-1" },
168171
{ type: "secret_text", name: "SECRET_2", text: "secret-2" },
169172
{ type: "secret_text", name: "SECRET_3", text: "secret-3" },
@@ -205,6 +208,7 @@ describe("versions secret bulk", () => {
205208
mockSetupApiCalls();
206209
mockPostVersion((metadata) => {
207210
expect(metadata.bindings).toStrictEqual([
211+
{ type: "inherit", name: "do-binding" },
208212
{ type: "secret_text", name: "SECRET_1", text: "secret-1" },
209213
{ type: "secret_text", name: "SECRET_2", text: "secret-2" },
210214
{ type: "secret_text", name: "SECRET_3", text: "secret-3" },
@@ -249,6 +253,7 @@ describe("versions secret bulk", () => {
249253
mockSetupApiCalls();
250254
mockPostVersion((metadata) => {
251255
expect(metadata.bindings).toStrictEqual([
256+
{ type: "inherit", name: "do-binding" },
252257
{ type: "secret_text", name: "SECRET_1", text: "secret-1" },
253258
{ type: "secret_text", name: "SECRET_2", text: "secret-2" },
254259
{ type: "secret_text", name: "SECRET_3", text: "secret-3" },

packages/wrangler/src/__tests__/versions/secrets/delete.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("versions secret delete", () => {
3232
mockPostVersion((metadata) => {
3333
// We should have all secrets except the one being deleted
3434
expect(metadata.bindings).toStrictEqual([
35+
{ type: "inherit", name: "do-binding" },
3536
{ type: "inherit", name: "ANOTHER_SECRET" },
3637
{ type: "inherit", name: "YET_ANOTHER_SECRET" },
3738
]);
@@ -55,6 +56,7 @@ describe("versions secret delete", () => {
5556
mockGetVersion();
5657
mockPostVersion((metadata) => {
5758
expect(metadata.bindings).toStrictEqual([
59+
{ type: "inherit", name: "do-binding" },
5860
{ type: "inherit", name: "ANOTHER_SECRET" },
5961
{ type: "inherit", name: "YET_ANOTHER_SECRET" },
6062
]);
@@ -82,6 +84,7 @@ describe("versions secret delete", () => {
8284
mockGetVersion();
8385
mockPostVersion((metadata) => {
8486
expect(metadata.bindings).toStrictEqual([
87+
{ type: "inherit", name: "do-binding" },
8588
{ type: "inherit", name: "ANOTHER_SECRET" },
8689
{ type: "inherit", name: "YET_ANOTHER_SECRET" },
8790
]);

packages/wrangler/src/__tests__/versions/secrets/put.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe("versions secret put", () => {
3535
mockSetupApiCalls();
3636
mockPostVersion((metadata) => {
3737
expect(metadata.bindings).toStrictEqual([
38+
{ type: "inherit", name: "do-binding" },
3839
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
3940
]);
4041
expect(metadata.keep_bindings).toStrictEqual([
@@ -97,6 +98,7 @@ describe("versions secret put", () => {
9798
mockSetupApiCalls();
9899
mockPostVersion((metadata) => {
99100
expect(metadata.bindings).toStrictEqual([
101+
{ type: "inherit", name: "do-binding" },
100102
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
101103
]);
102104
expect(metadata.keep_bindings).toStrictEqual([
@@ -138,6 +140,7 @@ describe("versions secret put", () => {
138140
mockSetupApiCalls();
139141
mockPostVersion((metadata) => {
140142
expect(metadata.bindings).toStrictEqual([
143+
{ type: "inherit", name: "do-binding" },
141144
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
142145
]);
143146
expect(metadata.keep_bindings).toStrictEqual([
@@ -178,6 +181,7 @@ describe("versions secret put", () => {
178181
mockSetupApiCalls();
179182
mockPostVersion((metadata) => {
180183
expect(metadata.bindings).toStrictEqual([
184+
{ type: "inherit", name: "do-binding" },
181185
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
182186
]);
183187
expect(metadata.keep_bindings).toStrictEqual([
@@ -208,6 +212,7 @@ describe("versions secret put", () => {
208212
mockSetupApiCalls();
209213
mockPostVersion((metadata) => {
210214
expect(metadata.bindings).toStrictEqual([
215+
{ type: "inherit", name: "do-binding" },
211216
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
212217
]);
213218
expect(metadata.keep_bindings).toStrictEqual([
@@ -245,6 +250,7 @@ describe("versions secret put", () => {
245250
mockSetupApiCalls();
246251
mockPostVersion((metadata) => {
247252
expect(metadata.bindings).toStrictEqual([
253+
{ type: "inherit", name: "do-binding" },
248254
{ type: "secret_text", name: "NEW_SECRET", text: "the-secret" },
249255
]);
250256
expect(metadata.keep_bindings).toStrictEqual([
@@ -273,6 +279,38 @@ describe("versions secret put", () => {
273279
expect(std.err).toMatchInlineSnapshot(`""`);
274280
});
275281

282+
test("all non-secret bindings are inherited", async () => {
283+
setIsTTY(true);
284+
285+
mockSetupApiCalls();
286+
287+
mockPrompt({
288+
text: "Enter a secret value:",
289+
options: { isSecret: true },
290+
result: "the-secret",
291+
});
292+
293+
mockPostVersion((metadata) => {
294+
expect(metadata.bindings).toStrictEqual([
295+
{ type: "inherit", name: "do-binding" },
296+
{ type: "secret_text", name: "SECRET", text: "the-secret" },
297+
]);
298+
expect(metadata.keep_bindings).toStrictEqual([
299+
"secret_key",
300+
"secret_text",
301+
]);
302+
expect(metadata.annotations).not.toBeUndefined();
303+
});
304+
await runWrangler("versions secret put SECRET --name script-name");
305+
306+
expect(std.out).toMatchInlineSnapshot(`
307+
"🌀 Creating the secret for the Worker \\"script-name\\"
308+
✨ Success! Created version id with secret SECRET.
309+
➡️ To deploy this version with secret SECRET to production traffic use the command \\"wrangler versions deploy\\"."
310+
`);
311+
expect(std.err).toMatchInlineSnapshot(`""`);
312+
});
313+
276314
test("can update an existing secret", async () => {
277315
setIsTTY(true);
278316

@@ -285,6 +323,7 @@ describe("versions secret put", () => {
285323
mockSetupApiCalls();
286324
mockPostVersion((metadata) => {
287325
expect(metadata.bindings).toStrictEqual([
326+
{ type: "inherit", name: "do-binding" },
288327
{ type: "secret_text", name: "SECRET", text: "the-secret" },
289328
]);
290329
expect(metadata.keep_bindings).toStrictEqual([
@@ -361,6 +400,7 @@ describe("versions secret put", () => {
361400
expect((formData.get("module.wasm") as File).size).equal(10);
362401

363402
expect(metadata.bindings).toStrictEqual([
403+
{ type: "inherit", name: "do-binding" },
364404
{ type: "secret_text", name: "SECRET", text: "the-secret" },
365405
]);
366406
expect(metadata.keep_bindings).toStrictEqual([

packages/wrangler/src/__tests__/versions/secrets/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export function mockGetVersion(versionInfo?: VersionDetails) {
5959
name: "YET_ANOTHER_SECRET",
6060
text: "Yet another secret shhhhh",
6161
},
62+
{
63+
name: "do-binding",
64+
type: "durable_object_namespace",
65+
namespace_id: "some-namespace-id",
66+
},
6267
],
6368
script: {
6469
etag: "etag",

packages/wrangler/src/versions/secrets/index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,15 @@ export async function copyWorkerVersionWithNewSecrets({
122122
);
123123

124124
// Filter out secrets because we're gonna inherit them
125-
const bindings: WorkerMetadataBinding[] =
126-
versionInfo.resources.bindings.filter(
127-
(binding) => binding.type !== "secret_text"
128-
);
129-
130-
// We cannot upload a DO with a namespace_id so remove it
131-
for (const binding of bindings) {
132-
if (binding.type === "durable_object_namespace") {
133-
// @ts-expect-error - it doesn't exist within wrangler but does in the API
134-
delete binding.namespace_id;
135-
}
136-
}
125+
const bindings: WorkerMetadataBinding[] = versionInfo.resources.bindings
126+
.filter((binding) => binding.type !== "secret_text")
127+
.map((binding) => {
128+
// Inherit all of the existing bindings
129+
return {
130+
name: binding.name,
131+
type: "inherit",
132+
};
133+
});
137134

138135
// Add the new secrets
139136
for (const secret of secrets) {

0 commit comments

Comments
 (0)