From 414711034396b1addea3f92724e49b7a777badca Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 4 Aug 2023 00:34:32 +0000 Subject: [PATCH 01/25] testing --- src/gcp/cloudbuild.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gcp/cloudbuild.ts b/src/gcp/cloudbuild.ts index 488d806ab94..d71e441b958 100644 --- a/src/gcp/cloudbuild.ts +++ b/src/gcp/cloudbuild.ts @@ -101,6 +101,7 @@ export async function getConnection( location: string, connectionId: string ): Promise { + console.log(projectId); const name = `projects/${projectId}/locations/${location}/connections/${connectionId}`; const res = await client.get(name); return res.body; From 1c025f1acd6e4771268746ff24cccf3b6a99239b Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 4 Aug 2023 00:36:15 +0000 Subject: [PATCH 02/25] testing --- src/gcp/cloudbuild.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gcp/cloudbuild.ts b/src/gcp/cloudbuild.ts index d71e441b958..488d806ab94 100644 --- a/src/gcp/cloudbuild.ts +++ b/src/gcp/cloudbuild.ts @@ -101,7 +101,6 @@ export async function getConnection( location: string, connectionId: string ): Promise { - console.log(projectId); const name = `projects/${projectId}/locations/${location}/connections/${connectionId}`; const res = await client.get(name); return res.body; From 4b3e8056870f0772a83dad601e91965b5d8c2e9b Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Thu, 3 Aug 2023 17:37:24 -0700 Subject: [PATCH 03/25] Init demo flow --- src/commands/frameworks-stacks-create.ts | 14 ++++++++++ src/commands/frameworks-stacks-delete.ts | 17 +++++++++++++ src/commands/frameworks-stacks-get.ts | 20 +++++++++++++++ src/commands/frameworks-stacks-list.ts | 17 +++++++++++++ src/commands/index.ts | 8 ++++++ src/gcp/frameworks.ts | 31 ++++++++++++++++++++++- src/init/features/frameworks/constants.ts | 5 +++- src/init/features/frameworks/index.ts | 18 +++++++------ src/init/features/frameworks/repo.ts | 15 ++++++----- src/test/init/frameworks/index.spec.ts | 4 +++ src/test/init/frameworks/repo.spec.ts | 2 +- 11 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 src/commands/frameworks-stacks-create.ts create mode 100644 src/commands/frameworks-stacks-delete.ts create mode 100644 src/commands/frameworks-stacks-get.ts create mode 100644 src/commands/frameworks-stacks-list.ts diff --git a/src/commands/frameworks-stacks-create.ts b/src/commands/frameworks-stacks-create.ts new file mode 100644 index 00000000000..7479c3ef84f --- /dev/null +++ b/src/commands/frameworks-stacks-create.ts @@ -0,0 +1,14 @@ +import { Command } from "../command"; +import { Options } from "../options"; +import { needProjectId } from "../projectUtils"; +import requireInteractive from "../requireInteractive"; +import { doSetup } from "../init/features/frameworks"; + +export const command = new Command("stacks:create") + .description("create stacks for a project") + .before(requireInteractive) + .action(async (options: Options) => { + const projectId = needProjectId(options); + await doSetup({}, projectId); + console.log(projectId); + }); diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts new file mode 100644 index 00000000000..dbbcda96b56 --- /dev/null +++ b/src/commands/frameworks-stacks-delete.ts @@ -0,0 +1,17 @@ +import { Command } from "../command"; +import { Options } from "../options"; +import { needProjectId } from "../projectUtils"; +import requireInteractive from "../requireInteractive"; +import * as gcp from "../gcp/frameworks"; + +export const command = new Command("stacks:delete") + .option("-l, --location ", "Stack backend location", "us-central1") + .option("-stack, --stackId ", "Stack backend location", "") + .description("list stacks for a project") + .before(requireInteractive) + .action(async (options: Options) => { + const projectId = needProjectId(options); + const location = options.location as string; + const stackId = options.stackId as string; + await gcp.deleteStack(projectId, location, stackId); + }); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts new file mode 100644 index 00000000000..e4be9709e4d --- /dev/null +++ b/src/commands/frameworks-stacks-get.ts @@ -0,0 +1,20 @@ +import { Command } from "../command"; +import { Options } from "../options"; +import { needProjectId } from "../projectUtils"; +import requireInteractive from "../requireInteractive"; +import * as gcp from "../gcp/frameworks"; +import { Stack } from "../gcp/frameworks"; + +export const command = new Command("stacks:get") + .option("-l, --location ", "Stack backend location", "us-central1") + .option("--stack, --stackId ", "Id for the stack", "") + .description("list stacks for a project") + .before(requireInteractive) + .action(async (options: Options) => { + const projectId = needProjectId(options); + const location = options.location as string; + const stackId = options.stackId as string; + const stack: Stack = await gcp.getStack(projectId, location, stackId); + + console.log(stack); + }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts new file mode 100644 index 00000000000..7c7cd271edc --- /dev/null +++ b/src/commands/frameworks-stacks-list.ts @@ -0,0 +1,17 @@ +import { Command } from "../command"; +import { Options } from "../options"; +import { needProjectId } from "../projectUtils"; +import requireInteractive from "../requireInteractive"; +import * as gcp from "../gcp/frameworks"; +import { ListStacksResponse } from "../gcp/frameworks"; + +export const command = new Command("stacks:list") + .option("-l, --location ", "Stack backend location", "us-central1") + .description("list stacks for a project") + .before(requireInteractive) + .action(async (options: Options) => { + const projectId = needProjectId(options); + const location = options.location as string; + const resp: ListStacksResponse = await gcp.listStack(projectId, location); + console.log(resp); + }); diff --git a/src/commands/index.ts b/src/commands/index.ts index 1b3c5d3bc30..13b5c5edd03 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -151,6 +151,14 @@ export function load(client: any): any { client.internaltesting.functions = {}; client.internaltesting.functions.discover = loadCommand("internaltesting-functions-discover"); } + if (experiments.isEnabled("frameworks")) { + client.frameworks = {}; + client.frameworks.stacks = {}; + client.frameworks.stacks.list = loadCommand("frameworks-stacks-list"); + client.frameworks.stacks.create = loadCommand("frameworks-stacks-create"); + client.frameworks.stacks.create = loadCommand("frameworks-stacks-get"); + client.frameworks.stacks.create = loadCommand("frameworks-stacks-delete"); + } client.login = loadCommand("login"); client.login.add = loadCommand("login-add"); client.login.ci = loadCommand("login-ci"); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 9cf26631805..b15d805ee26 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -27,7 +27,7 @@ export interface Stack { uri: string; } -export type StackOutputOnlyFields = "createTime" | "updateTime" | "uri" | "codebase"; +export type StackOutputOnlyFields = "createTime" | "updateTime" | "uri"; export interface Build { name: string; @@ -81,6 +81,12 @@ export interface Operation { // end oneof result } +export interface ListStacksResponse { + stacks: Stack[]; + nextPageToken: string; + unreachable: string[]; +} + /** * Creates a new Stack in a given project and location. */ @@ -113,6 +119,29 @@ export async function getStack( return res.body; } +/** + * List a all stacks present in a project and region. + */ +export async function listStack(projectId: string, location: string): Promise { + const name = `projects/${projectId}/locations/${location}/stacks/`; + const res = await client.get(name); + + return res.body; +} + +/** + * Creates a new Stack in a given project and location. + */ +export async function deleteStack( + projectId: string, + location: string, + stackId: string +): Promise { + const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`; + const res = await client.delete(name); + + return res.body; +} /** * Creates a new Build in a given project and location. */ diff --git a/src/init/features/frameworks/constants.ts b/src/init/features/frameworks/constants.ts index 90731f7858e..1fc8b11c0c9 100644 --- a/src/init/features/frameworks/constants.ts +++ b/src/init/features/frameworks/constants.ts @@ -1,4 +1,7 @@ export const DEFAULT_REGION = "us-central1"; -export const ALLOWED_REGIONS = [{ name: "us-central1 (Iowa)", value: "us-central1" }]; +export const ALLOWED_REGIONS = [ + { name: "us-central1", value: "us-central1" }, + { name: "us-west1", value: "us-west1" }, +]; export const DEFAULT_DEPLOY_METHOD = "github"; export const ALLOWED_DEPLOY_METHODS = [{ name: "Deploy using github", value: "github" }]; diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 26c0ebc160b..954943b9fac 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -27,8 +27,7 @@ const frameworksPollerOptions: Omit { - const projectId: string = setup?.rcfile?.projects?.default; +export async function doSetup(setup: any, projectId: string): Promise { setup.frameworks = {}; utils.logBullet("First we need a few details to create your service."); @@ -71,7 +70,10 @@ export async function doSetup(setup: any): Promise { setup.frameworks ); - await getOrCreateStack(projectId, setup); + const stack: Stack | undefined = await getOrCreateStack(projectId, setup); + if (stack) { + utils.logSuccess(`Successfully created a stack: ${stack.name}`); + } } function toStack( @@ -80,6 +82,10 @@ function toStack( ): Omit { return { name: stackId, + codebase: { + repository: `cloudbuild.googleapis.com/v2/${cloudBuildConnRepo.name}`, + rootDirectory: ".", + }, labels: {}, }; } @@ -96,11 +102,7 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise { - const connectionId = stackId; + const connectionId = generateConnectionId(location); await getOrCreateConnection(projectId, location, connectionId); let remoteUri = await promptRepositoryURI(projectId, location, connectionId); @@ -147,7 +150,7 @@ export async function getOrCreateRepository( connectionId: string, remoteUri: string ): Promise { - const repositoryId = generateRepositoryId(); + const repositoryId = generateRepositoryId(remoteUri); if (!repositoryId) { throw new FirebaseError(`Failed to generate repositoryId for URI "${remoteUri}".`); } diff --git a/src/test/init/frameworks/index.spec.ts b/src/test/init/frameworks/index.spec.ts index ccc7763a940..a60e6aa73a5 100644 --- a/src/test/init/frameworks/index.spec.ts +++ b/src/test/init/frameworks/index.spec.ts @@ -36,6 +36,10 @@ describe("operationsConverter", () => { const stackId = "stackId"; const stackInput = { name: stackId, + codebase: { + repository: `cloudbuild.googleapis.com/v2/projects/projectId/locations/us-central1/connections/frameworks-us-central1/repositories/repoId`, + rootDirectory: ".", + }, labels: {}, }; const op = { diff --git a/src/test/init/frameworks/repo.spec.ts b/src/test/init/frameworks/repo.spec.ts index 1c21b608b43..4425ca8d6a8 100644 --- a/src/test/init/frameworks/repo.spec.ts +++ b/src/test/init/frameworks/repo.spec.ts @@ -128,7 +128,7 @@ describe("composer", () => { getConnectionStub.resolves(pendingConn); fetchLinkableRepositoriesStub.resolves({ repositories: [] }); - await expect(repo.linkGitHubRepository(projectId, location, stackId)).to.be.rejected; + await expect(repo.linkGitHubRepository(projectId, location)).to.be.rejected; }); }); }); From 2fac7665f628e4bc288b4b0df12e36cf901e4571 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 1 Sep 2023 23:11:27 +0000 Subject: [PATCH 04/25] Create Stack request body changed --- src/init/features/frameworks/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 954943b9fac..03f03f5d06f 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -83,9 +83,10 @@ function toStack( return { name: stackId, codebase: { - repository: `cloudbuild.googleapis.com/v2/${cloudBuildConnRepo.name}`, - rootDirectory: ".", + repository: `${cloudBuildConnRepo.name}`, + rootDirectory: "src", }, + mode: "prod", labels: {}, }; } From 1609091bda925b12be8293f7f0c74d6401b97c99 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 13 Sep 2023 18:02:38 -0700 Subject: [PATCH 05/25] Updated CRUD API's for stacks --- src/commands/frameworks-stacks-create.ts | 3 +-- src/commands/frameworks-stacks-delete.ts | 2 +- src/commands/frameworks-stacks-get.ts | 4 ++-- src/commands/frameworks-stacks-list.ts | 7 ++++--- src/gcp/frameworks.ts | 11 ++++++----- src/init/features/frameworks/index.ts | 21 ++++++++++----------- src/init/features/frameworks/repo.ts | 12 ++++++++---- src/test/init/frameworks/index.spec.ts | 23 ++++++++++------------- src/test/init/frameworks/repo.spec.ts | 5 ++--- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/commands/frameworks-stacks-create.ts b/src/commands/frameworks-stacks-create.ts index 7479c3ef84f..102bc2b9c89 100644 --- a/src/commands/frameworks-stacks-create.ts +++ b/src/commands/frameworks-stacks-create.ts @@ -5,10 +5,9 @@ import requireInteractive from "../requireInteractive"; import { doSetup } from "../init/features/frameworks"; export const command = new Command("stacks:create") - .description("create stacks for a project") + .description("Create a stack in your Firebase project") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); await doSetup({}, projectId); - console.log(projectId); }); diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index dbbcda96b56..ddd66db1e6b 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -5,9 +5,9 @@ import requireInteractive from "../requireInteractive"; import * as gcp from "../gcp/frameworks"; export const command = new Command("stacks:delete") + .description("Delete a stack from your Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("-stack, --stackId ", "Stack backend location", "") - .description("list stacks for a project") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index e4be9709e4d..43ab7e44eb4 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -6,15 +6,15 @@ import * as gcp from "../gcp/frameworks"; import { Stack } from "../gcp/frameworks"; export const command = new Command("stacks:get") + .description("Get stack details of your Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("--stack, --stackId ", "Id for the stack", "") - .description("list stacks for a project") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; const stackId = options.stackId as string; const stack: Stack = await gcp.getStack(projectId, location, stackId); - console.log(stack); + return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 7c7cd271edc..d3bd1755031 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -6,12 +6,13 @@ import * as gcp from "../gcp/frameworks"; import { ListStacksResponse } from "../gcp/frameworks"; export const command = new Command("stacks:list") + .description("List stacks for you Firebase project.") .option("-l, --location ", "Stack backend location", "us-central1") - .description("list stacks for a project") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; - const resp: ListStacksResponse = await gcp.listStack(projectId, location); - console.log(resp); + const stacks: ListStacksResponse = await gcp.listStack(projectId, location); + console.log(stacks); + return stacks; }); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index b15d805ee26..186cd99f817 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -27,7 +27,7 @@ export interface Stack { uri: string; } -export type StackOutputOnlyFields = "createTime" | "updateTime" | "uri"; +export type StackOutputOnlyFields = "name" | "createTime" | "updateTime" | "uri"; export interface Build { name: string; @@ -93,12 +93,12 @@ export interface ListStacksResponse { export async function createStack( projectId: string, location: string, - stackInput: Omit + stackReqBoby: Omit, + stackId: string ): Promise { - const stackId = stackInput.name; const res = await client.post, Operation>( `projects/${projectId}/locations/${location}/stacks`, - stackInput, + stackReqBoby, { queryParams: { stackId } } ); @@ -120,7 +120,7 @@ export async function getStack( } /** - * List a all stacks present in a project and region. + * List all stacks present in a project and region. */ export async function listStack(projectId: string, location: string): Promise { const name = `projects/${projectId}/locations/${location}/stacks/`; @@ -142,6 +142,7 @@ export async function deleteStack( return res.body; } + /** * Creates a new Build in a given project and location. */ diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 03f03f5d06f..415ce526df6 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -76,15 +76,11 @@ export async function doSetup(setup: any, projectId: string): Promise { } } -function toStack( - cloudBuildConnRepo: Repository, - stackId: string -): Omit { +function toStack(cloudBuildConnRepo: Repository): Omit { return { - name: stackId, codebase: { repository: `${cloudBuildConnRepo.name}`, - rootDirectory: "src", + rootDirectory: "/", }, mode: "prod", labels: {}, @@ -104,8 +100,10 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise + stackReqBoby: Omit, + stackId: string ): Promise { - const op = await gcp.createStack(projectId, location, stackInput); + const op = await gcp.createStack(projectId, location, stackReqBoby, stackId); const stack = await poller.pollOperation({ ...frameworksPollerOptions, - pollerName: `create-${projectId}-${location}-${stackInput.name}`, + pollerName: `create-${projectId}-${location}-${stackId}`, operationResourceName: op.name, }); diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index cbe5057e87f..1ca9d16506f 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -27,15 +27,19 @@ function extractRepoSlugFromURI(remoteUri: string): string | undefined { /** * Generates a repository ID. - * N.B. The deterministic nature of the repository ID implies that each - * Cloud Build Connection will have one Cloud Build Repo child resource. - * The current implementation is subject to change in the event that - * the 1:1 Connection-to-Resource relationship no longer holds. + * The relation is 1:* between Cloud Build Connection and Github Repositories. */ function generateRepositoryId(remoteUri: string): string | undefined { return extractRepoSlugFromURI(remoteUri)?.replaceAll("/", "-"); } +/** + * The 'frameworks-' is prefixed, to seperate the Cloud Build connections created from + * AppHosting platforms with rest of manually created Cloud Build connections. + * + * The reason suffix 'location' is because of + * 1:1 relation between location and Cloud Build connection. + */ function generateConnectionId(location: string): string { return `frameworks-${location}`; } diff --git a/src/test/init/frameworks/index.spec.ts b/src/test/init/frameworks/index.spec.ts index a60e6aa73a5..63cb103b36b 100644 --- a/src/test/init/frameworks/index.spec.ts +++ b/src/test/init/frameworks/index.spec.ts @@ -34,14 +34,6 @@ describe("operationsConverter", () => { const projectId = "projectId"; const location = "us-central1"; const stackId = "stackId"; - const stackInput = { - name: stackId, - codebase: { - repository: `cloudbuild.googleapis.com/v2/projects/projectId/locations/us-central1/connections/frameworks-us-central1/repositories/repoId`, - rootDirectory: ".", - }, - labels: {}, - }; const op = { name: `projects/${projectId}/locations/${location}/stacks/${stackId}`, done: true, @@ -62,17 +54,24 @@ describe("operationsConverter", () => { }, }; const cloudBuildConnRepo = { - name: `projects/${projectId}/locations/${location}/stacks/${stackId}`, + name: `projects/${projectId}/locations/${location}/connections/framework-${location}/repositories/repoId`, remoteUri: "remoteUri", createTime: "0", updateTime: "1", }; - + const stackInput = { + codebase: { + repository: cloudBuildConnRepo.name, + rootDirectory: "/", + }, + mode: "prod", + labels: {}, + }; it("should createStack", async () => { createStackStub.resolves(op); pollOperationStub.resolves(completeStack); - await createStack(projectId, location, stackInput); + await createStack(projectId, location, stackInput, stackId); expect(createStackStub).to.be.calledWith(projectId, location, stackInput); }); @@ -90,10 +89,8 @@ describe("operationsConverter", () => { const newStackId = "newStackId"; const newPath = `projects/${projectId}/locations/${location}/stacks/${newStackId}`; setup.frameworks.serviceName = newStackId; - stackInput.name = newStackId; op.name = newPath; completeStack.name = newPath; - cloudBuildConnRepo.name = newPath; getStackStub.throws(new FirebaseError("error", { status: 404 })); linkGitHubRepositoryStub.resolves(cloudBuildConnRepo); createStackStub.resolves(op); diff --git a/src/test/init/frameworks/repo.spec.ts b/src/test/init/frameworks/repo.spec.ts index 4425ca8d6a8..9b80636762f 100644 --- a/src/test/init/frameworks/repo.spec.ts +++ b/src/test/init/frameworks/repo.spec.ts @@ -46,8 +46,7 @@ describe("composer", () => { describe("connect GitHub repo", () => { const projectId = "projectId"; const location = "us-central1"; - const stackId = "stack0"; - const connectionId = `composer-${stackId}-conn`; + const connectionId = `frameworks-${location}`; const op = { name: `projects/${projectId}/locations/${location}/connections/${connectionId}`, @@ -119,7 +118,7 @@ describe("composer", () => { projectId, location, connectionId, - "composer-repo", + "test-repo0", repos.repositories[0].remoteUri ); }); From 7c8b3e330cf06f2c7e4ff14ddf4c8ad8b2f90735 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Thu, 14 Sep 2023 07:45:12 -0700 Subject: [PATCH 06/25] Updated changes --- src/commands/frameworks-stacks-create.ts | 2 +- src/commands/frameworks-stacks-delete.ts | 2 +- src/commands/frameworks-stacks-get.ts | 4 ++-- src/commands/frameworks-stacks-list.ts | 4 ++-- src/gcp/frameworks.ts | 2 -- src/init/features/frameworks/index.ts | 3 --- src/test/init/frameworks/index.spec.ts | 1 - 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/commands/frameworks-stacks-create.ts b/src/commands/frameworks-stacks-create.ts index 102bc2b9c89..91317bf8c2a 100644 --- a/src/commands/frameworks-stacks-create.ts +++ b/src/commands/frameworks-stacks-create.ts @@ -5,7 +5,7 @@ import requireInteractive from "../requireInteractive"; import { doSetup } from "../init/features/frameworks"; export const command = new Command("stacks:create") - .description("Create a stack in your Firebase project") + .description("Create a stack in a Firebase project") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index ddd66db1e6b..db5fe29c74b 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -5,7 +5,7 @@ import requireInteractive from "../requireInteractive"; import * as gcp from "../gcp/frameworks"; export const command = new Command("stacks:delete") - .description("Delete a stack from your Firebase project") + .description("Delete a stack from a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("-stack, --stackId ", "Stack backend location", "") .before(requireInteractive) diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 43ab7e44eb4..40096e79274 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -6,7 +6,7 @@ import * as gcp from "../gcp/frameworks"; import { Stack } from "../gcp/frameworks"; export const command = new Command("stacks:get") - .description("Get stack details of your Firebase project") + .description("Get stack details of a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("--stack, --stackId ", "Id for the stack", "") .before(requireInteractive) @@ -15,6 +15,6 @@ export const command = new Command("stacks:get") const location = options.location as string; const stackId = options.stackId as string; const stack: Stack = await gcp.getStack(projectId, location, stackId); - console.log(stack); + return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index d3bd1755031..abdca12d8a0 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -6,13 +6,13 @@ import * as gcp from "../gcp/frameworks"; import { ListStacksResponse } from "../gcp/frameworks"; export const command = new Command("stacks:list") - .description("List stacks for you Firebase project.") + .description("List stacks of a Firebase project.") .option("-l, --location ", "Stack backend location", "us-central1") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; const stacks: ListStacksResponse = await gcp.listStack(projectId, location); - console.log(stacks); + return stacks; }); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 186cd99f817..8ae5c3b03df 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -83,8 +83,6 @@ export interface Operation { export interface ListStacksResponse { stacks: Stack[]; - nextPageToken: string; - unreachable: string[]; } /** diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 415ce526df6..52be59193d6 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -82,7 +82,6 @@ function toStack(cloudBuildConnRepo: Repository): Omit { repository: cloudBuildConnRepo.name, rootDirectory: "/", }, - mode: "prod", labels: {}, }; it("should createStack", async () => { From 64337b1f54c5973e0c88ad28f21f55ae18d9192a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 15 Sep 2023 15:17:34 -0700 Subject: [PATCH 07/25] updated comments --- src/init/features/frameworks/repo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init/features/frameworks/repo.ts b/src/init/features/frameworks/repo.ts index 1ca9d16506f..1cbe8169f7a 100644 --- a/src/init/features/frameworks/repo.ts +++ b/src/init/features/frameworks/repo.ts @@ -35,7 +35,7 @@ function generateRepositoryId(remoteUri: string): string | undefined { /** * The 'frameworks-' is prefixed, to seperate the Cloud Build connections created from - * AppHosting platforms with rest of manually created Cloud Build connections. + * Frameworks platforms with rest of manually created Cloud Build connections. * * The reason suffix 'location' is because of * 1:1 relation between location and Cloud Build connection. From a73bfd639ed2973036046683c5c2011a2111223c Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 19 Sep 2023 10:32:11 -0700 Subject: [PATCH 08/25] Update CRUD options --- src/commands/frameworks-stacks-create.ts | 2 +- src/commands/frameworks-stacks-delete.ts | 11 +++++++++-- src/commands/frameworks-stacks-get.ts | 11 +++++++++-- src/commands/frameworks-stacks-list.ts | 7 +++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/commands/frameworks-stacks-create.ts b/src/commands/frameworks-stacks-create.ts index 91317bf8c2a..5ffe85a9c12 100644 --- a/src/commands/frameworks-stacks-create.ts +++ b/src/commands/frameworks-stacks-create.ts @@ -9,5 +9,5 @@ export const command = new Command("stacks:create") .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); - await doSetup({}, projectId); + await doSetup(options, projectId); }); diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index db5fe29c74b..2133461ebb4 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -1,17 +1,24 @@ import { Command } from "../command"; import { Options } from "../options"; import { needProjectId } from "../projectUtils"; -import requireInteractive from "../requireInteractive"; +import { FirebaseError } from "../error"; import * as gcp from "../gcp/frameworks"; +import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("-stack, --stackId ", "Stack backend location", "") - .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; const stackId = options.stackId as string; + if (isEmpty(stackId)) { + throw new FirebaseError("StackId can't be empty."); + } + if (isEmpty(location)) { + throw new FirebaseError("Location can't be empty."); + } + await gcp.deleteStack(projectId, location, stackId); }); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 40096e79274..74fcaee986e 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -1,20 +1,27 @@ import { Command } from "../command"; import { Options } from "../options"; import { needProjectId } from "../projectUtils"; -import requireInteractive from "../requireInteractive"; import * as gcp from "../gcp/frameworks"; import { Stack } from "../gcp/frameworks"; +import { FirebaseError } from "../error"; +import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:get") .description("Get stack details of a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") .option("--stack, --stackId ", "Id for the stack", "") - .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; const stackId = options.stackId as string; + if (isEmpty(stackId)) { + throw new FirebaseError("StackId can't be empty."); + } + if (isEmpty(location)) { + throw new FirebaseError("Location can't be empty."); + } const stack: Stack = await gcp.getStack(projectId, location, stackId); + console.log(stack); return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index abdca12d8a0..bde822ee068 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -1,17 +1,20 @@ import { Command } from "../command"; import { Options } from "../options"; import { needProjectId } from "../projectUtils"; -import requireInteractive from "../requireInteractive"; import * as gcp from "../gcp/frameworks"; import { ListStacksResponse } from "../gcp/frameworks"; +import { FirebaseError } from "../error"; +import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:list") .description("List stacks of a Firebase project.") .option("-l, --location ", "Stack backend location", "us-central1") - .before(requireInteractive) .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; + if (isEmpty(location)) { + throw new FirebaseError("Location can't be empty."); + } const stacks: ListStacksResponse = await gcp.listStack(projectId, location); return stacks; From 9e58710835f627e9ae857bbea9f41b136dba7b1b Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 12:50:59 -0700 Subject: [PATCH 09/25] resolved comments --- src/commands/frameworks-stacks-delete.ts | 7 +++---- src/commands/frameworks-stacks-get.ts | 10 ++++------ src/commands/frameworks-stacks-list.ts | 7 +++---- src/commands/index.ts | 2 +- src/gcp/frameworks.ts | 4 +++- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 2133461ebb4..d9a10ed9634 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -3,7 +3,6 @@ import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import { FirebaseError } from "../error"; import * as gcp from "../gcp/frameworks"; -import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") @@ -13,10 +12,10 @@ export const command = new Command("stacks:delete") const projectId = needProjectId(options); const location = options.location as string; const stackId = options.stackId as string; - if (isEmpty(stackId)) { - throw new FirebaseError("StackId can't be empty."); + if (!stackId) { + throw new FirebaseError("Stack id can't be empty."); } - if (isEmpty(location)) { + if (!location) { throw new FirebaseError("Location can't be empty."); } diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 74fcaee986e..8f77ec2748f 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -2,9 +2,7 @@ import { Command } from "../command"; import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; -import { Stack } from "../gcp/frameworks"; import { FirebaseError } from "../error"; -import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:get") .description("Get stack details of a Firebase project") @@ -14,13 +12,13 @@ export const command = new Command("stacks:get") const projectId = needProjectId(options); const location = options.location as string; const stackId = options.stackId as string; - if (isEmpty(stackId)) { - throw new FirebaseError("StackId can't be empty."); + if (!stackId) { + throw new FirebaseError("Stack id can't be empty."); } - if (isEmpty(location)) { + if (!location) { throw new FirebaseError("Location can't be empty."); } - const stack: Stack = await gcp.getStack(projectId, location, stackId); + const stack = await gcp.getStack(projectId, location, stackId); console.log(stack); return stack; diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index bde822ee068..7427f3684db 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -2,9 +2,7 @@ import { Command } from "../command"; import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; -import { ListStacksResponse } from "../gcp/frameworks"; import { FirebaseError } from "../error"; -import isEmpty from "lodash/isEmpty"; export const command = new Command("stacks:list") .description("List stacks of a Firebase project.") @@ -12,10 +10,11 @@ export const command = new Command("stacks:list") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; - if (isEmpty(location)) { + if (!location) { throw new FirebaseError("Location can't be empty."); } - const stacks: ListStacksResponse = await gcp.listStack(projectId, location); + const stacks = await gcp.listStack(projectId, location); + console.log(stacks); return stacks; }); diff --git a/src/commands/index.ts b/src/commands/index.ts index 13b5c5edd03..4814d4f66fe 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -151,7 +151,7 @@ export function load(client: any): any { client.internaltesting.functions = {}; client.internaltesting.functions.discover = loadCommand("internaltesting-functions-discover"); } - if (experiments.isEnabled("frameworks")) { + if (experiments.isEnabled("internalframeworks")) { client.frameworks = {}; client.frameworks.stacks = {}; client.frameworks.stacks.list = loadCommand("frameworks-stacks-list"); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 8ae5c3b03df..fcc80fc56eb 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -128,15 +128,17 @@ export async function listStack(projectId: string, location: string): Promise
  • { + console.log("HI i am in list"); const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`; const res = await client.delete(name); + console.log(res); return res.body; } From 4e43d6878faee7381be93921021f1b149d578d9a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 12:51:14 -0700 Subject: [PATCH 10/25] resolved comments --- src/commands/frameworks-stacks-delete.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index d9a10ed9634..23a4c873f6b 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -3,6 +3,7 @@ import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import { FirebaseError } from "../error"; import * as gcp from "../gcp/frameworks"; +import { promptOnce } from "../prompt"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") @@ -18,6 +19,18 @@ export const command = new Command("stacks:delete") if (!location) { throw new FirebaseError("Location can't be empty."); } + const confirmDeletion = await promptOnce( + { + type: "confirm", + name: "force", + default: false, + message: "You are about to delete the Stack with id:\n" + stackId + "\n Are you sure?", + }, + options + ); + if (!confirmDeletion) { + throw new FirebaseError("Command aborted."); + } await gcp.deleteStack(projectId, location, stackId); }); From 285d148570abb5296b37ab890b176b0dc53bea29 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 12:53:04 -0700 Subject: [PATCH 11/25] resolved comments --- src/gcp/frameworks.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index fcc80fc56eb..6697b98fd3e 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -135,10 +135,8 @@ export async function deleteStack( location: string, stackId: string ): Promise { - console.log("HI i am in list"); const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`; const res = await client.delete(name); - console.log(res); return res.body; } From af5db625c3f58c92215b2c959cad0ea3937070c5 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 14:15:07 -0700 Subject: [PATCH 12/25] Changing stack to backend in APIs --- src/gcp/frameworks.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 6697b98fd3e..2554b0de281 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -92,12 +92,12 @@ export async function createStack( projectId: string, location: string, stackReqBoby: Omit, - stackId: string + backendId: string ): Promise { const res = await client.post, Operation>( - `projects/${projectId}/locations/${location}/stacks`, + `projects/${projectId}/locations/${location}/backends`, stackReqBoby, - { queryParams: { stackId } } + { queryParams: { backendId } } ); return res.body; @@ -111,7 +111,7 @@ export async function getStack( location: string, stackId: string ): Promise { - const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`; + const name = `projects/${projectId}/locations/${location}/backends/${stackId}`; const res = await client.get(name); return res.body; @@ -121,7 +121,7 @@ export async function getStack( * List all stacks present in a project and region. */ export async function listStack(projectId: string, location: string): Promise { - const name = `projects/${projectId}/locations/${location}/stacks/`; + const name = `projects/${projectId}/locations/${location}/backends/`; const res = await client.get(name); return res.body; @@ -135,7 +135,7 @@ export async function deleteStack( location: string, stackId: string ): Promise { - const name = `projects/${projectId}/locations/${location}/stacks/${stackId}`; + const name = `projects/${projectId}/locations/${location}/backends/${stackId}`; const res = await client.delete(name); return res.body; @@ -152,7 +152,7 @@ export async function createBuild( ): Promise { const buildId = buildInput.name; const res = await client.post, Operation>( - `projects/${projectId}/locations/${location}/stacks/${stackId}/builds`, + `projects/${projectId}/locations/${location}/backends/${stackId}/builds`, buildInput, { queryParams: { buildId } } ); From f3bdc35a0c8aba0f7964eb69b367f5d1debf322f Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 14:43:48 -0700 Subject: [PATCH 13/25] Added changes to modify api --- src/commands/frameworks-stacks-delete.ts | 8 +++++--- src/commands/frameworks-stacks-get.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 23a4c873f6b..f89c8b9bfdd 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -8,7 +8,8 @@ import { promptOnce } from "../prompt"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") - .option("-stack, --stackId ", "Stack backend location", "") + .option("-s, --stackId ", "Stack backend location", "") + .withForce() .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; @@ -19,17 +20,18 @@ export const command = new Command("stacks:delete") if (!location) { throw new FirebaseError("Location can't be empty."); } + console.log(options); const confirmDeletion = await promptOnce( { type: "confirm", name: "force", default: false, - message: "You are about to delete the Stack with id:\n" + stackId + "\n Are you sure?", + message: "You are about to delete the Stack with id: " + stackId + "\n Are you sure?", }, options ); if (!confirmDeletion) { - throw new FirebaseError("Command aborted."); + throw new FirebaseError("Deletion aborted."); } await gcp.deleteStack(projectId, location, stackId); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 8f77ec2748f..c4f250ea3c3 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -7,7 +7,7 @@ import { FirebaseError } from "../error"; export const command = new Command("stacks:get") .description("Get stack details of a Firebase project") .option("-l, --location ", "Stack backend location", "us-central1") - .option("--stack, --stackId ", "Id for the stack", "") + .option("--s, --stackId ", "Id for the stack", "") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; From c8c3ce9ea3c222b48b406bbc8d273a57ccb127f0 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 15:07:50 -0700 Subject: [PATCH 14/25] minor change to region --- src/init/features/frameworks/constants.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/init/features/frameworks/constants.ts b/src/init/features/frameworks/constants.ts index 1fc8b11c0c9..cf0279f091b 100644 --- a/src/init/features/frameworks/constants.ts +++ b/src/init/features/frameworks/constants.ts @@ -1,7 +1,4 @@ export const DEFAULT_REGION = "us-central1"; -export const ALLOWED_REGIONS = [ - { name: "us-central1", value: "us-central1" }, - { name: "us-west1", value: "us-west1" }, -]; +export const ALLOWED_REGIONS = [{ name: "us-central1", value: "us-central1" }]; export const DEFAULT_DEPLOY_METHOD = "github"; export const ALLOWED_DEPLOY_METHODS = [{ name: "Deploy using github", value: "github" }]; From 97815272fc70124bfa64bb9a3e9de769de8161fe Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 10 Oct 2023 15:38:31 -0700 Subject: [PATCH 15/25] Added error messages --- src/commands/frameworks-stacks-delete.ts | 11 +++++++++-- src/commands/frameworks-stacks-get.ts | 11 ++++++++--- src/commands/frameworks-stacks-list.ts | 11 ++++++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index f89c8b9bfdd..340b24c3dee 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -4,6 +4,7 @@ import { needProjectId } from "../projectUtils"; import { FirebaseError } from "../error"; import * as gcp from "../gcp/frameworks"; import { promptOnce } from "../prompt"; +import * as utils from "../utils"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") @@ -20,7 +21,6 @@ export const command = new Command("stacks:delete") if (!location) { throw new FirebaseError("Location can't be empty."); } - console.log(options); const confirmDeletion = await promptOnce( { type: "confirm", @@ -34,5 +34,12 @@ export const command = new Command("stacks:delete") throw new FirebaseError("Deletion aborted."); } - await gcp.deleteStack(projectId, location, stackId); + try { + await gcp.deleteStack(projectId, location, stackId); + utils.logSuccess(`Successfully deleted the stack: ${stackId}`); + } catch (err: any) { + throw new FirebaseError( + `Failed to delete stack: ${stackId}. Please check the parameters you have provided.` + ); + } }); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index c4f250ea3c3..f77dbd43c12 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -18,8 +18,13 @@ export const command = new Command("stacks:get") if (!location) { throw new FirebaseError("Location can't be empty."); } - const stack = await gcp.getStack(projectId, location, stackId); - console.log(stack); - return stack; + try { + const stack = await gcp.getStack(projectId, location, stackId); + console.log(stack); + } catch (err: any) { + throw new FirebaseError( + `Failed to get stack: ${stackId}. Please check the parameters you have provided.` + ); + } }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 7427f3684db..c574d768398 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -13,8 +13,13 @@ export const command = new Command("stacks:list") if (!location) { throw new FirebaseError("Location can't be empty."); } - const stacks = await gcp.listStack(projectId, location); - console.log(stacks); - return stacks; + try { + const stacks = await gcp.listStack(projectId, location); + console.log(stacks); + } catch (err: any) { + throw new FirebaseError( + `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.` + ); + } }); From d44fb6d3b790b6452325478ecb95ee2738f27615 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Thu, 12 Oct 2023 14:34:37 -0700 Subject: [PATCH 16/25] catch block added --- src/commands/frameworks-stacks-delete.ts | 3 --- src/commands/frameworks-stacks-get.ts | 6 ++---- src/commands/frameworks-stacks-list.ts | 6 ++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 340b24c3dee..5e576de7499 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -18,9 +18,6 @@ export const command = new Command("stacks:delete") if (!stackId) { throw new FirebaseError("Stack id can't be empty."); } - if (!location) { - throw new FirebaseError("Location can't be empty."); - } const confirmDeletion = await promptOnce( { type: "confirm", diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index f77dbd43c12..0cf947cc574 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -3,6 +3,7 @@ import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; +import { logger } from "../logger"; export const command = new Command("stacks:get") .description("Get stack details of a Firebase project") @@ -15,13 +16,10 @@ export const command = new Command("stacks:get") if (!stackId) { throw new FirebaseError("Stack id can't be empty."); } - if (!location) { - throw new FirebaseError("Location can't be empty."); - } try { const stack = await gcp.getStack(projectId, location, stackId); - console.log(stack); + logger.info(stack); } catch (err: any) { throw new FirebaseError( `Failed to get stack: ${stackId}. Please check the parameters you have provided.` diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index c574d768398..093c7fc3478 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -3,6 +3,7 @@ import { Options } from "../options"; import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; +import { logger } from "../logger"; export const command = new Command("stacks:list") .description("List stacks of a Firebase project.") @@ -10,13 +11,10 @@ export const command = new Command("stacks:list") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; - if (!location) { - throw new FirebaseError("Location can't be empty."); - } try { const stacks = await gcp.listStack(projectId, location); - console.log(stacks); + logger.info(stacks); } catch (err: any) { throw new FirebaseError( `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.` From b30ee48ea8cf1c2b4433e0aceff12b8726bd5e1a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Mon, 16 Oct 2023 13:18:54 -0700 Subject: [PATCH 17/25] Added few changes --- src/commands/frameworks-stacks-delete.ts | 2 +- src/commands/frameworks-stacks-get.ts | 2 +- src/commands/frameworks-stacks-list.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 5e576de7499..98504aca3bb 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -34,7 +34,7 @@ export const command = new Command("stacks:delete") try { await gcp.deleteStack(projectId, location, stackId); utils.logSuccess(`Successfully deleted the stack: ${stackId}`); - } catch (err: any) { + } catch (err) { throw new FirebaseError( `Failed to delete stack: ${stackId}. Please check the parameters you have provided.` ); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 0cf947cc574..bb7ebcb2f7d 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -20,7 +20,7 @@ export const command = new Command("stacks:get") try { const stack = await gcp.getStack(projectId, location, stackId); logger.info(stack); - } catch (err: any) { + } catch (err) { throw new FirebaseError( `Failed to get stack: ${stackId}. Please check the parameters you have provided.` ); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 093c7fc3478..4ff3ed98eea 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -15,7 +15,7 @@ export const command = new Command("stacks:list") try { const stacks = await gcp.listStack(projectId, location); logger.info(stacks); - } catch (err: any) { + } catch (err) { throw new FirebaseError( `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.` ); From 7b80e73c040338397553d8f753b2dea41367ca9e Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 25 Oct 2023 16:36:00 +0000 Subject: [PATCH 18/25] Returned stack --- src/commands/frameworks-stacks-delete.ts | 5 +++-- src/commands/frameworks-stacks-get.ts | 12 +++++++----- src/commands/frameworks-stacks-list.ts | 11 +++++++---- src/gcp/frameworks.ts | 2 +- src/init/features/frameworks/index.ts | 3 +++ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 98504aca3bb..ab4f1cce336 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -34,9 +34,10 @@ export const command = new Command("stacks:delete") try { await gcp.deleteStack(projectId, location, stackId); utils.logSuccess(`Successfully deleted the stack: ${stackId}`); - } catch (err) { + } catch (err: any) { throw new FirebaseError( - `Failed to delete stack: ${stackId}. Please check the parameters you have provided.` + `Failed to delete stack: ${stackId}. Please check the parameters you have provided.`, + {original: err} ); } }); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index bb7ebcb2f7d..d57007adfdc 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -17,12 +17,14 @@ export const command = new Command("stacks:get") throw new FirebaseError("Stack id can't be empty."); } + let stack; try { - const stack = await gcp.getStack(projectId, location, stackId); + stack = await gcp.getStack(projectId, location, stackId); logger.info(stack); - } catch (err) { - throw new FirebaseError( - `Failed to get stack: ${stackId}. Please check the parameters you have provided.` - ); + } catch (err: any) { + throw new FirebaseError(`Failed to get stack: ${stackId}. Please check the parameters you have provided.`, + { original: err }); } + + return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 4ff3ed98eea..73b6386dd35 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -12,12 +12,15 @@ export const command = new Command("stacks:list") const projectId = needProjectId(options); const location = options.location as string; + let stacks; try { - const stacks = await gcp.listStack(projectId, location); + stacks = await gcp.listStack(projectId, location); logger.info(stacks); - } catch (err) { - throw new FirebaseError( - `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.` + } catch (err: any) { + throw new FirebaseError(`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, + { original: err } ); } + + return stacks; }); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 2554b0de281..cc7f3a5f4d2 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -121,7 +121,7 @@ export async function getStack( * List all stacks present in a project and region. */ export async function listStack(projectId: string, location: string): Promise { - const name = `projects/${projectId}/locations/${location}/backends/`; + const name = `projects/${projectId}/locations/${location}/backends`; const res = await client.get(name); return res.body; diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 52be59193d6..930420c9c6b 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -97,9 +97,12 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise Date: Wed, 25 Oct 2023 16:56:25 +0000 Subject: [PATCH 19/25] Return stack --- src/commands/frameworks-stacks-get.ts | 9 +++++---- src/commands/frameworks-stacks-list.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index d57007adfdc..f216b2fb6ea 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -17,14 +17,15 @@ export const command = new Command("stacks:get") throw new FirebaseError("Stack id can't be empty."); } - let stack; try { - stack = await gcp.getStack(projectId, location, stackId); + const stack = await gcp.getStack(projectId, location, stackId); + /** + * TODO print this in a prettier way. + */ logger.info(stack); + return stack; } catch (err: any) { throw new FirebaseError(`Failed to get stack: ${stackId}. Please check the parameters you have provided.`, { original: err }); } - - return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 73b6386dd35..b101bde7484 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -12,15 +12,16 @@ export const command = new Command("stacks:list") const projectId = needProjectId(options); const location = options.location as string; - let stacks; try { - stacks = await gcp.listStack(projectId, location); + const stacks = await gcp.listStack(projectId, location); + /** + * TODO print this in a prettier way. + */ logger.info(stacks); + return stacks } catch (err: any) { throw new FirebaseError(`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, { original: err } ); } - - return stacks; }); From d9921884e06ee301ab823dc1783cdb30a485e924 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 25 Oct 2023 17:07:08 +0000 Subject: [PATCH 20/25] Added return statements --- src/commands/frameworks-stacks-get.ts | 6 ++++-- src/commands/frameworks-stacks-list.ts | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index f216b2fb6ea..51de117987d 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -17,15 +17,17 @@ export const command = new Command("stacks:get") throw new FirebaseError("Stack id can't be empty."); } + let stack; try { - const stack = await gcp.getStack(projectId, location, stackId); + stack = await gcp.getStack(projectId, location, stackId); /** * TODO print this in a prettier way. */ logger.info(stack); - return stack; } catch (err: any) { throw new FirebaseError(`Failed to get stack: ${stackId}. Please check the parameters you have provided.`, { original: err }); } + + return stack; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index b101bde7484..c9fa37951e0 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -12,16 +12,18 @@ export const command = new Command("stacks:list") const projectId = needProjectId(options); const location = options.location as string; + let stacks; try { - const stacks = await gcp.listStack(projectId, location); - /** - * TODO print this in a prettier way. - */ - logger.info(stacks); - return stacks + stacks = await gcp.listStack(projectId, location); + /** + * TODO print this in a prettier way. + */ + logger.info(stacks); } catch (err: any) { throw new FirebaseError(`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, { original: err } ); } + + return stacks; }); From 8f942aa55d73160cd267612e0f01a4c130d13d43 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 25 Oct 2023 22:41:45 +0000 Subject: [PATCH 21/25] Removed comments --- src/init/features/frameworks/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 930420c9c6b..52be59193d6 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -97,12 +97,9 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise Date: Wed, 25 Oct 2023 22:49:16 +0000 Subject: [PATCH 22/25] changed comments --- src/commands/frameworks-stacks-delete.ts | 4 ++-- src/commands/frameworks-stacks-get.ts | 4 ++-- src/commands/frameworks-stacks-list.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index ab4f1cce336..61fb11e70f4 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -8,8 +8,8 @@ import * as utils from "../utils"; export const command = new Command("stacks:delete") .description("Delete a stack from a Firebase project") - .option("-l, --location ", "Stack backend location", "us-central1") - .option("-s, --stackId ", "Stack backend location", "") + .option("-l, --location ", "App Backend location", "us-central1") + .option("-s, --stackId ", "Stack Id", "") .withForce() .action(async (options: Options) => { const projectId = needProjectId(options); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 51de117987d..6f0d3431dee 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -7,8 +7,8 @@ import { logger } from "../logger"; export const command = new Command("stacks:get") .description("Get stack details of a Firebase project") - .option("-l, --location ", "Stack backend location", "us-central1") - .option("--s, --stackId ", "Id for the stack", "") + .option("-l, --location ", "App Backend location", "us-central1") + .option("--s, --stackId ", "Stack Id", "") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index c9fa37951e0..08fd1d351fe 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -7,7 +7,7 @@ import { logger } from "../logger"; export const command = new Command("stacks:list") .description("List stacks of a Firebase project.") - .option("-l, --location ", "Stack backend location", "us-central1") + .option("-l, --location ", "App Backend location", "us-central1") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; From fdeda7ca9d3e19b4ea1dd5935644685052dd6111 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 27 Oct 2023 17:20:00 +0000 Subject: [PATCH 23/25] Added minor change --- src/init/features/frameworks/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init/features/frameworks/constants.ts b/src/init/features/frameworks/constants.ts index cf0279f091b..90731f7858e 100644 --- a/src/init/features/frameworks/constants.ts +++ b/src/init/features/frameworks/constants.ts @@ -1,4 +1,4 @@ export const DEFAULT_REGION = "us-central1"; -export const ALLOWED_REGIONS = [{ name: "us-central1", value: "us-central1" }]; +export const ALLOWED_REGIONS = [{ name: "us-central1 (Iowa)", value: "us-central1" }]; export const DEFAULT_DEPLOY_METHOD = "github"; export const ALLOWED_DEPLOY_METHODS = [{ name: "Deploy using github", value: "github" }]; From 71d534c7fd73cf33208f21adc131c597c0d9a6d9 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 27 Oct 2023 20:08:36 +0000 Subject: [PATCH 24/25] Format code --- src/commands/frameworks-stacks-delete.ts | 2 +- src/commands/frameworks-stacks-get.ts | 6 ++++-- src/commands/frameworks-stacks-list.ts | 13 +++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/commands/frameworks-stacks-delete.ts b/src/commands/frameworks-stacks-delete.ts index 61fb11e70f4..8916e856b10 100644 --- a/src/commands/frameworks-stacks-delete.ts +++ b/src/commands/frameworks-stacks-delete.ts @@ -37,7 +37,7 @@ export const command = new Command("stacks:delete") } catch (err: any) { throw new FirebaseError( `Failed to delete stack: ${stackId}. Please check the parameters you have provided.`, - {original: err} + { original: err } ); } }); diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 6f0d3431dee..91059921654 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -25,8 +25,10 @@ export const command = new Command("stacks:get") */ logger.info(stack); } catch (err: any) { - throw new FirebaseError(`Failed to get stack: ${stackId}. Please check the parameters you have provided.`, - { original: err }); + throw new FirebaseError( + `Failed to get stack: ${stackId}. Please check the parameters you have provided.`, + { original: err } + ); } return stack; diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 08fd1d351fe..b86e65b9034 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -15,13 +15,14 @@ export const command = new Command("stacks:list") let stacks; try { stacks = await gcp.listStack(projectId, location); - /** - * TODO print this in a prettier way. - */ - logger.info(stacks); + /** + * TODO print this in a prettier way. + */ //fasdfas// + logger.info(stacks); } catch (err: any) { - throw new FirebaseError(`Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, - { original: err } + throw new FirebaseError( + `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, + { original: err } ); } From 681a695d7a32f59af40ee805b2e5865e00c6472a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Fri, 27 Oct 2023 20:16:37 +0000 Subject: [PATCH 25/25] Format code --- src/commands/frameworks-stacks-list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index b86e65b9034..61ccd6bbb16 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -17,7 +17,7 @@ export const command = new Command("stacks:list") stacks = await gcp.listStack(projectId, location); /** * TODO print this in a prettier way. - */ //fasdfas// + */ logger.info(stacks); } catch (err: any) { throw new FirebaseError(