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

Use correct bucket name field when reading DefaultBucket for storage #6420

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/gcp/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
];
};
labels: {
(key: any): string;

Check warning on line 117 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
};
storageClass: string;
billing: {
Expand All @@ -133,39 +133,47 @@
];
}

interface GetDefaultBucketResponse {
name: string;
location: string;
bucket: {
name: string;
};
}

/** Response type for obtaining the storage service agent */
interface StorageServiceAccountResponse {
email_address: string;
kind: string;
}

export async function getDefaultBucket(projectId: string): Promise<string> {

Check warning on line 150 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Missing JSDoc comment
await ensure(projectId, "firebasestorage.googleapis.com", "storage", false);
try {
const localAPIClient = new Client({ urlPrefix: firebaseStorageOrigin, apiVersion: "v1alpha" });
const response = await localAPIClient.get<{ name: string }>(
const response = await localAPIClient.get<GetDefaultBucketResponse>(
`/projects/${projectId}/defaultBucket`
);
if (!response.body?.name) {
if (!response.body?.bucket.name) {
logger.debug("Default storage bucket is undefined.");
throw new FirebaseError(
"Your project is being set up. Please wait a minute before deploying again."
);
}
return response.body.name;
return response.body.bucket.name.split("/").pop()!;

Check warning on line 163 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Forbidden non-null assertion
} catch (err: any) {

Check warning on line 164 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
logger.info(
"\n\nThere was an issue deploying your Storage rules. 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."
"\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."
abhis3 marked this conversation as resolved.
Show resolved Hide resolved
);
throw err;
}
}

export async function upload(

Check warning on line 172 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Missing JSDoc comment
source: any,

Check warning on line 173 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
uploadUrl: string,
extraHeaders?: Record<string, string>
): Promise<any> {

Check warning on line 176 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
const url = new URL(uploadUrl);
const localAPIClient = new Client({ urlPrefix: url.origin, auth: false });
const res = await localAPIClient.request({
Expand All @@ -177,7 +185,7 @@
"content-type": "application/zip",
...extraHeaders,
},
body: source.stream,

Check warning on line 188 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 188 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .stream on an `any` value
skipLog: { resBody: true },
});
return {
Expand Down Expand Up @@ -219,7 +227,7 @@
* Deletes an object via Firebase Storage.
* @param {string} location A Firebase Storage location, of the form "/v0/b/<bucket>/o/<object>"
*/
export function deleteObject(location: string): Promise<any> {

Check warning on line 230 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
const localAPIClient = new Client({ urlPrefix: storageOrigin });
return localAPIClient.delete(location);
}
Expand Down
Loading