Skip to content

Commit 8040437

Browse files
authored
Accidentally expanded the required permissions for firebase use (#8531)
* Accidentally expanded the required permissions for firebase use * Await * fix + type * typo
1 parent 4ef94df commit 8040437

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Fixed issue where `firebase init firestore` would raise an error due to rules/indexes file path being undefined. (#8518)
2+
- Fixed an issue where `firebase use` required `serviceusage.viewer` permissions. (#8519)

src/ensureApiEnabled.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { serviceUsageOrigin } from "./api";
55
import { Client } from "./apiv2";
66
import * as utils from "./utils";
77
import { FirebaseError, isBillingError } from "./error";
8+
import { logger } from "./logger";
89

910
export const POLL_SETTINGS = {
1011
pollInterval: 10000,
@@ -173,6 +174,21 @@ export async function ensure(
173174
return enableApiWithRetries(projectId, hostname, prefix, silent);
174175
}
175176

177+
export async function bestEffortEnsure(
178+
projectId: string,
179+
apiUri: string,
180+
prefix: string,
181+
silent = false,
182+
): Promise<void> {
183+
try {
184+
await ensure(projectId, apiUri, prefix, silent);
185+
} catch (err: any) {
186+
logger.debug(
187+
`Unable to check that ${apiUri} is enabled on ${projectId}. Calls to it will fail if it is not enabled`,
188+
);
189+
}
190+
}
191+
176192
/**
177193
* Returns a link to enable an API on a project in Cloud console. This can be used instead of ensure
178194
* in contexts where automatically enabling APIs is not desirable (ie emulator commands).

src/management/projects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as api from "../api";
99
import { logger } from "../logger";
1010
import * as utils from "../utils";
1111
import { FirebaseProjectMetadata, CloudProjectInfo, ProjectPage } from "../types/project";
12-
import { ensure } from "../ensureApiEnabled";
12+
import { bestEffortEnsure } from "../ensureApiEnabled";
1313

1414
const TIMEOUT_MILLIS = 30000;
1515
const MAXIMUM_PROMPT_LIST = 100;
@@ -469,7 +469,7 @@ export interface ProjectInfo {
469469
* @param projectId
470470
*/
471471
export async function getProject(projectId: string): Promise<ProjectInfo> {
472-
await ensure(projectId, api.resourceManagerOrigin(), "firebase", true);
472+
await bestEffortEnsure(projectId, api.resourceManagerOrigin(), "firebase", true);
473473
const response = await resourceManagerClient.get<ProjectInfo>(`/projects/${projectId}`);
474474
return response.body;
475475
}

0 commit comments

Comments
 (0)