Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure API is enabled for frameworks commands. #6548

Merged
merged 1 commit into from
Dec 6, 2023
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
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,7 +7,9 @@
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;
const TABLE_HEAD = [
Expand All @@ -24,6 +26,7 @@
.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 All @@ -33,7 +36,7 @@
}

if (!location) {
location = await promptOnce({

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
name: "region",
type: "list",
default: DEFAULT_REGION,
Expand All @@ -42,24 +45,24 @@
});
}

const table = new Table({

Check warning on line 48 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 48 in src/commands/frameworks-backends-delete.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe construction of an any type value
head: TABLE_HEAD,
style: { head: ["green"] },
});
table.colWidths = COLUMN_LENGTH;

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .colWidths on an `any` value

let backend;
try {
backend = await gcp.getBackend(projectId, location, backendId);
populateTable(backend, table);
} catch (err: any) {

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
throw new FirebaseError(`No backends found with given parameters. Command aborted.`, {
original: err,

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
});
}

utils.logWarning("You are about to permanently delete the backend:");
logger.info(table.toString());

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `Error`

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .toString on an `any` value

const confirmDeletion = await promptOnce(
{
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but didn't we want to ensure all of the dependent APIs as well (in case the user manually toggles any of them off?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah let me tackle that problem in the follow up PR.

}
Loading