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

Remove --location from apphosting:backends:get and return the first backend if multiple are found. #8260

Merged
merged 1 commit into from
Mar 3, 2025
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
25 changes: 11 additions & 14 deletions src/commands/apphosting-backends-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,15 @@ import { printBackendsTable } from "./apphosting-backends-list";

export const command = new Command("apphosting:backends:get <backend>")
.description("print info about a Firebase App Hosting backend")
.option("-l, --location <location>", "backend location")
.before(apphosting.ensureApiEnabled)
.action(async (backend: string, options: Options) => {
const projectId = needProjectId(options);
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const location = (options.location as string) ?? "-";

let backendsList: apphosting.Backend[] = [];
try {
if (location !== "-") {
const backendInRegion = await apphosting.getBackend(projectId, location, backend);
backendsList.push(backendInRegion);
} else {
const resp = await apphosting.listBackends(projectId, "-");
const allBackends = resp.backends || [];
backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backend);
}
const resp = await apphosting.listBackends(projectId, "-");
const allBackends = resp.backends || [];
backendsList = allBackends.filter((bkd) => bkd.name.split("/").pop() === backend);
} catch (err: unknown) {
throw new FirebaseError(
`Failed to get backend: ${backend}. Please check the parameters you have provided.`,
Expand All @@ -37,6 +27,13 @@ export const command = new Command("apphosting:backends:get <backend>")
logWarning(`Backend "${backend}" not found`);
return;
}
printBackendsTable(backendsList);
if (backendsList.length > 1) {
logWarning(
`Detected multiple backends with the same ${backend} ID. This is not allowed until we can support more locations.\n` +
`Please delete and recreate any backends that share an ID with another backend. ` +
`Use apphosting:backends:list to see all backends.\n Returning the following backend:`,
);
}
printBackendsTable(backendsList.slice(0, 1));
return backendsList[0];
});
Loading