Skip to content

Commit 62df08a

Browse files
Add options to update pipelines to remove CORS (#8829)
* Add options to update pipelines to remove CORS * Update some help text for consistency Co-authored-by: Pranshu Maheshwari <[email protected]> --------- Co-authored-by: Pranshu Maheshwari <[email protected]>
1 parent 09464a6 commit 62df08a

File tree

10 files changed

+92
-47
lines changed

10 files changed

+92
-47
lines changed

.changeset/slow-roses-create.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Add option `--cors-origin none` to remove CORS settings on a pipeline

packages/wrangler/src/__tests__/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("wrangler", () => {
6363
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
6464
wrangler ai 🤖 Manage AI models
6565
wrangler workflows 🔁 Manage Workflows [open-beta]
66-
wrangler pipelines 🚰 Manage Worker Pipelines [open beta]
66+
wrangler pipelines 🚰 Manage Cloudflare Pipelines [open beta]
6767
wrangler login 🔓 Login to Cloudflare
6868
wrangler logout 🚪 Logout from Cloudflare
6969
wrangler whoami 🕵️ Retrieve your user information
@@ -123,7 +123,7 @@ describe("wrangler", () => {
123123
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
124124
wrangler ai 🤖 Manage AI models
125125
wrangler workflows 🔁 Manage Workflows [open-beta]
126-
wrangler pipelines 🚰 Manage Worker Pipelines [open beta]
126+
wrangler pipelines 🚰 Manage Cloudflare Pipelines [open beta]
127127
wrangler login 🔓 Login to Cloudflare
128128
wrangler logout 🚪 Logout from Cloudflare
129129
wrangler whoami 🕵️ Retrieve your user information

packages/wrangler/src/__tests__/pipelines.test.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ describe("pipelines", () => {
274274
expect(std.out).toMatchInlineSnapshot(`
275275
"wrangler pipelines
276276
277-
🚰 Manage Worker Pipelines [open beta]
277+
🚰 Manage Cloudflare Pipelines [open beta]
278278
279279
COMMANDS
280-
wrangler pipelines create <pipeline> Create a new Pipeline
281-
wrangler pipelines list List current Pipelines
282-
wrangler pipelines get <pipeline> Get a Pipeline configuration
283-
wrangler pipelines update <pipeline> Update a Pipeline
284-
wrangler pipelines delete <pipeline> Delete a Pipeline
280+
wrangler pipelines create <pipeline> Create a new pipeline
281+
wrangler pipelines list List all pipelines
282+
wrangler pipelines get <pipeline> Get a pipeline's configuration
283+
wrangler pipelines update <pipeline> Update a pipeline
284+
wrangler pipelines delete <pipeline> Delete a pipeline
285285
286286
GLOBAL FLAGS
287287
-c, --config Path to Wrangler configuration file [string]
@@ -301,7 +301,7 @@ describe("pipelines", () => {
301301
expect(std.out).toMatchInlineSnapshot(`
302302
"wrangler pipelines create <pipeline>
303303
304-
Create a new Pipeline
304+
Create a new pipeline
305305
306306
POSITIONALS
307307
pipeline The name of the new pipeline [string] [required]
@@ -324,7 +324,7 @@ describe("pipelines", () => {
324324
--compression Compression format for output files [string] [choices: \\"none\\", \\"gzip\\", \\"deflate\\"] [default: \\"gzip\\"]
325325
326326
Pipeline settings
327-
--shard-count Number of pipeline shards. More shards handle higher request volume; fewer shards produce larger output files. Defaults to 2 if unset. Minimum: 1, Maximum: 15 [number]
327+
--shard-count Number of shards for the pipeline. More shards handle higher request volume; fewer shards produce larger output files. Defaults to 2 if unset. Minimum: 1, Maximum: 15 [number]
328328
329329
GLOBAL FLAGS
330330
-c, --config Path to Wrangler configuration file [string]
@@ -342,8 +342,8 @@ describe("pipelines", () => {
342342
);
343343
expect(requests.count).toEqual(1);
344344
expect(std.out).toMatchInlineSnapshot(`
345-
"🌀 Creating Pipeline named \\"my-pipeline\\"
346-
✅ Successfully created Pipeline \\"my-pipeline\\" with ID 0001
345+
"🌀 Creating pipeline named \\"my-pipeline\\"
346+
✅ Successfully created pipeline \\"my-pipeline\\" with ID 0001
347347
348348
Id: 0001
349349
Name: my-pipeline
@@ -364,7 +364,7 @@ describe("pipelines", () => {
364364
Max duration: 300 seconds
365365
Max records: 10,000,000
366366
367-
🎉 You can now send data to your Pipeline!
367+
🎉 You can now send data to your pipeline!
368368
369369
To send data to your pipeline from a Worker, add the following to your wrangler config file:
370370
@@ -377,7 +377,7 @@ describe("pipelines", () => {
377377
]
378378
}
379379
380-
Send data to your Pipeline's HTTP endpoint:
380+
Send data to your pipeline's HTTP endpoint:
381381
382382
curl \\"foo\\" -d '[{\\"foo\\": \\"bar\\"}]'
383383
"
@@ -654,6 +654,42 @@ describe("pipelines", () => {
654654
]);
655655
});
656656

657+
it("should update remove cors headers", async () => {
658+
const pipeline: Pipeline = samplePipeline;
659+
mockGetRequest(pipeline.name, pipeline);
660+
661+
const update = JSON.parse(JSON.stringify(pipeline));
662+
update.source = [
663+
{
664+
type: "http",
665+
format: "json",
666+
authenticated: true,
667+
},
668+
];
669+
const updateReq = mockUpdateRequest(update.name, update);
670+
671+
await runWrangler(
672+
"pipelines update my-pipeline --cors-origins http://localhost:8787"
673+
);
674+
675+
expect(updateReq.count).toEqual(1);
676+
expect(updateReq.body?.source.length).toEqual(2);
677+
expect(updateReq.body?.source[1].type).toEqual("http");
678+
expect((updateReq.body?.source[1] as HttpSource).cors?.origins).toEqual([
679+
"http://localhost:8787",
680+
]);
681+
682+
mockGetRequest(pipeline.name, pipeline);
683+
const secondUpdateReq = mockUpdateRequest(update.name, update);
684+
await runWrangler("pipelines update my-pipeline --cors-origins none");
685+
expect(secondUpdateReq.count).toEqual(1);
686+
expect(secondUpdateReq.body?.source.length).toEqual(2);
687+
expect(secondUpdateReq.body?.source[1].type).toEqual("http");
688+
expect(
689+
(secondUpdateReq.body?.source[1] as HttpSource).cors?.origins
690+
).toEqual([]);
691+
});
692+
657693
it("should fail a missing pipeline", async () => {
658694
const requests = mockGetRequest("bad-pipeline", null, 404, {
659695
code: 1000,
@@ -704,8 +740,8 @@ describe("pipelines", () => {
704740

705741
expect(std.err).toMatchInlineSnapshot(`""`);
706742
expect(std.out).toMatchInlineSnapshot(`
707-
"Deleting Pipeline foo.
708-
Deleted Pipeline foo."
743+
"Deleting pipeline foo.
744+
Deleted pipeline foo."
709745
`);
710746
expect(requests.count).toEqual(1);
711747
});
@@ -723,7 +759,7 @@ describe("pipelines", () => {
723759

724760
expect(std.err).toMatchInlineSnapshot(`""`);
725761
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
726-
"Deleting Pipeline bad-pipeline.
762+
"Deleting pipeline bad-pipeline.
727763
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
728764
Pipeline does not exist [code: 1000]
729765
If you think this is a bug, please open an issue at:

packages/wrangler/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ export function createCLIParser(argv: string[]) {
958958
// [OPEN BETA] pipelines
959959
wrangler.command(
960960
"pipelines",
961-
`🚰 Manage Worker Pipelines ${chalk.hex(betaCmdColor)("[open beta]")}`,
961+
`🚰 Manage Cloudflare Pipelines ${chalk.hex(betaCmdColor)("[open beta]")}`,
962962
(pipelinesYargs) => {
963963
return pipelines(pipelinesYargs.command(subHelp));
964964
}

packages/wrangler/src/pipelines/cli/create.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function addCreateOptions(yargs: Argv<CommonYargsOptions>) {
161161
.option("shard-count", {
162162
type: "number",
163163
describe:
164-
"Number of pipeline shards. More shards handle higher request volume; fewer shards produce larger output files. Defaults to 2 if unset. Minimum: 1, Maximum: 15",
164+
"Number of shards for the pipeline. More shards handle higher request volume; fewer shards produce larger output files. Defaults to 2 if unset. Minimum: 1, Maximum: 15",
165165
demandOption: false,
166166
})
167167
);
@@ -277,14 +277,14 @@ export async function createPipelineHandler(
277277
pipelineConfig.metadata.shards = args.shardCount;
278278
}
279279

280-
logger.log(`🌀 Creating Pipeline named "${name}"`);
280+
logger.log(`🌀 Creating pipeline named "${name}"`);
281281
const pipeline = await createPipeline(accountId, pipelineConfig);
282282

283283
logger.log(
284-
`✅ Successfully created Pipeline "${pipeline.name}" with ID ${pipeline.id}\n`
284+
`✅ Successfully created pipeline "${pipeline.name}" with ID ${pipeline.id}\n`
285285
);
286286
logger.log(formatPipelinePretty(pipeline));
287-
logger.log("🎉 You can now send data to your Pipeline!");
287+
logger.log("🎉 You can now send data to your pipeline!");
288288

289289
if (args.source.includes("worker")) {
290290
logger.log(
@@ -306,7 +306,7 @@ export async function createPipelineHandler(
306306
}
307307

308308
if (args.source.includes("http")) {
309-
logger.log(`\nSend data to your Pipeline's HTTP endpoint:\n`);
309+
logger.log(`\nSend data to your pipeline's HTTP endpoint:\n`);
310310
logger.log(`curl "${pipeline.endpoint}" -d '[{"foo": "bar"}]'\n`);
311311
}
312312
}

packages/wrangler/src/pipelines/cli/delete.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { Argv } from "yargs";
1313
export function addDeleteOptions(yargs: Argv<CommonYargsOptions>) {
1414
return yargs.positional("pipeline", {
1515
type: "string",
16-
describe: "The name of the Pipeline to show",
16+
describe: "The name of the pipeline to delete",
1717
demandOption: true,
1818
});
1919
}
@@ -28,8 +28,8 @@ export async function deletePipelineHandler(
2828

2929
validateName("pipeline name", name);
3030

31-
logger.log(`Deleting Pipeline ${name}.`);
31+
logger.log(`Deleting pipeline ${name}.`);
3232
await deletePipeline(accountId, name);
3333

34-
logger.log(`Deleted Pipeline ${name}.`);
34+
logger.log(`Deleted pipeline ${name}.`);
3535
}

packages/wrangler/src/pipelines/cli/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function addGetOptions(yargs: Argv<CommonYargsOptions>) {
1616
return yargs
1717
.positional("pipeline", {
1818
type: "string",
19-
describe: "The name of the Pipeline to show",
19+
describe: "The name of the pipeline to inspect",
2020
demandOption: true,
2121
})
2222
.option("format", {

packages/wrangler/src/pipelines/cli/update.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import type { Argv } from "yargs";
2626
*/
2727
export function addUpdateOptions(yargs: Argv<CommonYargsOptions>) {
2828
/* These arguments are nearly identical to the option used for creating a pipeline, with some notable differences.
29-
Particularly, not all options are available for updating, and the default values have been removed. In this case,
29+
Particularly, not all options are available for updating, and the default values have been removed. In this case,
3030
`undefined` is used to determine if the user provided that flag at all with the intent to change the value.
3131
*/
3232
return (
3333
yargs
3434
.positional("pipeline", {
35-
describe: "The name of the Pipeline to update",
35+
describe: "The name of the pipeline to update",
3636
type: "string",
3737
demandOption: true,
3838
})
@@ -49,7 +49,7 @@ export function addUpdateOptions(yargs: Argv<CommonYargsOptions>) {
4949
.option("source", {
5050
type: "array",
5151
describe:
52-
"Space separated list of allowed sources. Options are 'http' or 'worker'. Setting this will remove all other existing sources.",
52+
"Space separated list of allowed sources. Options are 'http' or 'worker'",
5353
demandOption: false,
5454
})
5555
.option("require-http-auth", {
@@ -157,7 +157,7 @@ export function addUpdateOptions(yargs: Argv<CommonYargsOptions>) {
157157
.option("shard-count", {
158158
type: "number",
159159
describe:
160-
"Number of pipeline shards. More shards handle higher request volume; fewer shards produce larger output files",
160+
"Number of shards for the pipeline. More shards handle higher request volume; fewer shards produce larger output files",
161161
demandOption: false,
162162
})
163163
);
@@ -227,18 +227,12 @@ export async function updatePipelineHandler(
227227
http: (): HttpSource => {
228228
const existing = existingSources.find((s: Source) => s.type === "http");
229229

230-
const http: HttpSource = {
230+
return {
231231
...existing, // Copy over existing properties for forwards compatibility
232232
type: "http",
233233
format: "json",
234234
...(args.requireHttpAuth && { authentication: args.requireHttpAuth }), // Include only if defined
235235
};
236-
237-
if (args.corsOrigins && args.corsOrigins.length > 0) {
238-
http.cors = { origins: args.corsOrigins };
239-
}
240-
241-
return http;
242236
},
243237
worker: (): BindingSource => {
244238
const existing = existingSources.find(
@@ -293,15 +287,15 @@ export async function updatePipelineHandler(
293287
if (args.requireHttpAuth) {
294288
httpSource.authentication = args.requireHttpAuth;
295289
}
296-
if (args.corsOrigins && args.corsOrigins.length > 0) {
290+
if (args.corsOrigins) {
297291
httpSource.cors = { origins: args.corsOrigins };
298292
}
299293
}
300294

301-
logger.log(`🌀 Updating Pipeline "${name}"`);
295+
logger.log(`🌀 Updating pipeline "${name}"`);
302296
const pipeline = await updatePipeline(accountId, name, pipelineConfig);
303297

304298
logger.log(
305-
`✅ Successfully updated Pipeline "${pipeline.name}" with ID ${pipeline.id}\n`
299+
`✅ Successfully updated pipeline "${pipeline.name}" with ID ${pipeline.id}\n`
306300
);
307301
}

packages/wrangler/src/pipelines/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,31 @@ export function pipelines(pipelineYargs: CommonYargsArgv) {
125125
return pipelineYargs
126126
.command(
127127
"create <pipeline>",
128-
"Create a new Pipeline",
128+
"Create a new pipeline",
129129
addCreateOptions,
130130
createPipelineHandler
131131
)
132132
.command(
133133
"list",
134-
"List current Pipelines",
134+
"List all pipelines",
135135
(yargs) => yargs,
136136
listPipelinesHandler
137137
)
138138
.command(
139139
"get <pipeline>",
140-
"Get a Pipeline configuration",
140+
"Get a pipeline's configuration",
141141
addGetOptions,
142142
getPipelineHandler
143143
)
144144
.command(
145145
"update <pipeline>",
146-
"Update a Pipeline",
146+
"Update a pipeline",
147147
addUpdateOptions,
148148
updatePipelineHandler
149149
)
150150
.command(
151151
"delete <pipeline>",
152-
"Delete a Pipeline",
152+
"Delete a pipeline",
153153
addDeleteOptions,
154154
deletePipelineHandler
155155
);

packages/wrangler/src/pipelines/validate.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ export function validateCorsOrigins(values: string[] | undefined) {
1111
return values;
1212
}
1313

14+
// If none provided, ignore other options
15+
if (values.includes("none")) {
16+
if (values.length > 1) {
17+
throw new UserError(
18+
"When specifying 'none', only one value is permitted."
19+
);
20+
}
21+
return [];
22+
}
23+
1424
// If wildcard provided, ignore other options
1525
if (values.includes("*")) {
1626
if (values.length > 1) {
1727
throw new UserError("When specifying '*', only one value is permitted.");
1828
}
19-
return values;
29+
return values; // ["*"]
2030
}
2131

2232
// Ensure any value matches the format for a CORS origin

0 commit comments

Comments
 (0)