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

rename secret:bulk top-level command to secret bulk subcommand #5988

Merged
merged 2 commits into from
Jun 6, 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/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
Loading