-
Notifications
You must be signed in to change notification settings - Fork 1.1k
updates runv2.ts with listServices function and trigger updates #9482
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
Changes from all commits
94046bf
fff9ff3
dce07ab
99ece3c
432d686
6676deb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Adds listServices and also defines trigger within runv2.ts [#9482] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,6 +200,49 @@ export async function updateService(service: Omit<Service, ServiceOutputFields>) | |
| return svc; | ||
| } | ||
|
|
||
| /** | ||
| * Lists Cloud Run services in the given project. | ||
| * | ||
| * This method only returns services with the "goog-managed-by" label set to | ||
| * "cloud-functions" or "firebase-functions". | ||
| */ | ||
| export async function listServices(projectId: string): Promise<Service[]> { | ||
| const allServices: Service[] = []; | ||
| let pageToken: string | undefined = undefined; | ||
|
|
||
| do { | ||
| const queryParams: Record<string, string> = {}; | ||
| if (pageToken) { | ||
| queryParams["pageToken"] = pageToken; | ||
| } | ||
|
|
||
| const res = await client.get<{ services?: Service[]; nextPageToken?: string }>( | ||
| `/projects/${projectId}/locations/-/services`, | ||
| { queryParams }, | ||
| ); | ||
|
|
||
| if (res.status !== 200) { | ||
| throw new FirebaseError(`Failed to list services. HTTP Error: ${res.status}`, { | ||
| original: res.body as any, | ||
| }); | ||
| } | ||
|
|
||
| if (res.body.services) { | ||
| for (const service of res.body.services) { | ||
| if ( | ||
| service.labels?.[CLIENT_NAME_LABEL] === "cloud-functions" || | ||
| service.labels?.[CLIENT_NAME_LABEL] === "firebase-functions" | ||
| ) { | ||
| allServices.push(service); | ||
| } | ||
| } | ||
| } | ||
| pageToken = res.body.nextPageToken; | ||
| } while (pageToken); | ||
|
|
||
| return allServices; | ||
| } | ||
|
|
||
| // TODO: Replace with real version: | ||
| function functionNameToServiceName(id: string): string { | ||
| return id.toLowerCase().replace(/_/g, "-"); | ||
|
|
@@ -487,9 +530,16 @@ export function endpointFromService(service: Omit<Service, ServiceOutputFields>) | |
| service.annotations?.[FUNCTION_TARGET_ANNOTATION] || | ||
| service.annotations?.[FUNCTION_ID_ANNOTATION] || | ||
| id, | ||
|
|
||
| // TODO: trigger types. | ||
| httpsTrigger: {}, | ||
| // TODO: Figure out how to encode all trigger types to the underlying Run service that is compatible with both V2 functions and "direct to run" functions | ||
| ...(service.annotations?.[TRIGGER_TYPE_ANNOTATION] === "HTTP_TRIGGER" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: There are actually few other triggers types that all kind of look like HTTP function:
I'd be okay leaving this as todo as we figure out how to encode this information to the underlying Run service that is compatible with both V2 functions and "direct to run" functions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added TODO |
||
| ? { httpsTrigger: {} } | ||
| : { | ||
| eventTrigger: { | ||
| eventType: service.annotations?.[TRIGGER_TYPE_ANNOTATION] || "unknown", | ||
| // TODO: Figure out how to recover the retry info from Run (vs Functions API) as we currently default to false. | ||
| retry: false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a TODO comment here on figuring out how we currently set this to false b/c we don't know how to recover the info from Run (vs Functions API)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added TODO |
||
| }, | ||
| }), | ||
| }; | ||
| proto.renameIfPresent(endpoint, service.template, "concurrency", "containerConcurrency"); | ||
| proto.renameIfPresent(endpoint, service.labels || {}, "codebase", CODEBASE_LABEL); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.