Skip to content

Commit 0923994

Browse files
committed
Ensure API is enabled for frameworks commands.
1 parent a3f5163 commit 0923994

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

src/commands/frameworks-backends-create.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Options } from "../options";
33
import { needProjectId } from "../projectUtils";
44
import requireInteractive from "../requireInteractive";
55
import { doSetup } from "../init/features/frameworks";
6+
import { ensureApiEnabled } from "../gcp/frameworks";
67

78
export const command = new Command("backends:create")
89
.description("Create a backend in a Firebase project")
10+
.before(ensureApiEnabled)
911
.before(requireInteractive)
1012
.action(async (options: Options) => {
1113
const projectId = needProjectId(options);

src/commands/frameworks-backends-delete.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { promptOnce } from "../prompt";
77
import * as utils from "../utils";
88
import { logger } from "../logger";
99
import { DEFAULT_REGION, ALLOWED_REGIONS } from "../init/features/frameworks/constants";
10+
import { ensureApiEnabled } from "../gcp/frameworks";
11+
1012
const Table = require("cli-table");
1113

1214
const COLUMN_LENGTH = 20;
@@ -24,6 +26,7 @@ export const command = new Command("backends:delete")
2426
.option("-l, --location <location>", "App Backend location", "")
2527
.option("-s, --backend <backend>", "Backend Id", "")
2628
.withForce()
29+
.before(ensureApiEnabled)
2730
.action(async (options: Options) => {
2831
const projectId = needProjectId(options);
2932
let location = options.location as string;

src/commands/frameworks-backends-get.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { needProjectId } from "../projectUtils";
44
import * as gcp from "../gcp/frameworks";
55
import { FirebaseError } from "../error";
66
import { logger } from "../logger";
7+
import { ensureApiEnabled } from "../gcp/frameworks";
8+
79
const Table = require("cli-table");
810
const COLUMN_LENGTH = 20;
911
const TABLE_HEAD = [
@@ -18,6 +20,7 @@ export const command = new Command("backends:get")
1820
.description("Get backend details of a Firebase project")
1921
.option("-l, --location <location>", "App Backend location", "-")
2022
.option("-b, --backend <backend>", "Backend Id", "")
23+
.before(ensureApiEnabled)
2124
.action(async (options: Options) => {
2225
const projectId = needProjectId(options);
2326
const location = options.location as string;

src/commands/frameworks-backends-list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as gcp from "../gcp/frameworks";
55
import { FirebaseError } from "../error";
66
import { logger } from "../logger";
77
import { bold } from "colorette";
8+
import { ensureApiEnabled } from "../gcp/frameworks";
89

910
const Table = require("cli-table");
1011
const COLUMN_LENGTH = 20;
@@ -19,6 +20,7 @@ const TABLE_HEAD = [
1920
export const command = new Command("backends:list")
2021
.description("List backends of a Firebase project.")
2122
.option("-l, --location <location>", "App Backend location", "-")
23+
.before(ensureApiEnabled)
2224
.action(async (options: Options) => {
2325
const projectId = needProjectId(options);
2426
const location = options.location as string;

src/gcp/frameworks.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Client } from "../apiv2";
2+
import { needProjectId } from "../projectUtils";
23
import { frameworksOrigin } from "../api";
4+
import { ensure } from "../ensureApiEnabled";
35

6+
export const API_HOST = new URL(frameworksOrigin).host;
47
export const API_VERSION = "v1alpha";
58

69
const client = new Client({
@@ -162,3 +165,11 @@ export async function createBuild(
162165

163166
return res.body;
164167
}
168+
169+
/**
170+
* Ensure that Frameworks API is enabled on the project.
171+
*/
172+
export async function ensureApiEnabled(options: any): Promise<void> {
173+
const projectId = needProjectId(options);
174+
return await ensure(projectId, API_HOST, "frameworks");
175+
}

0 commit comments

Comments
 (0)