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

Changed stack to backend #6488

Merged
merged 11 commits into from
Nov 1, 2023
37 changes: 23 additions & 14 deletions src/commands/frameworks-stacks-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
const Table = require("cli-table");

export const command = new Command("stacks:get")
.description("Get stack details of a Firebase project")
export const command = new Command("backends:get")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "us-central1")
.option("--s, --stackId <stackId>", "Stack Id", "")
.option("--s, --backendId <backendId>", "Backend Id", "")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const stackId = options.stackId as string;
if (!stackId) {
throw new FirebaseError("Stack id can't be empty.");
const backendId = options.backendId as string;
if (!backendId) {
throw new FirebaseError("Backend id can't be empty.");
}

let stack;
let backend;
try {
stack = await gcp.getStack(projectId, location, stackId);
/**
* TODO print this in a prettier way.
*/
logger.info(stack);
backend = await gcp.getBackend(projectId, location, backendId);
const table = new Table({
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
style: { head: ["yellow"] },
});
table.push([
backend.name,
backend.codebase.repository,
backend.uri,
backend.createTime,
backend.updateTime,
]);
logger.info(table.toString());
} catch (err: any) {
throw new FirebaseError(
`Failed to get stack: ${stackId}. Please check the parameters you have provided.`,
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
{ original: err }
);
}

return stack;
return backend;
});
32 changes: 22 additions & 10 deletions src/commands/frameworks-stacks-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,39 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
const Table = require("cli-table");

export const command = new Command("stacks:list")
.description("List stacks of a Firebase project.")
export const command = new Command("backends:list")
.description("List backends of a Firebase project.")
.option("-l, --location <location>", "App Backend location", "us-central1")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const table = new Table({
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
style: { head: ["yellow"] },
});

let stacks;
let backendsList;
try {
stacks = await gcp.listStack(projectId, location);
/**
* TODO print this in a prettier way.
*/
logger.info(stacks);
backendsList = await gcp.listBackend(projectId, location);
svnsairam marked this conversation as resolved.
Show resolved Hide resolved
for (const backend of backendsList.backends) {
const entry = [
backend.name,
backend.codebase.repository,
backend.uri,
backend.createTime,
backend.updateTime,
];
table.push(entry);
}
logger.info(table.toString());
} catch (err: any) {
throw new FirebaseError(
`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`,
`Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`,
{ original: err }
);
}

return stacks;
return backendsList;
});
18 changes: 9 additions & 9 deletions src/gcp/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export interface Operation {
// end oneof result
}

export interface ListStacksResponse {
stacks: Stack[];
export interface ListBackendsResponse {
backends: Stack[];
}

/**
Expand All @@ -104,25 +104,25 @@ export async function createStack(
}

/**
* Gets stack details.
* Gets backend details.
*/
export async function getStack(
export async function getBackend(
projectId: string,
location: string,
stackId: string
backendId: string
): Promise<Stack> {
const name = `projects/${projectId}/locations/${location}/backends/${stackId}`;
const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
const res = await client.get<Stack>(name);

return res.body;
}

/**
* List all stacks present in a project and region.
* List all backends present in a project and region.
*/
export async function listStack(projectId: string, location: string): Promise<ListStacksResponse> {
export async function listBackend(projectId: string, location: string): Promise<ListBackendsResponse> {
const name = `projects/${projectId}/locations/${location}/backends`;
const res = await client.get<ListStacksResponse>(name);
const res = await client.get<ListBackendsResponse>(name);

return res.body;
}
Expand Down
4 changes: 2 additions & 2 deletions src/init/features/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise<S
}

async function getExistingStack(projectId: string, setup: any, location: string): Promise<Stack> {
let stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
let stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
while (stack) {
setup.frameworks.serviceName = undefined;
await promptOnce(
Expand All @@ -139,7 +139,7 @@ async function getExistingStack(projectId: string, setup: any, location: string)
},
setup.frameworks
);
stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
setup.frameworks.existingStack = undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/init/frameworks/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("operationsConverter", () => {
.stub(poller, "pollOperation")
.throws("Unexpected pollOperation call");
createStackStub = sandbox.stub(gcp, "createStack").throws("Unexpected createStack call");
getStackStub = sandbox.stub(gcp, "getStack").throws("Unexpected getStack call");
getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getStack call");
linkGitHubRepositoryStub = sandbox
.stub(repo, "linkGitHubRepository")
.throws("Unexpected getStack call");
Expand Down