Skip to content

Commit 1c42466

Browse files
authored
Making explicit that if a body is sent to delete event notification config rules it is sent with an array of ruleIds (#6706)
1 parent 7c95836 commit 1c42466

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

.changeset/blue-bags-walk.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+
fix: making explicit to only send a body if there are rule ids specified in the config delete

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,10 @@ describe("r2", () => {
10211021
-v, --version Show version number [boolean]
10221022
10231023
OPTIONS
1024-
--event-types, --event-type Specify the kinds of object events to emit notifications for. ex. '--event-types object-create object-delete' [array] [required] [choices: \\"object-create\\", \\"object-delete\\"]
1025-
--prefix only actions on objects with this prefix will emit notifications [string]
1026-
--suffix only actions on objects with this suffix will emit notifications [string]
1027-
--queue The name of the queue to which event notifications will be sent. ex '--queue my-queue' [string] [required]"
1024+
--event-types, --event-type The type of event(s) that will emit event notifications [array] [required] [choices: \\"object-create\\", \\"object-delete\\"]
1025+
--prefix The prefix that an object must match to emit event notifications (note: regular expressions not supported) [string]
1026+
--suffix The suffix that an object must match to emit event notifications (note: regular expressions not supported) [string]
1027+
--queue The name of the queue that will receive event notification messages [string] [required]"
10281028
`);
10291029
});
10301030
});
@@ -1039,6 +1039,7 @@ describe("r2", () => {
10391039
async ({ request, params }) => {
10401040
const { accountId } = params;
10411041
expect(accountId).toEqual("some-account-id");
1042+
expect(request.body).toBeNull();
10421043
expect(request.headers.get("authorization")).toEqual(
10431044
"Bearer some-api-token"
10441045
);
@@ -1100,6 +1101,9 @@ describe("r2", () => {
11001101
async ({ request, params }) => {
11011102
const { accountId } = params;
11021103
expect(accountId).toEqual("some-account-id");
1104+
expect(request.body).not.toBeNull();
1105+
const requestBody = await request.text();
1106+
expect(requestBody).toContain(`"ruleIds":["${ruleId}"]`);
11031107
expect(request.headers.get("authorization")).toEqual(
11041108
"Bearer some-api-token"
11051109
);
@@ -1174,8 +1178,8 @@ describe("r2", () => {
11741178
-v, --version Show version number [boolean]
11751179
11761180
OPTIONS
1177-
--queue The name of the queue that is configured to receive notifications. ex '--queue my-queue' [string] [required]
1178-
--rule The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted. [string]"
1181+
--queue The name of the queue that will receive event notification messages [string] [required]
1182+
--rule The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted [string]"
11791183
`);
11801184
});
11811185
});

packages/wrangler/src/r2/helpers.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,24 @@ export async function deleteEventNotificationConfig(
584584
logger.log(
585585
`Disabling event notifications for "${bucketName}" to queue ${queueName}...`
586586
);
587-
588-
const body: DeleteNotificationRequestBody =
589-
ruleId !== undefined
590-
? {
591-
ruleIds: [ruleId],
592-
}
593-
: {};
594-
595-
return await fetchResult<null>(
596-
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
597-
{ method: "DELETE", body: JSON.stringify(body), headers }
598-
);
587+
if (ruleId !== undefined) {
588+
const body: DeleteNotificationRequestBody =
589+
ruleId !== undefined
590+
? {
591+
ruleIds: [ruleId],
592+
}
593+
: {};
594+
595+
return await fetchResult<null>(
596+
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
597+
{ method: "DELETE", body: JSON.stringify(body), headers }
598+
);
599+
} else {
600+
return await fetchResult<null>(
601+
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
602+
{ method: "DELETE", headers }
603+
);
604+
}
599605
}
600606

601607
/**

packages/wrangler/src/r2/notification.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export function CreateOptions(yargs: CommonYargsArgv) {
4949
demandOption: true,
5050
})
5151
.option("event-types", {
52-
describe:
53-
"Specify the kinds of object events to emit notifications for. ex. '--event-types object-create object-delete'",
52+
describe: "The type of event(s) that will emit event notifications",
5453
alias: "event-type",
5554
choices: Object.keys(actionsForEventCategories),
5655
demandOption: true,
@@ -59,18 +58,18 @@ export function CreateOptions(yargs: CommonYargsArgv) {
5958
})
6059
.option("prefix", {
6160
describe:
62-
"only actions on objects with this prefix will emit notifications",
61+
"The prefix that an object must match to emit event notifications (note: regular expressions not supported)",
6362
requiresArg: false,
6463
type: "string",
6564
})
6665
.option("suffix", {
6766
describe:
68-
"only actions on objects with this suffix will emit notifications",
67+
"The suffix that an object must match to emit event notifications (note: regular expressions not supported)",
6968
type: "string",
7069
})
7170
.option("queue", {
7271
describe:
73-
"The name of the queue to which event notifications will be sent. ex '--queue my-queue'",
72+
"The name of the queue that will receive event notification messages",
7473
demandOption: true,
7574
requiresArg: true,
7675
type: "string",
@@ -108,14 +107,14 @@ export function DeleteOptions(yargs: CommonYargsArgv) {
108107
})
109108
.option("queue", {
110109
describe:
111-
"The name of the queue that is configured to receive notifications. ex '--queue my-queue'",
110+
"The name of the queue that will receive event notification messages",
112111
demandOption: true,
113112
requiresArg: true,
114113
type: "string",
115114
})
116115
.option("rule", {
117116
describe:
118-
"The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted.",
117+
"The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted",
119118
requiresArg: false,
120119
type: "string",
121120
});

0 commit comments

Comments
 (0)