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

Fix tiny bug where backends:list command fails when API responds without any backend resources. #6547

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
19 changes: 6 additions & 13 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,42 @@
import { logger } from "../logger";
import { bold } from "colorette";

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

Check warning on line 9 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 9 in src/commands/frameworks-backends-list.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 = [
"Backend Id",
"Repository Name",
"Location",
"URL",
"Created Date",
"Updated Date",
];
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", "-")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const table = new Table({

Check warning on line 18 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .colWidths on an `any` value
const backendsList: gcp.ListBackendsResponse[] = [];
const backendsList: gcp.Backend[] = [];
try {
const backendsPerRegion = await gcp.listBackends(projectId, location);
backendsList.push(backendsPerRegion);
populateTable(backendsPerRegion, location, table);
backendsList.push(...backendsPerRegion.backends);
Copy link
Contributor

Choose a reason for hiding this comment

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

just ooc what do we do if the user has 100s of backends? It doesn't look like we allow them to page through the results atm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. will leave a bug for myself.

populateTable(backendsList, table);

logger.info();
logger.info(`Backends for project ${bold(projectId)}`);
logger.info();
logger.info(table.toString());

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .toString on an `any` value

Check warning on line 32 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
} catch (err: any) {

Check warning on line 33 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
throw new FirebaseError(
`Unable to list backends present for project: ${projectId}. Please check the parameters you have provided.`,
{ original: err }

Check warning on line 36 in src/commands/frameworks-backends-list.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
);
}

return backendsList;
});

function populateTable(backendsLists: gcp.ListBackendsResponse, location: string, table: any) {
for (const backend of backendsLists.backends) {
function populateTable(backends: gcp.Backend[], table: any) {
for (const backend of backends) {
const [location, , backendId] = backend.name.split("/").slice(3, 6);
const entry = [
backendId,
Expand Down
Loading