Skip to content

Commit

Permalink
Ensure API is enabled for frameworks commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold committed Dec 6, 2023
1 parent 1b7de46 commit 700f7a2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commands/frameworks-backends-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import requireInteractive from "../requireInteractive";
import { doSetup } from "../init/features/frameworks";
import { ensureApiEnabled } from "../gcp/frameworks";

export const command = new Command("backends:create")
.description("Create a backend in a Firebase project")
.before(ensureApiEnabled)
.before(requireInteractive)
.action(async (options: Options) => {
const projectId = needProjectId(options);
Expand Down
3 changes: 3 additions & 0 deletions src/commands/frameworks-backends-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { promptOnce } from "../prompt";
import * as utils from "../utils";
import { logger } from "../logger";
import { DEFAULT_REGION, ALLOWED_REGIONS } from "../init/features/frameworks/constants";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");

Check warning on line 12 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 12 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

const COLUMN_LENGTH = 20;
Expand All @@ -24,6 +26,7 @@ export const command = new Command("backends:delete")
.option("-l, --location <location>", "App Backend location", "")
.option("-s, --backend <backend>", "Backend Id", "")
.withForce()
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
let location = options.location as string;
Expand Down
3 changes: 3 additions & 0 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
const TABLE_HEAD = [
Expand All @@ -18,6 +20,7 @@ export const command = new Command("backends:get")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "-")
.option("-b, --backend <backend>", "Backend Id", "")
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
Expand Down
2 changes: 2 additions & 0 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
export const command = new Command("backends:list")
.description("List backends of a Firebase project.")
.option("-l, --location <location>", "App Backend location", "-")
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
Expand Down
11 changes: 11 additions & 0 deletions src/gcp/frameworks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Client } from "../apiv2";
import { needProjectId } from "../projectUtils";
import { frameworksOrigin } from "../api";
import { ensure } from "../ensureApiEnabled";

export const API_HOST = new URL(frameworksOrigin).host;
export const API_VERSION = "v1alpha";

const client = new Client({
Expand Down Expand Up @@ -162,3 +165,11 @@ export async function createBuild(

return res.body;
}

/**
* Ensure that Frameworks API is enabled on the project.
*/
export async function ensureApiEnabled(options: any): Promise<void> {
const projectId = needProjectId(options);
return await ensure(projectId, API_HOST, "frameworks", true);
}

0 comments on commit 700f7a2

Please sign in to comment.