Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update R2 CreateBucket to include storage class in request body #5561

Merged
merged 2 commits into from
Apr 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-squids-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feat: update R2 CreateBucket action to include the storage class in the request body
13 changes: 5 additions & 8 deletions packages/wrangler/src/__tests__/helpers/msw/handlers/r2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ export const mswR2handlers = [
),
rest.post(
"*/accounts/:accountId/r2/buckets",
(request, response, context) => {
const storageClassValue = request.headers.get("cf-r2-storage-class");
if (
storageClassValue !== null &&
!isValidStorageClass(storageClassValue)
) {
async (request, response, context) => {
const { storageClass } = await request.json();
if (storageClass !== null && !isValidStorageClass(storageClass)) {
return response.once(
context.status(400),
context.json({
success: false,
errors: [
{
code: 10062,
message: "The storage class specified is not valid.",
code: 10040,
message: "The JSON you provided was not well formed.",
},
],
messages: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe("r2", () => {

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.

The storage class specified is not valid. [code: 10062]
The JSON you provided was not well formed. [code: 10040]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/r2/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export async function createR2Bucket(
if (jurisdiction !== undefined) {
headers["cf-r2-jurisdiction"] = jurisdiction;
}
if (storageClass !== undefined) {
headers["cf-r2-storage-class"] = storageClass;
}
return await fetchResult<void>(`/accounts/${accountId}/r2/buckets`, {
method: "POST",
body: JSON.stringify({ name: bucketName }),
body: JSON.stringify({
name: bucketName,
...(storageClass !== undefined && { storageClass }),
}),
headers,
});
}
Expand Down