Skip to content

Commit dc02291

Browse files
abhis3joehan
andauthored
GetStorageDefaultBucket through Storage API (#6471)
* GetStorageDefaultBucket through Storage API * pretty it up * Update CHANGELOG.md --------- Co-authored-by: joehan <[email protected]>
1 parent dea0741 commit dc02291

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
- Fix blocking functions in the emulator when using multiple codebases (#6504).
2-
- Add force flag call-out for bypassing prompts (#6506).
1+
- Breaking: dropped support for running the CLI on Node.js v16.
2+
- Added support for running the CLI on Node.js v20. Installations from https://firebase.tools will now use Node.js 20.
3+
- Switched Storage deployment to use GetDefaultBucket endpoint to fetch default Storage bucket. (#6467)
4+
- Fixed an issue with emulating blocking functions when using multiple codebases (#6504).
5+
- Added force flag call-out for bypassing prompts (#6506).

src/gcp/storage.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Readable } from "stream";
22
import * as path from "path";
33

4-
import { storageOrigin } from "../api";
4+
import { firebaseStorageOrigin, storageOrigin } from "../api";
55
import { Client } from "../apiv2";
66
import { FirebaseError } from "../error";
77
import { logger } from "../logger";
8-
import { getFirebaseProject } from "../management/projects";
8+
import { ensure } from "../ensureApiEnabled";
99

1010
/** Bucket Interface */
1111
interface BucketResponse {
@@ -133,22 +133,34 @@ interface ListBucketsResponse {
133133
];
134134
}
135135

136+
interface GetDefaultBucketResponse {
137+
name: string;
138+
location: string;
139+
bucket: {
140+
name: string;
141+
};
142+
}
143+
136144
/** Response type for obtaining the storage service agent */
137145
interface StorageServiceAccountResponse {
138146
email_address: string;
139147
kind: string;
140148
}
141149

142150
export async function getDefaultBucket(projectId: string): Promise<string> {
151+
await ensure(projectId, "firebasestorage.googleapis.com", "storage", false);
143152
try {
144-
const metadata = await getFirebaseProject(projectId);
145-
if (!metadata.resources?.storageBucket) {
153+
const localAPIClient = new Client({ urlPrefix: firebaseStorageOrigin, apiVersion: "v1alpha" });
154+
const response = await localAPIClient.get<GetDefaultBucketResponse>(
155+
`/projects/${projectId}/defaultBucket`
156+
);
157+
if (!response.body?.bucket.name) {
146158
logger.debug("Default storage bucket is undefined.");
147159
throw new FirebaseError(
148160
"Your project is being set up. Please wait a minute before deploying again."
149161
);
150162
}
151-
return metadata.resources.storageBucket;
163+
return response.body.bucket.name.split("/").pop()!;
152164
} catch (err: any) {
153165
logger.info(
154166
"\n\nThere was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support."

0 commit comments

Comments
 (0)