Skip to content

Commit

Permalink
rename secret:bulk top-level command to secret bulk subcommand (#…
Browse files Browse the repository at this point in the history
…5988)

* rename `secret:bulk` top-level command to `secret bulk` subcommand
and deprecate `secret:bulk`

Fixes #5168

* add changeset
  • Loading branch information
RamIdeas authored Jun 6, 2024
1 parent ab95473 commit e144f63
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 132 deletions.
7 changes: 7 additions & 0 deletions .changeset/calm-flowers-doubt.md
Original file line number Diff line number Diff line change
@@ -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.
157 changes: 78 additions & 79 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`""`);
});
Expand All @@ -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
Expand Down Expand Up @@ -166,6 +164,7 @@ describe("wrangler", () => {
wrangler secret put <key> Create or update a secret variable for a Worker
wrangler secret delete <key> 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]
Expand Down
56 changes: 43 additions & 13 deletions packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\\" "`
);
Expand All @@ -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<string>`
Expand Down Expand Up @@ -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
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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\\"
Expand All @@ -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"]`
);
Expand All @@ -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({
Expand Down Expand Up @@ -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]`
);
Expand All @@ -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({
Expand Down Expand Up @@ -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]`
);
Expand All @@ -796,6 +800,7 @@ describe("wrangler secret", () => {
"
`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});

it("should merge existing bindings and secrets when patching", async () => {
Expand Down Expand Up @@ -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\\"
Expand All @@ -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]"
`);
});
});
});
Loading

0 comments on commit e144f63

Please sign in to comment.