Skip to content

Commit

Permalink
Add confirmation for removing custom domain from R2 bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesphillip committed Oct 26, 2024
1 parent 98976f2 commit a4a4750
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { actionsForEventCategories } from "../r2/helpers";
import { endEventLoop } from "./helpers/end-event-loop";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
import { mockConfirm } from "./helpers/mock-dialogs";
import { useMockIsTTY } from "./helpers/mock-istty";
import { createFetchResult, msw, mswR2handlers } from "./helpers/msw";
import { runInTempDir } from "./helpers/run-in-tmp";
Expand Down Expand Up @@ -1581,7 +1582,7 @@ describe("r2", () => {
)
);
await runWrangler(
`r2 bucket domain remove ${bucketName} --domain ${domainName}`
`r2 bucket domain remove ${bucketName} --domain ${domainName} --force`
);
expect(std.out).toMatchInlineSnapshot(`
"Removing custom domain 'example.com' from bucket 'my-bucket'...
Expand Down
18 changes: 17 additions & 1 deletion packages/wrangler/src/r2/domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readConfig } from "../config";
import { confirm } from "../dialogs";
import { logger } from "../logger";
import { printWranglerBanner } from "../update-check";
import { requireAuth } from "../user";
Expand Down Expand Up @@ -142,6 +143,12 @@ export function RemoveOptions(yargs: CommonYargsArgv) {
alias: "J",
requiresArg: true,
type: "string",
})
.option("force", {
describe: "Skip confirmation",
type: "boolean",
alias: "y",
default: false,
});
}

Expand All @@ -152,8 +159,17 @@ export async function RemoveHandler(
const config = readConfig(args.config, args);
const accountId = await requireAuth(config);

const { bucket, domain, jurisdiction } = args;
const { bucket, domain, jurisdiction, force } = args;

if (!force) {
const confirmedRemoval = await confirm(
`Are you sure you want to remove the custom domain '${domain}' from bucket '${bucket}'? Your bucket will no longer be available from 'https://${domain}'`
);
if (!confirmedRemoval) {
logger.log("Removal cancelled.");
return;
}
}
logger.log(`Removing custom domain '${domain}' from bucket '${bucket}'...`);

await removeCustomDomainFromBucket(accountId, bucket, domain, jurisdiction);
Expand Down

0 comments on commit a4a4750

Please sign in to comment.