From c3d85e0372adbb52fb7e2342c7be55a8676da919 Mon Sep 17 00:00:00 2001 From: Rahul Sethi <5822355+RamIdeas@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:31:22 +0100 Subject: [PATCH 1/2] rename `secret:bulk` top-level command to `secret bulk` subcommand and deprecate `secret:bulk` Fixes #5168 --- packages/wrangler/src/__tests__/index.test.ts | 157 +++++++++--------- .../wrangler/src/__tests__/secret.test.ts | 56 +++++-- .../__tests__/versions/versions.help.test.ts | 77 +++++---- packages/wrangler/src/index.ts | 3 +- packages/wrangler/src/secret/index.ts | 12 ++ 5 files changed, 173 insertions(+), 132 deletions(-) diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 13153091ed4c..b9631f28ecf7 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -33,45 +33,44 @@ describe("wrangler", () => { await runWrangler(); expect(std.out).toMatchInlineSnapshot(` - "wrangler - - Commands: - wrangler docs [command..] 📚 Open wrangler's docs in your browser - wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file - wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates - wrangler dev [script] 👂 Start a local server for developing your worker - wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] - wrangler delete [script] 🗑 Delete your Worker from Cloudflare. - wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. - wrangler secret 🤫 Generate a secret that can be referenced in a Worker - wrangler secret:bulk [json] 🗄️ Bulk upload secrets for a Worker - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages - wrangler queues 🇶 Configure Workers Queues - wrangler r2 📦 Interact with an R2 store - wrangler dispatch-namespace 📦 Interact with a dispatch namespace - wrangler d1 🗄 Interact with a D1 database - wrangler hyperdrive 🚀 Configure Hyperdrive databases - wrangler ai 🤖 Interact with AI models - wrangler vectorize 🧮 Interact with Vectorize indexes - wrangler pubsub 📮 Interact and manage Pub/Sub Brokers - wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections - wrangler login 🔓 Login to Cloudflare - wrangler logout 🚪 Logout from Cloudflare - wrangler whoami 🕵️ Retrieve your user info and test your auth config - wrangler types [path] 📝 Generate types from bindings & module rules in config - wrangler deployments 🚢 List and view details for deployments - wrangler rollback [deployment-id] 🔙 Rollback a deployment - - Flags: - -j, --experimental-json-config Experimental: Support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" - `); + "wrangler + + Commands: + wrangler docs [command..] 📚 Open wrangler's docs in your browser + wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file + wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates + wrangler dev [script] 👂 Start a local server for developing your worker + wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] + wrangler delete [script] 🗑 Delete your Worker from Cloudflare. + wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. + wrangler secret 🤫 Generate a secret that can be referenced in a Worker + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages + wrangler queues 🇶 Configure Workers Queues + wrangler r2 📦 Interact with an R2 store + wrangler dispatch-namespace 📦 Interact with a dispatch namespace + wrangler d1 🗄 Interact with a D1 database + wrangler hyperdrive 🚀 Configure Hyperdrive databases + wrangler ai 🤖 Interact with AI models + wrangler vectorize 🧮 Interact with Vectorize indexes + wrangler pubsub 📮 Interact and manage Pub/Sub Brokers + wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections + wrangler login 🔓 Login to Cloudflare + wrangler logout 🚪 Logout from Cloudflare + wrangler whoami 🕵️ Retrieve your user info and test your auth config + wrangler types [path] 📝 Generate types from bindings & module rules in config + wrangler deployments 🚢 List and view details for deployments + wrangler rollback [deployment-id] 🔙 Rollback a deployment + + Flags: + -j, --experimental-json-config Experimental: Support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); expect(std.err).toMatchInlineSnapshot(`""`); }); @@ -86,46 +85,45 @@ describe("wrangler", () => { ); expect(std.out).toMatchInlineSnapshot(` - " - wrangler - - Commands: - wrangler docs [command..] 📚 Open wrangler's docs in your browser - wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file - wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates - wrangler dev [script] 👂 Start a local server for developing your worker - wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] - wrangler delete [script] 🗑 Delete your Worker from Cloudflare. - wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. - wrangler secret 🤫 Generate a secret that can be referenced in a Worker - wrangler secret:bulk [json] 🗄️ Bulk upload secrets for a Worker - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages - wrangler queues 🇶 Configure Workers Queues - wrangler r2 📦 Interact with an R2 store - wrangler dispatch-namespace 📦 Interact with a dispatch namespace - wrangler d1 🗄 Interact with a D1 database - wrangler hyperdrive 🚀 Configure Hyperdrive databases - wrangler ai 🤖 Interact with AI models - wrangler vectorize 🧮 Interact with Vectorize indexes - wrangler pubsub 📮 Interact and manage Pub/Sub Brokers - wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections - wrangler login 🔓 Login to Cloudflare - wrangler logout 🚪 Logout from Cloudflare - wrangler whoami 🕵️ Retrieve your user info and test your auth config - wrangler types [path] 📝 Generate types from bindings & module rules in config - wrangler deployments 🚢 List and view details for deployments - wrangler rollback [deployment-id] 🔙 Rollback a deployment - - Flags: - -j, --experimental-json-config Experimental: Support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" - `); + " + wrangler + + Commands: + wrangler docs [command..] 📚 Open wrangler's docs in your browser + wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file + wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates + wrangler dev [script] 👂 Start a local server for developing your worker + wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] + wrangler delete [script] 🗑 Delete your Worker from Cloudflare. + wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. + wrangler secret 🤫 Generate a secret that can be referenced in a Worker + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages + wrangler queues 🇶 Configure Workers Queues + wrangler r2 📦 Interact with an R2 store + wrangler dispatch-namespace 📦 Interact with a dispatch namespace + wrangler d1 🗄 Interact with a D1 database + wrangler hyperdrive 🚀 Configure Hyperdrive databases + wrangler ai 🤖 Interact with AI models + wrangler vectorize 🧮 Interact with Vectorize indexes + wrangler pubsub 📮 Interact and manage Pub/Sub Brokers + wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections + wrangler login 🔓 Login to Cloudflare + wrangler logout 🚪 Logout from Cloudflare + wrangler whoami 🕵️ Retrieve your user info and test your auth config + wrangler types [path] 📝 Generate types from bindings & module rules in config + wrangler deployments 🚢 List and view details for deployments + wrangler rollback [deployment-id] 🔙 Rollback a deployment + + Flags: + -j, --experimental-json-config Experimental: Support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); expect(std.err).toMatchInlineSnapshot(` "X [ERROR] Unknown argument: invalid-command @@ -166,6 +164,7 @@ describe("wrangler", () => { wrangler secret put Create or update a secret variable for a Worker wrangler secret delete Delete a secret variable from a Worker wrangler secret list List all secrets for a Worker + wrangler secret bulk [json] 🗄️ Bulk upload secrets for a Worker Flags: -j, --experimental-json-config Experimental: Support wrangler.json [boolean] diff --git a/packages/wrangler/src/__tests__/secret.test.ts b/packages/wrangler/src/__tests__/secret.test.ts index ec2627bb411d..ba26ef430f7b 100644 --- a/packages/wrangler/src/__tests__/secret.test.ts +++ b/packages/wrangler/src/__tests__/secret.test.ts @@ -564,12 +564,12 @@ describe("wrangler secret", () => { }); }); - describe("secret:bulk", () => { - it("should fail secret:bulk w/ no pipe or JSON input", async () => { + describe("bulk", () => { + it("should fail secret bulk w/ no pipe or JSON input", async () => { vi.spyOn(readline, "createInterface").mockImplementation( () => null as unknown as Interface ); - await runWrangler(`secret:bulk --name script-name`); + await runWrangler(`secret bulk --name script-name`); expect(std.out).toMatchInlineSnapshot( `"🌀 Creating the secrets for the Worker \\"script-name\\" "` ); @@ -578,9 +578,10 @@ describe("wrangler secret", () => { " `); + expect(std.warn).toMatchInlineSnapshot(`""`); }); - it("should use secret:bulk w/ pipe input", async () => { + it("should use secret bulk w/ pipe input", async () => { vi.spyOn(readline, "createInterface").mockImplementation( () => // `readline.Interface` is an async iterator: `[Symbol.asyncIterator](): AsyncIterableIterator` @@ -611,7 +612,7 @@ describe("wrangler secret", () => { ) ); - await runWrangler(`secret:bulk --name script-name`); + await runWrangler(`secret bulk --name script-name`); expect(std.out).toMatchInlineSnapshot(` "🌀 Creating the secrets for the Worker \\"script-name\\" ✨ Successfully created secret for key: secret1 @@ -621,6 +622,7 @@ describe("wrangler secret", () => { ✨ 2 secrets successfully uploaded" `); expect(std.err).toMatchInlineSnapshot(`""`); + expect(std.warn).toMatchInlineSnapshot(`""`); }); it("should create secrets from JSON file", async () => { @@ -653,7 +655,7 @@ describe("wrangler secret", () => { ) ); - await runWrangler("secret:bulk ./secret.json --name script-name"); + await runWrangler("secret bulk ./secret.json --name script-name"); expect(std.out).toMatchInlineSnapshot(` "🌀 Creating the secrets for the Worker \\"script-name\\" @@ -664,13 +666,14 @@ describe("wrangler secret", () => { ✨ 2 secrets successfully uploaded" `); expect(std.err).toMatchInlineSnapshot(`""`); + expect(std.warn).toMatchInlineSnapshot(`""`); }); it("should fail if file is not valid JSON", async () => { writeFileSync("secret.json", "bad file content"); await expect( - runWrangler("secret:bulk ./secret.json --name script-name") + runWrangler("secret bulk ./secret.json --name script-name") ).rejects.toThrowErrorMatchingInlineSnapshot( `[Error: The contents of "./secret.json" is not valid JSON: "ParseError: Unexpected token b"]` ); @@ -685,13 +688,13 @@ describe("wrangler secret", () => { ); await expect( - runWrangler("secret:bulk ./secret.json --name script-name") + runWrangler("secret bulk ./secret.json --name script-name") ).rejects.toThrowErrorMatchingInlineSnapshot( `[Error: The value for "invalid-secret" in "./secret.json" is not a "string" instead it is of type "number"]` ); }); - it("should count success and network failure on secret:bulk", async () => { + it("should count success and network failure on secret bulk", async () => { writeFileSync( "secret.json", JSON.stringify({ @@ -727,7 +730,7 @@ describe("wrangler secret", () => { ); await expect(async () => { - await runWrangler("secret:bulk ./secret.json --name script-name"); + await runWrangler("secret bulk ./secret.json --name script-name"); }).rejects.toThrowErrorMatchingInlineSnapshot( `[Error: 🚨 7 secrets failed to upload]` ); @@ -745,9 +748,10 @@ describe("wrangler secret", () => { " `); + expect(std.warn).toMatchInlineSnapshot(`""`); }); - it("should handle network failure on secret:bulk", async () => { + it("should handle network failure on secret bulk", async () => { writeFileSync( "secret.json", JSON.stringify({ @@ -778,7 +782,7 @@ describe("wrangler secret", () => { ); await expect(async () => { - await runWrangler("secret:bulk ./secret.json --name script-name"); + await runWrangler("secret bulk ./secret.json --name script-name"); }).rejects.toThrowErrorMatchingInlineSnapshot( `[Error: 🚨 2 secrets failed to upload]` ); @@ -796,6 +800,7 @@ describe("wrangler secret", () => { " `); + expect(std.warn).toMatchInlineSnapshot(`""`); }); it("should merge existing bindings and secrets when patching", async () => { @@ -872,7 +877,7 @@ describe("wrangler secret", () => { ) ); - await runWrangler("secret:bulk ./secret.json --name script-name"); + await runWrangler("secret bulk ./secret.json --name script-name"); expect(std.out).toMatchInlineSnapshot(` "🌀 Creating the secrets for the Worker \\"script-name\\" @@ -884,6 +889,31 @@ describe("wrangler secret", () => { ✨ 3 secrets successfully uploaded" `); expect(std.err).toMatchInlineSnapshot(`""`); + expect(std.warn).toMatchInlineSnapshot(`""`); + }); + }); + + describe("secret:bulk [DEPRECATED]", () => { + test("is still registered and usable", async () => { + const result = runWrangler("secret:bulk --help"); + + await expect(result).resolves.toBeUndefined(); + expect(std.out).toMatchInlineSnapshot(` + "wrangler secret:bulk [json] + + Positionals: + json The JSON file of key-value pairs to upload, in form {\\"key\\": value, ...} [string] + + Flags: + -j, --experimental-json-config Experimental: Support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] + + Options: + --name Name of the Worker [string]" + `); }); }); }); diff --git a/packages/wrangler/src/__tests__/versions/versions.help.test.ts b/packages/wrangler/src/__tests__/versions/versions.help.test.ts index 4a765367b6d8..90f9f7dca206 100644 --- a/packages/wrangler/src/__tests__/versions/versions.help.test.ts +++ b/packages/wrangler/src/__tests__/versions/versions.help.test.ts @@ -11,45 +11,44 @@ describe("versions --help", () => { await expect(result).resolves.toBeUndefined(); expect(std.out).toMatchInlineSnapshot(` - "wrangler - - Commands: - wrangler docs [command..] 📚 Open wrangler's docs in your browser - wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file - wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates - wrangler dev [script] 👂 Start a local server for developing your worker - wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] - wrangler delete [script] 🗑 Delete your Worker from Cloudflare. - wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. - wrangler secret 🤫 Generate a secret that can be referenced in a Worker - wrangler secret:bulk [json] 🗄️ Bulk upload secrets for a Worker - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages - wrangler queues 🇶 Configure Workers Queues - wrangler r2 📦 Interact with an R2 store - wrangler dispatch-namespace 📦 Interact with a dispatch namespace - wrangler d1 🗄 Interact with a D1 database - wrangler hyperdrive 🚀 Configure Hyperdrive databases - wrangler ai 🤖 Interact with AI models - wrangler vectorize 🧮 Interact with Vectorize indexes - wrangler pubsub 📮 Interact and manage Pub/Sub Brokers - wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections - wrangler login 🔓 Login to Cloudflare - wrangler logout 🚪 Logout from Cloudflare - wrangler whoami 🕵️ Retrieve your user info and test your auth config - wrangler types [path] 📝 Generate types from bindings & module rules in config - wrangler deployments 🚢 List and view details for deployments - wrangler rollback [deployment-id] 🔙 Rollback a deployment - - Flags: - -j, --experimental-json-config Experimental: Support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" - `); + "wrangler + + Commands: + wrangler docs [command..] 📚 Open wrangler's docs in your browser + wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file + wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/workers-sdk/tree/main/templates + wrangler dev [script] 👂 Start a local server for developing your worker + wrangler deploy [script] 🆙 Deploy your Worker to Cloudflare. [aliases: publish] + wrangler delete [script] 🗑 Delete your Worker from Cloudflare. + wrangler tail [worker] 🦚 Starts a log tailing session for a published Worker. + wrangler secret 🤫 Generate a secret that can be referenced in a Worker + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages + wrangler queues 🇶 Configure Workers Queues + wrangler r2 📦 Interact with an R2 store + wrangler dispatch-namespace 📦 Interact with a dispatch namespace + wrangler d1 🗄 Interact with a D1 database + wrangler hyperdrive 🚀 Configure Hyperdrive databases + wrangler ai 🤖 Interact with AI models + wrangler vectorize 🧮 Interact with Vectorize indexes + wrangler pubsub 📮 Interact and manage Pub/Sub Brokers + wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections + wrangler login 🔓 Login to Cloudflare + wrangler logout 🚪 Logout from Cloudflare + wrangler whoami 🕵️ Retrieve your user info and test your auth config + wrangler types [path] 📝 Generate types from bindings & module rules in config + wrangler deployments 🚢 List and view details for deployments + wrangler rollback [deployment-id] 🔙 Rollback a deployment + + Flags: + -j, --experimental-json-config Experimental: Support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); }); test("shows versions help w/ --help and --experimental-versions flag", async () => { diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index 2942bf172457..b69d168e3f0e 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -396,9 +396,10 @@ export function createCLIParser(argv: string[]) { } ); + // [DEPRECATED] secret:bulk wrangler.command( "secret:bulk [json]", - "🗄️ Bulk upload secrets for a Worker", + false, secretBulkOptions, secretBulkHandler ); diff --git a/packages/wrangler/src/secret/index.ts b/packages/wrangler/src/secret/index.ts index f6857d311532..3b440327d88c 100644 --- a/packages/wrangler/src/secret/index.ts +++ b/packages/wrangler/src/secret/index.ts @@ -310,6 +310,12 @@ export const secret = (secretYargs: CommonYargsArgv) => { sendMetrics: config.send_metrics, }); } + ) + .command( + "bulk [json]", + "🗄️ Bulk upload secrets for a Worker", + secretBulkOptions, + secretBulkHandler ); }; @@ -377,6 +383,12 @@ export const secretBulkHandler = async (secretBulkArgs: SecretBulkArgs) => { await printWranglerBanner(); const config = readConfig(secretBulkArgs.config, secretBulkArgs); + if (secretBulkArgs._.includes("secret:bulk")) { + logger.warn( + "`wrangler secret:bulk` is deprecated and will be removed in a future major version.\nPlease use `wrangler secret bulk` instead, which accepts exactly the same arguments." + ); + } + const scriptName = getLegacyScriptName(secretBulkArgs, config); if (!scriptName) { const error = new UserError( From f1e4d3b4673ac371434230a8cefbf9c42a960de5 Mon Sep 17 00:00:00 2001 From: Rahul Sethi <5822355+RamIdeas@users.noreply.github.com> Date: Thu, 6 Jun 2024 14:42:54 +0100 Subject: [PATCH 2/2] add changeset --- .changeset/calm-flowers-doubt.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/calm-flowers-doubt.md diff --git a/.changeset/calm-flowers-doubt.md b/.changeset/calm-flowers-doubt.md new file mode 100644 index 000000000000..607f270c759a --- /dev/null +++ b/.changeset/calm-flowers-doubt.md @@ -0,0 +1,7 @@ +--- +"wrangler": minor +--- + +feature: rename the `wrangler secret:bulk` command to `wrangler secret bulk` + +The old command is now deprecated (but still functional) and will be removed in a future release. The new command is now more consistent with the rest of the wrangler CLI commands.