Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed an issue where Storage rules could not be deployed to projects without a billing plan. (#5955)
4 changes: 0 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export const appDistributionOrigin = utils.envOverride(
"FIREBASE_APP_DISTRIBUTION_URL",
"https://firebaseappdistribution.googleapis.com"
);
export const appengineOrigin = utils.envOverride(
"FIREBASE_APPENGINE_URL",
"https://appengine.googleapis.com"
);
export const authOrigin = utils.envOverride("FIREBASE_AUTH_URL", "https://accounts.google.com");
export const consoleOrigin = utils.envOverride(
"FIREBASE_CONSOLE_URL",
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/storage/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function (context: any, options: Options): Promise<void> {
const rulesDeploy = new RulesDeploy(options, RulesetServiceType.FIREBASE_STORAGE);
const rulesConfigsToDeploy: any[] = [];

if (!Array.isArray(rulesConfig)) {
if (!Array.isArray(rulesConfig) && options.project) {
const defaultBucket = await gcp.storage.getDefaultBucket(options.project);
rulesConfig = [Object.assign(rulesConfig, { bucket: defaultBucket })];
}
Expand Down
14 changes: 7 additions & 7 deletions src/gcp/storage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Readable } from "stream";
import * as path from "path";

import { appengineOrigin, storageOrigin } from "../api";
import { storageOrigin } from "../api";
import { Client } from "../apiv2";
import { logger } from "../logger";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { getFirebaseProject } from "../management/projects";

/** Bucket Interface */
interface BucketResponse {
Expand Down Expand Up @@ -138,17 +139,16 @@ interface StorageServiceAccountResponse {
kind: string;
}

export async function getDefaultBucket(projectId?: string): Promise<string> {
export async function getDefaultBucket(projectId: string): Promise<string> {
try {
const appengineClient = new Client({ urlPrefix: appengineOrigin, apiVersion: "v1" });
const resp = await appengineClient.get<{ defaultBucket: string }>(`/apps/${projectId}`);
if (resp.body.defaultBucket === "undefined") {
const metadata = await getFirebaseProject(projectId);
if (!metadata.resources?.storageBucket) {
logger.debug("Default storage bucket is undefined.");
throw new FirebaseError(
"Your project is being set up. Please wait a minute before deploying again."
);
}
return resp.body.defaultBucket;
return metadata.resources.storageBucket;
} catch (err: any) {
logger.info(
"\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."
Expand Down