Skip to content

Commit 494fd92

Browse files
committed
Remove enabled option from r2 bucket domain add and update. Added confirmation prompt to add.
1 parent 5e44242 commit 494fd92

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ describe("r2", () => {
14731473
)
14741474
);
14751475
await runWrangler(
1476-
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId}`
1476+
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId} --force`
14771477
);
14781478
expect(std.out).toMatchInlineSnapshot(`
14791479
"Connecting custom domain 'example.com' to bucket 'my-bucket'...
@@ -1484,7 +1484,7 @@ describe("r2", () => {
14841484
it("should error if domain and zone-id are not provided", async () => {
14851485
const bucketName = "my-bucket";
14861486
await expect(
1487-
runWrangler(`r2 bucket domain add ${bucketName}`)
1487+
runWrangler(`r2 bucket domain add ${bucketName} --force`)
14881488
).rejects.toThrowErrorMatchingInlineSnapshot(
14891489
`[Error: Missing required arguments: domain, zone-id]`
14901490
);
@@ -1608,7 +1608,6 @@ describe("r2", () => {
16081608
const requestBody = await request.json();
16091609
expect(requestBody).toEqual({
16101610
domain: domainName,
1611-
enabled: false,
16121611
minTLS: "1.3",
16131612
});
16141613
return HttpResponse.json(createFetchResult({}));
@@ -1617,7 +1616,7 @@ describe("r2", () => {
16171616
)
16181617
);
16191618
await runWrangler(
1620-
`r2 bucket domain update ${bucketName} --domain ${domainName} --enabled false --min-tls 1.3`
1619+
`r2 bucket domain update ${bucketName} --domain ${domainName} --min-tls 1.3`
16211620
);
16221621
expect(std.out).toMatchInlineSnapshot(`
16231622
"Updating custom domain 'example.com' for bucket 'my-bucket'...

packages/wrangler/src/r2/domain.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ export function AddOptions(yargs: CommonYargsArgv) {
7474
type: "string",
7575
demandOption: true,
7676
})
77-
.option("enabled", {
78-
describe:
79-
"Whether to enable public access at the custom domain (default is enabled)",
80-
type: "boolean",
81-
})
8277
.option("min-tls", {
8378
describe:
8479
"Set the minimum TLS version for the custom domain (defaults to 1.0 if not set)",
@@ -90,6 +85,12 @@ export function AddOptions(yargs: CommonYargsArgv) {
9085
alias: "J",
9186
requiresArg: true,
9287
type: "string",
88+
})
89+
.option("force", {
90+
describe: "Skip confirmation",
91+
type: "boolean",
92+
alias: "y",
93+
default: false,
9394
});
9495
}
9596

@@ -100,14 +101,18 @@ export async function AddHandler(
100101
const config = readConfig(args.config, args);
101102
const accountId = await requireAuth(config);
102103

103-
const {
104-
bucket,
105-
domain,
106-
zoneId,
107-
enabled = true,
108-
minTls = "1.0",
109-
jurisdiction,
110-
} = args;
104+
const { bucket, domain, zoneId, minTls = "1.0", jurisdiction, force } = args;
105+
106+
if (!force) {
107+
const confirmedAdd = await confirm(
108+
`Are you sure you want to add the custom domain '${domain}' to bucket '${bucket}'? ` +
109+
`The contents of your bucket will be made publicly available at 'https://${domain}'`
110+
);
111+
if (!confirmedAdd) {
112+
logger.log("Add cancelled.");
113+
return;
114+
}
115+
}
111116

112117
logger.log(`Connecting custom domain '${domain}' to bucket '${bucket}'...`);
113118

@@ -117,7 +122,6 @@ export async function AddHandler(
117122
{
118123
domain,
119124
zoneId,
120-
enabled,
121125
minTLS: minTls,
122126
},
123127
jurisdiction
@@ -163,7 +167,8 @@ export async function RemoveHandler(
163167

164168
if (!force) {
165169
const confirmedRemoval = await confirm(
166-
`Are you sure you want to remove the custom domain '${domain}' from bucket '${bucket}'? Your bucket will no longer be available from 'https://${domain}'`
170+
`Are you sure you want to remove the custom domain '${domain}' from bucket '${bucket}'? ` +
171+
`Your bucket will no longer be available from 'https://${domain}'`
167172
);
168173
if (!confirmedRemoval) {
169174
logger.log("Removal cancelled.");
@@ -190,10 +195,6 @@ export function UpdateOptions(yargs: CommonYargsArgv) {
190195
type: "string",
191196
demandOption: true,
192197
})
193-
.option("enabled", {
194-
describe: "Enable or disable public access at the custom domain",
195-
type: "boolean",
196-
})
197198
.option("min-tls", {
198199
describe: "Update the minimum TLS version for the custom domain",
199200
choices: ["1.0", "1.1", "1.2", "1.3"],
@@ -214,7 +215,7 @@ export async function UpdateHandler(
214215
const config = readConfig(args.config, args);
215216
const accountId = await requireAuth(config);
216217

217-
const { bucket, domain, enabled, minTls, jurisdiction } = args;
218+
const { bucket, domain, minTls, jurisdiction } = args;
218219

219220
logger.log(`Updating custom domain '${domain}' for bucket '${bucket}'...`);
220221

@@ -224,7 +225,6 @@ export async function UpdateHandler(
224225
domain,
225226
{
226227
domain,
227-
enabled,
228228
minTLS: minTls,
229229
},
230230
jurisdiction

packages/wrangler/src/r2/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ export async function deleteEventNotificationConfig(
608608

609609
export interface CustomDomainConfig {
610610
domain: string;
611-
enabled?: boolean;
612611
minTLS?: string;
613612
zoneId?: string;
614613
}
@@ -643,7 +642,10 @@ export async function attachCustomDomainToBucket(
643642
{
644643
method: "POST",
645644
headers,
646-
body: JSON.stringify(config),
645+
body: JSON.stringify({
646+
...config,
647+
enabled: true,
648+
}),
647649
}
648650
);
649651
}

0 commit comments

Comments
 (0)