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

Svn main 001 rem #6489

Merged
merged 18 commits into from
Nov 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");

Check warning on line 7 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 7 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Require statement not part of import statement

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({

Check warning on line 24 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 24 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe construction of an any type value
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
style: { head: ["green"] },
});
table.push([

Check warning on line 28 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .push on an `any` value

Check warning on line 28 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
backend.name,
backend.codebase.repository,
backend.uri,
backend.createTime,
backend.updateTime,
]);
logger.info(table.toString());

Check warning on line 35 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

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

Check warning on line 35 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .toString on an `any` value

Check warning on line 35 in src/commands/frameworks-backends-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

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

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

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
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