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
@@ -1 +1,2 @@
- Fixed issue where `firebase init firestore` would raise an error due to rules/indexes file path being undefined. (#8518)
- Fixed an issue where `firebase use` required `serviceusage.viewer` permissions. (#8519)
16 changes: 16 additions & 0 deletions src/ensureApiEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Client } from "./apiv2";
import * as utils from "./utils";
import { FirebaseError, isBillingError } from "./error";
import { logger } from "./logger";

export const POLL_SETTINGS = {
pollInterval: 10000,
Expand Down Expand Up @@ -49,7 +50,7 @@
* Attempt to enable an API on the specified project (just once).
*
* If enabling an API for a customer, prefer `ensure` which will check for the
* API first, which is a seperate permission than enabling.

Check warning on line 53 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param projectId The project in which to enable the API.
* @param apiName The name of the API e.g. `someapi.googleapis.com`.
Expand All @@ -64,8 +65,8 @@
skipLog: { resBody: true },
},
);
} catch (err: any) {

Check warning on line 68 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (isBillingError(err)) {

Check warning on line 69 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `{ context?: { body?: { error?: { details?: { type: string; reason?: string | undefined; violations?: { type: string; }[] | undefined; }[] | undefined; } | undefined; } | undefined; } | undefined; }`
throw new FirebaseError(`Your project ${bold(
projectId,
)} must be on the Blaze (pay-as-you-go) plan to complete this command. Required API ${bold(
Expand All @@ -73,7 +74,7 @@
)} can't be enabled until the upgrade is complete. To upgrade, visit the following URL:

https://console.firebase.google.com/project/${projectId}/usage/details`);
} else if (isPermissionError(err)) {

Check warning on line 77 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `{ context?: { body?: { error?: { status?: string | undefined; } | undefined; } | undefined; } | undefined; }`
const apiPermissionDeniedRegex = new RegExp(
/Permission denied to enable service \[([.a-zA-Z]+)\]/,
);
Expand Down Expand Up @@ -146,7 +147,7 @@
}

/**
* Check if an API is enabled on a project, try to enable it if not with polling and retries.

Check warning on line 150 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param projectId The project on which to check enablement.
* @param apiUri The name of the API e.g. `someapi.googleapis.com`.
Expand All @@ -173,9 +174,24 @@
return enableApiWithRetries(projectId, hostname, prefix, silent);
}

export async function bestEffortEnsure(

Check warning on line 177 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
projectId: string,
apiUri: string,
prefix: string,
silent = false,
): Promise<void> {
try {
await ensure(projectId, apiUri, prefix, silent);
} catch (err: any) {

Check warning on line 185 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
logger.debug(
`Unable to check that ${apiUri} is enabled on ${projectId}. Calls to it will fail if it is not enabled`,
);
}
}

/**
* Returns a link to enable an API on a project in Cloud console. This can be used instead of ensure
* in contexts where automatically enabling APIs is not desirable (ie emulator commands).

Check warning on line 194 in src/ensureApiEnabled.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected only 0 line after block description
*
* @param projectId The project to generate an API enablement link for
* @param apiName The name of the API e.g. `someapi.googleapis.com`.
Expand Down
4 changes: 2 additions & 2 deletions src/management/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { logger } from "../logger";
import * as utils from "../utils";
import { FirebaseProjectMetadata, CloudProjectInfo, ProjectPage } from "../types/project";
import { ensure } from "../ensureApiEnabled";
import { bestEffortEnsure } from "../ensureApiEnabled";

const TIMEOUT_MILLIS = 30000;
const MAXIMUM_PROMPT_LIST = 100;
Expand All @@ -26,7 +26,7 @@
type: ProjectParentResourceType;
}

export async function promptProjectCreation(): Promise<{ projectId: string; displayName: string }> {

Check warning on line 29 in src/management/projects.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const projectId = await prompt.input({
message:
"Please specify a unique project id " +
Expand Down Expand Up @@ -70,7 +70,7 @@
apiVersion: "v1",
});

export async function createFirebaseProjectAndLog(

Check warning on line 73 in src/management/projects.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
projectId: string,
options: { displayName?: string; parentResource?: ProjectParentResource },
): Promise<FirebaseProjectMetadata> {
Expand Down Expand Up @@ -469,7 +469,7 @@
* @param projectId
*/
export async function getProject(projectId: string): Promise<ProjectInfo> {
await ensure(projectId, api.resourceManagerOrigin(), "firebase", true);
await bestEffortEnsure(projectId, api.resourceManagerOrigin(), "firebase", true);
const response = await resourceManagerClient.get<ProjectInfo>(`/projects/${projectId}`);
return response.body;
}
Loading