Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/blue-bags-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: making explicit to only send a body if there are rule ids specified in the config delete
16 changes: 10 additions & 6 deletions packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,10 @@ describe("r2", () => {
-v, --version Show version number [boolean]

OPTIONS
--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\\"]
--prefix only actions on objects with this prefix will emit notifications [string]
--suffix only actions on objects with this suffix will emit notifications [string]
--queue The name of the queue to which event notifications will be sent. ex '--queue my-queue' [string] [required]"
--event-types, --event-type The type of event(s) that will emit event notifications [array] [required] [choices: \\"object-create\\", \\"object-delete\\"]
--prefix The prefix that an object must match to emit event notifications (note: regular expressions not supported) [string]
--suffix The suffix that an object must match to emit event notifications (note: regular expressions not supported) [string]
--queue The name of the queue that will receive event notification messages [string] [required]"
`);
});
});
Expand All @@ -1039,6 +1039,7 @@ describe("r2", () => {
async ({ request, params }) => {
const { accountId } = params;
expect(accountId).toEqual("some-account-id");
expect(request.body).toBeNull();
expect(request.headers.get("authorization")).toEqual(
"Bearer some-api-token"
);
Expand Down Expand Up @@ -1100,6 +1101,9 @@ describe("r2", () => {
async ({ request, params }) => {
const { accountId } = params;
expect(accountId).toEqual("some-account-id");
expect(request.body).not.toBeNull();
const requestBody = await request.text();
expect(requestBody).toContain(`"ruleIds":["${ruleId}"]`);
expect(request.headers.get("authorization")).toEqual(
"Bearer some-api-token"
);
Expand Down Expand Up @@ -1174,8 +1178,8 @@ describe("r2", () => {
-v, --version Show version number [boolean]

OPTIONS
--queue The name of the queue that is configured to receive notifications. ex '--queue my-queue' [string] [required]
--rule The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted. [string]"
--queue The name of the queue that will receive event notification messages [string] [required]
--rule The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted [string]"
`);
});
});
Expand Down
30 changes: 18 additions & 12 deletions packages/wrangler/src/r2/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,24 @@ export async function deleteEventNotificationConfig(
logger.log(
`Disabling event notifications for "${bucketName}" to queue ${queueName}...`
);

const body: DeleteNotificationRequestBody =
ruleId !== undefined
? {
ruleIds: [ruleId],
}
: {};

return await fetchResult<null>(
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
{ method: "DELETE", body: JSON.stringify(body), headers }
);
if (ruleId !== undefined) {
const body: DeleteNotificationRequestBody =
ruleId !== undefined
? {
ruleIds: [ruleId],
}
: {};

return await fetchResult<null>(
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
{ method: "DELETE", body: JSON.stringify(body), headers }
);
} else {
return await fetchResult<null>(
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
{ method: "DELETE", headers }
);
}
}

/**
Expand Down
13 changes: 6 additions & 7 deletions packages/wrangler/src/r2/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export function CreateOptions(yargs: CommonYargsArgv) {
demandOption: true,
})
.option("event-types", {
describe:
"Specify the kinds of object events to emit notifications for. ex. '--event-types object-create object-delete'",
describe: "The type of event(s) that will emit event notifications",
alias: "event-type",
choices: Object.keys(actionsForEventCategories),
demandOption: true,
Expand All @@ -59,18 +58,18 @@ export function CreateOptions(yargs: CommonYargsArgv) {
})
.option("prefix", {
describe:
"only actions on objects with this prefix will emit notifications",
"The prefix that an object must match to emit event notifications (note: regular expressions not supported)",
requiresArg: false,
type: "string",
})
.option("suffix", {
describe:
"only actions on objects with this suffix will emit notifications",
"The suffix that an object must match to emit event notifications (note: regular expressions not supported)",
type: "string",
})
.option("queue", {
describe:
"The name of the queue to which event notifications will be sent. ex '--queue my-queue'",
"The name of the queue that will receive event notification messages",
demandOption: true,
requiresArg: true,
type: "string",
Expand Down Expand Up @@ -108,14 +107,14 @@ export function DeleteOptions(yargs: CommonYargsArgv) {
})
.option("queue", {
describe:
"The name of the queue that is configured to receive notifications. ex '--queue my-queue'",
"The name of the queue that will receive event notification messages",
demandOption: true,
requiresArg: true,
type: "string",
})
.option("rule", {
describe:
"The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted.",
"The id of the rule to delete. If no rule is specified, all rules for the bucket/queue configuration will be deleted",
requiresArg: false,
type: "string",
});
Expand Down