Skip to content

Commit

Permalink
Svn main 001 rem (#6489)
Browse files Browse the repository at this point in the history
* Change name from stack to backend

* Change name from stack to backend

* changed file names

* changed file names in experiments

* changed name

* lower case backend

* Changed stack to backend

* change stack to backend in index file

* List stacks in table

* Backends for project message

* resolve merge conflicts

* removed linter errors

* changed table head color to green

* test method stack to backend

* Changed stack to backend (#6488)

* Changed stack to backend

* change stack to backend in index file

* List stacks in table

* Backends for project message

* Changed file names

* removed linter errors

* change file names from stack to backend

* changed table head color to green

* test method stack to backend

* changed file name
  • Loading branch information
svnsairam committed Nov 2, 2023
1 parent c5c872c commit 27957b3
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 83 deletions.
44 changes: 44 additions & 0 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command } from "../command";
import { Options } from "../options";
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("backends:get")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "us-central1")
.option("--s, --backendId <backendId>", "Backend Id", "")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const backendId = options.backendId as string;
if (!backendId) {
throw new FirebaseError("Backend id can't be empty.");
}

let backend;
try {
backend = await gcp.getBackend(projectId, location, backendId);
const table = new Table({
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
style: { head: ["green"] },
});
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 backend: ${backendId}. Please check the parameters you have provided.`,
{ original: err }
);
}

return backend;
});
44 changes: 44 additions & 0 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";
const Table = require("cli-table");

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: ["green"] },
});

let backendsList;
try {
backendsList = await gcp.listBackends(projectId, location);
for (const backend of backendsList.backends) {
const entry = [
backend.name,
backend.codebase.repository,
backend.uri,
backend.createTime,
backend.updateTime,
];
table.push(entry);
}
logger.info(`Backends for project ${bold(projectId)}`);
logger.info(table.toString());
} catch (err: any) {
throw new FirebaseError(
`Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`,
{ original: err }
);
}

return backendsList;
});
35 changes: 0 additions & 35 deletions src/commands/frameworks-stacks-get.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/commands/frameworks-stacks-list.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ export function load(client: any): any {
}
if (experiments.isEnabled("internalframeworks")) {
client.frameworks = {};
client.frameworks.stacks = {};
client.frameworks.stacks.list = loadCommand("frameworks-stacks-list");
client.frameworks.stacks.create = loadCommand("frameworks-backends-create");
client.frameworks.stacks.create = loadCommand("frameworks-stacks-get");
client.frameworks.stacks.create = loadCommand("frameworks-backends-delete");
client.frameworks.backends = {};
client.frameworks.backends.list = loadCommand("frameworks-backends-list");
client.frameworks.backends.create = loadCommand("frameworks-backends-create");
client.frameworks.backends.get = loadCommand("frameworks-backends-get");
client.frameworks.backends.delete = loadCommand("frameworks-backends-delete");
}
client.login = loadCommand("login");
client.login.add = loadCommand("login-add");
Expand Down
21 changes: 12 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,28 @@ 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 listBackends(
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
4 changes: 2 additions & 2 deletions src/test/init/frameworks/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ 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 getBackend call");
linkGitHubRepositoryStub = sandbox
.stub(repo, "linkGitHubRepository")
.throws("Unexpected getStack call");
.throws("Unexpected getBackend call");
});

afterEach(() => {
Expand Down

0 comments on commit 27957b3

Please sign in to comment.