diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aae097dfd5..11407829ccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/ensureApiEnabled.ts b/src/ensureApiEnabled.ts index 781f10d5957..6085ff1d3d6 100644 --- a/src/ensureApiEnabled.ts +++ b/src/ensureApiEnabled.ts @@ -5,6 +5,7 @@ import { serviceUsageOrigin } from "./api"; import { Client } from "./apiv2"; import * as utils from "./utils"; import { FirebaseError, isBillingError } from "./error"; +import { logger } from "./logger"; export const POLL_SETTINGS = { pollInterval: 10000, @@ -173,6 +174,21 @@ export async function ensure( return enableApiWithRetries(projectId, hostname, prefix, silent); } +export async function bestEffortEnsure( + projectId: string, + apiUri: string, + prefix: string, + silent = false, +): Promise { + try { + await ensure(projectId, apiUri, prefix, silent); + } catch (err: any) { + 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). diff --git a/src/management/projects.ts b/src/management/projects.ts index 20ad83ce84f..bb20be18d74 100644 --- a/src/management/projects.ts +++ b/src/management/projects.ts @@ -9,7 +9,7 @@ import * as api from "../api"; 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; @@ -469,7 +469,7 @@ export interface ProjectInfo { * @param projectId */ export async function getProject(projectId: string): Promise { - await ensure(projectId, api.resourceManagerOrigin(), "firebase", true); + await bestEffortEnsure(projectId, api.resourceManagerOrigin(), "firebase", true); const response = await resourceManagerClient.get(`/projects/${projectId}`); return response.body; }