Skip to content

Commit 8581663

Browse files
committed
Remove enabled option from r2 bucket domain add and update. Added confirmation prompt to add.
1 parent 3455178 commit 8581663

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
@@ -1497,7 +1497,7 @@ describe("r2", () => {
14971497
)
14981498
);
14991499
await runWrangler(
1500-
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId}`
1500+
`r2 bucket domain add ${bucketName} --domain ${domainName} --zone-id ${zoneId} --force`
15011501
);
15021502
expect(std.out).toMatchInlineSnapshot(`
15031503
"Connecting custom domain 'example.com' to bucket 'my-bucket'...
@@ -1508,7 +1508,7 @@ describe("r2", () => {
15081508
it("should error if domain and zone-id are not provided", async () => {
15091509
const bucketName = "my-bucket";
15101510
await expect(
1511-
runWrangler(`r2 bucket domain add ${bucketName}`)
1511+
runWrangler(`r2 bucket domain add ${bucketName} --force`)
15121512
).rejects.toThrowErrorMatchingInlineSnapshot(
15131513
`[Error: Missing required arguments: domain, zone-id]`
15141514
);
@@ -1632,7 +1632,6 @@ describe("r2", () => {
16321632
const requestBody = await request.json();
16331633
expect(requestBody).toEqual({
16341634
domain: domainName,
1635-
enabled: false,
16361635
minTLS: "1.3",
16371636
});
16381637
return HttpResponse.json(createFetchResult({}));
@@ -1641,7 +1640,7 @@ describe("r2", () => {
16411640
)
16421641
);
16431642
await runWrangler(
1644-
`r2 bucket domain update ${bucketName} --domain ${domainName} --enabled false --min-tls 1.3`
1643+
`r2 bucket domain update ${bucketName} --domain ${domainName} --min-tls 1.3`
16451644
);
16461645
expect(std.out).toMatchInlineSnapshot(`
16471646
"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
@@ -610,7 +610,6 @@ export async function deleteEventNotificationConfig(
610610

611611
export interface CustomDomainConfig {
612612
domain: string;
613-
enabled?: boolean;
614613
minTLS?: string;
615614
zoneId?: string;
616615
}
@@ -645,7 +644,10 @@ export async function attachCustomDomainToBucket(
645644
{
646645
method: "POST",
647646
headers,
648-
body: JSON.stringify(config),
647+
body: JSON.stringify({
648+
...config,
649+
enabled: true,
650+
}),
649651
}
650652
);
651653
}

0 commit comments

Comments
 (0)