From 14342b253f0cd37ce1f1d1a702cb66706fa52ccb Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Sun, 18 Jun 2023 19:15:14 -0700 Subject: [PATCH 1/8] Initial commit to stacks api --- src/api.ts | 4 ++ .../compose/discover/firestackApi.ts | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/frameworks/compose/discover/firestackApi.ts diff --git a/src/api.ts b/src/api.ts index c20ead3091b..00726f31760 100644 --- a/src/api.ts +++ b/src/api.ts @@ -173,6 +173,10 @@ export const serviceUsageOrigin = utils.envOverride( "FIREBASE_SERVICE_USAGE_URL", "https://serviceusage.googleapis.com" ); +export const firestackApiOrigin = utils.envOverride( + "FIRESTACK_API_URL", + "https://firestack.googleapis.com" +); export const githubOrigin = utils.envOverride("GITHUB_URL", "https://github.com"); export const githubApiOrigin = utils.envOverride("GITHUB_API_URL", "https://api.github.com"); export const secretManagerOrigin = utils.envOverride( diff --git a/src/frameworks/compose/discover/firestackApi.ts b/src/frameworks/compose/discover/firestackApi.ts new file mode 100644 index 00000000000..7c4cdfeffa4 --- /dev/null +++ b/src/frameworks/compose/discover/firestackApi.ts @@ -0,0 +1,70 @@ +import { Client } from "../../../apiv2"; +import { firestackApiOrigin } from "../../../api"; + +export const API_VERSION = "v1"; + +const client = new Client({ + urlPrefix: firestackApiOrigin, + auth: true, + apiVersion: API_VERSION, +}); + +export type State = "BUILDING" | "BUILD" | "DEPLOYING" | "READY" | "FAILED"; + +/** A Stack, the primary resource of Frameworks. */ +interface StackBase { + name: string; + mode?: string; + labels: Record; + codebase: Codebase; +} + +interface Codebase { + repository?: string; + rootDirectory: string; +} + +export type OutputStack = StackBase & { + createTime: string; + updateTime: string; + uri: string; +}; + +interface Build { + name: string; + state: State; + image: string; + buildLogsUri: string; +} + +export type OutputBuild = Build & { + createTime: Date; + updateTime: Date; + sourceRef: string; +}; + +/** + * Creates a new Stack in a given project and location. + */ +export async function createStack( + projectId: string, + location: string, + functionId: string +): Promise { + const name = `projects/${projectId}/locations/${location}/functions/${functionId}`; + const res = await client.get(name); + return res.body; +} + +/** + * Creates a new Build in a given project and location. + */ +export async function createBuild( + projectId: string, + location: string, + functionId: string +): Promise { + const name = `projects/${projectId}/locations/${location}/functions/${functionId}`; + const res = await client.get(name); + return res.body; +} From 7eac41d33602f575ea53c9288d14d672bcffacb6 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Mon, 19 Jun 2023 16:50:04 -0700 Subject: [PATCH 2/8] Added more properties to the Stack and Build object --- .../compose/discover/firestackApi.ts | 102 ++++++++++++++---- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/src/frameworks/compose/discover/firestackApi.ts b/src/frameworks/compose/discover/firestackApi.ts index 7c4cdfeffa4..8c5ec8e214c 100644 --- a/src/frameworks/compose/discover/firestackApi.ts +++ b/src/frameworks/compose/discover/firestackApi.ts @@ -11,12 +11,31 @@ const client = new Client({ export type State = "BUILDING" | "BUILD" | "DEPLOYING" | "READY" | "FAILED"; -/** A Stack, the primary resource of Frameworks. */ -interface StackBase { +type RolloutPolicy = {}; +type Spec = {}; + +interface TrafficTarget { + build: string; + percent: number; +} + +interface TrafficTargetList { + values: TrafficTarget[]; +} + +interface RunService { name: string; - mode?: string; - labels: Record; - codebase: Codebase; +} + +interface ManagedResource { + // oneof managed_resource { + runService: RunService; + // end oneof managed_resource +} + +interface TrafficTargetStatus { + build: string; + percent: number; } interface Codebase { @@ -24,16 +43,33 @@ interface Codebase { rootDirectory: string; } +/** A Stack, the primary resource of Frameworks. */ +interface StackBase { + name: string; + mode?: string; + codebase: Codebase; + labels: Record; + // oneof traffic_management + traffic: TrafficTargetList; + rolloutPolicy: RolloutPolicy; + // end oneof traffic_management +} + export type OutputStack = StackBase & { createTime: string; updateTime: string; uri: string; + trafficStatuses: TrafficTargetStatus[]; + managedResources: ManagedResource[]; }; interface Build { name: string; state: State; + error: Status; image: string; + spec: Spec; + source: BuildSource; buildLogsUri: string; } @@ -43,28 +79,56 @@ export type OutputBuild = Build & { sourceRef: string; }; +interface BuildSource { + codeBaseSource?: CodebaseSource; +} + +interface Status { + code: number; + message: string; + details: any[]; +} + +interface CodebaseSource { + // oneof reference + branch: string; + commit: string; + tag: string; + // end oneof reference +} + +export interface OperationMetadata { + createTime: string; + endTime: string; + target: string; + verb: string; + statusDetail: string; + cancelRequested: boolean; + apiVersion: string; +} + +export interface Operation { + name: string; + metadata?: OperationMetadata; + done: boolean; + // oneof result + error?: Status; + response?: any; + // end oneof result +} + /** * Creates a new Stack in a given project and location. */ -export async function createStack( - projectId: string, - location: string, - functionId: string -): Promise { - const name = `projects/${projectId}/locations/${location}/functions/${functionId}`; - const res = await client.get(name); +export async function createStack(stack: StackBase): Promise { + const res = await client.post(stack.name, stack, {}); return res.body; } /** * Creates a new Build in a given project and location. */ -export async function createBuild( - projectId: string, - location: string, - functionId: string -): Promise { - const name = `projects/${projectId}/locations/${location}/functions/${functionId}`; - const res = await client.get(name); +export async function createBuild(build: Build): Promise { + const res = await client.post(build.name, build, {}); return res.body; } From d0d493e35c7bc7d43b44467fc3b0273ffb319350 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 20 Jun 2023 15:30:15 -0700 Subject: [PATCH 3/8] Added api calls for framework stacks --- .../compose/discover/firestackApi.ts | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/frameworks/compose/discover/firestackApi.ts b/src/frameworks/compose/discover/firestackApi.ts index 8c5ec8e214c..bd8014220dd 100644 --- a/src/frameworks/compose/discover/firestackApi.ts +++ b/src/frameworks/compose/discover/firestackApi.ts @@ -44,7 +44,7 @@ interface Codebase { } /** A Stack, the primary resource of Frameworks. */ -interface StackBase { +interface Stack { name: string; mode?: string; codebase: Codebase; @@ -53,15 +53,19 @@ interface StackBase { traffic: TrafficTargetList; rolloutPolicy: RolloutPolicy; // end oneof traffic_management -} - -export type OutputStack = StackBase & { createTime: string; updateTime: string; uri: string; trafficStatuses: TrafficTargetStatus[]; managedResources: ManagedResource[]; -}; +} + +export type StackOutputOnlyFields = + | "createTime" + | "updateTime" + | "uri" + | "trafficStatuses" + | "managedResources"; interface Build { name: string; @@ -71,13 +75,12 @@ interface Build { spec: Spec; source: BuildSource; buildLogsUri: string; -} - -export type OutputBuild = Build & { createTime: Date; updateTime: Date; sourceRef: string; -}; +} + +export type BuildOutputOnlyFields = "createTime" | "updateTime" | "sourceRef"; interface BuildSource { codeBaseSource?: CodebaseSource; @@ -120,15 +123,34 @@ export interface Operation { /** * Creates a new Stack in a given project and location. */ -export async function createStack(stack: StackBase): Promise { - const res = await client.post(stack.name, stack, {}); +export async function createStack( + projectId: string, + location: string, + stackId: string, + stack: Stack +): Promise { + const res = await client.post, Operation>( + `projects/${projectId}/locations/${location}/stacks`, + stack, + { queryParams: { stackId } } + ); return res.body; } /** * Creates a new Build in a given project and location. */ -export async function createBuild(build: Build): Promise { - const res = await client.post(build.name, build, {}); +export async function createBuild( + projectId: string, + location: string, + stackId: string, + buildId: string, + build: Build +): Promise { + const res = await client.post, Operation>( + `projects/${projectId}/locations/${location}/stacks/${stackId}/builds`, + build, + { queryParams: { buildId } } + ); return res.body; } From ca48bca8ebac41c4690552b037b30cd2479cb935 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 20 Jun 2023 15:32:22 -0700 Subject: [PATCH 4/8] Changed naming --- src/api.ts | 7 ++++--- .../discover/{firestackApi.ts => frameworkstackApi.ts} | 0 2 files changed, 4 insertions(+), 3 deletions(-) rename src/frameworks/compose/discover/{firestackApi.ts => frameworkstackApi.ts} (100%) diff --git a/src/api.ts b/src/api.ts index 00726f31760..d22fc2d0ae1 100644 --- a/src/api.ts +++ b/src/api.ts @@ -173,9 +173,10 @@ export const serviceUsageOrigin = utils.envOverride( "FIREBASE_SERVICE_USAGE_URL", "https://serviceusage.googleapis.com" ); -export const firestackApiOrigin = utils.envOverride( - "FIRESTACK_API_URL", - "https://firestack.googleapis.com" +// TODO: Change to correct URL later. +export const frameworkstackApiOrigin = utils.envOverride( + "FRAMEWORKSTACK_API_URL", + "https://frameworkstack.googleapis.com" ); export const githubOrigin = utils.envOverride("GITHUB_URL", "https://github.com"); export const githubApiOrigin = utils.envOverride("GITHUB_API_URL", "https://api.github.com"); diff --git a/src/frameworks/compose/discover/firestackApi.ts b/src/frameworks/compose/discover/frameworkstackApi.ts similarity index 100% rename from src/frameworks/compose/discover/firestackApi.ts rename to src/frameworks/compose/discover/frameworkstackApi.ts From feb60258cda9f9e15633ae541d187e8d77b84ea2 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 20 Jun 2023 15:32:37 -0700 Subject: [PATCH 5/8] Changed naming --- src/frameworks/compose/discover/frameworkstackApi.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frameworks/compose/discover/frameworkstackApi.ts b/src/frameworks/compose/discover/frameworkstackApi.ts index bd8014220dd..a856b9106b4 100644 --- a/src/frameworks/compose/discover/frameworkstackApi.ts +++ b/src/frameworks/compose/discover/frameworkstackApi.ts @@ -1,10 +1,10 @@ import { Client } from "../../../apiv2"; -import { firestackApiOrigin } from "../../../api"; +import { frameworkstackApiOrigin } from "../../../api"; export const API_VERSION = "v1"; const client = new Client({ - urlPrefix: firestackApiOrigin, + urlPrefix: frameworkstackApiOrigin, auth: true, apiVersion: API_VERSION, }); From 81c2730616641b39b579af5d928bc79d571b039a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 20 Jun 2023 15:52:58 -0700 Subject: [PATCH 6/8] Review changes --- src/api.ts | 6 +++--- .../discover/{frameworkstackApi.ts => frameworks.ts} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/frameworks/compose/discover/{frameworkstackApi.ts => frameworks.ts} (96%) diff --git a/src/api.ts b/src/api.ts index d22fc2d0ae1..6286b8596c5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -174,9 +174,9 @@ export const serviceUsageOrigin = utils.envOverride( "https://serviceusage.googleapis.com" ); // TODO: Change to correct URL later. -export const frameworkstackApiOrigin = utils.envOverride( - "FRAMEWORKSTACK_API_URL", - "https://frameworkstack.googleapis.com" +export const frameworksOrigin = utils.envOverride( + "FRAMEWORKS_URL", + "https://placeholder.googleapis.com" ); export const githubOrigin = utils.envOverride("GITHUB_URL", "https://github.com"); export const githubApiOrigin = utils.envOverride("GITHUB_API_URL", "https://api.github.com"); diff --git a/src/frameworks/compose/discover/frameworkstackApi.ts b/src/frameworks/compose/discover/frameworks.ts similarity index 96% rename from src/frameworks/compose/discover/frameworkstackApi.ts rename to src/frameworks/compose/discover/frameworks.ts index a856b9106b4..d66d7baea63 100644 --- a/src/frameworks/compose/discover/frameworkstackApi.ts +++ b/src/frameworks/compose/discover/frameworks.ts @@ -1,10 +1,10 @@ import { Client } from "../../../apiv2"; -import { frameworkstackApiOrigin } from "../../../api"; +import { frameworksOrigin } from "../../../api"; export const API_VERSION = "v1"; const client = new Client({ - urlPrefix: frameworkstackApiOrigin, + urlPrefix: frameworksOrigin, auth: true, apiVersion: API_VERSION, }); From 7760c2d72458a71cdebb9a3c3508234f53386240 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Tue, 20 Jun 2023 15:58:24 -0700 Subject: [PATCH 7/8] Removed and used minimal fields --- src/frameworks/compose/discover/frameworks.ts | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/frameworks/compose/discover/frameworks.ts b/src/frameworks/compose/discover/frameworks.ts index d66d7baea63..c46d56847b1 100644 --- a/src/frameworks/compose/discover/frameworks.ts +++ b/src/frameworks/compose/discover/frameworks.ts @@ -11,33 +11,6 @@ const client = new Client({ export type State = "BUILDING" | "BUILD" | "DEPLOYING" | "READY" | "FAILED"; -type RolloutPolicy = {}; -type Spec = {}; - -interface TrafficTarget { - build: string; - percent: number; -} - -interface TrafficTargetList { - values: TrafficTarget[]; -} - -interface RunService { - name: string; -} - -interface ManagedResource { - // oneof managed_resource { - runService: RunService; - // end oneof managed_resource -} - -interface TrafficTargetStatus { - build: string; - percent: number; -} - interface Codebase { repository?: string; rootDirectory: string; @@ -49,30 +22,18 @@ interface Stack { mode?: string; codebase: Codebase; labels: Record; - // oneof traffic_management - traffic: TrafficTargetList; - rolloutPolicy: RolloutPolicy; - // end oneof traffic_management createTime: string; updateTime: string; uri: string; - trafficStatuses: TrafficTargetStatus[]; - managedResources: ManagedResource[]; } -export type StackOutputOnlyFields = - | "createTime" - | "updateTime" - | "uri" - | "trafficStatuses" - | "managedResources"; +export type StackOutputOnlyFields = "createTime" | "updateTime" | "uri"; interface Build { name: string; state: State; error: Status; image: string; - spec: Spec; source: BuildSource; buildLogsUri: string; createTime: Date; From 63fa9e323364a732ad590489d954df01b62e82fd Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 21 Jun 2023 13:41:00 -0700 Subject: [PATCH 8/8] Moved frameworks api file --- src/api.ts | 1 - src/{frameworks/compose/discover => api}/frameworks.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) rename src/{frameworks/compose/discover => api}/frameworks.ts (96%) diff --git a/src/api.ts b/src/api.ts index 6286b8596c5..0a362e63758 100644 --- a/src/api.ts +++ b/src/api.ts @@ -173,7 +173,6 @@ export const serviceUsageOrigin = utils.envOverride( "FIREBASE_SERVICE_USAGE_URL", "https://serviceusage.googleapis.com" ); -// TODO: Change to correct URL later. export const frameworksOrigin = utils.envOverride( "FRAMEWORKS_URL", "https://placeholder.googleapis.com" diff --git a/src/frameworks/compose/discover/frameworks.ts b/src/api/frameworks.ts similarity index 96% rename from src/frameworks/compose/discover/frameworks.ts rename to src/api/frameworks.ts index c46d56847b1..30fcc41bd66 100644 --- a/src/frameworks/compose/discover/frameworks.ts +++ b/src/api/frameworks.ts @@ -1,5 +1,5 @@ -import { Client } from "../../../apiv2"; -import { frameworksOrigin } from "../../../api"; +import { Client } from "../apiv2"; +import { frameworksOrigin } from "../api"; export const API_VERSION = "v1";