-
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 1 commit
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 |
|---|---|---|
|
|
@@ -200,6 +200,49 @@ | |
| 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; | ||
| } | ||
brittanycho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // TODO: Replace with real version: | ||
| function functionNameToServiceName(id: string): string { | ||
| return id.toLowerCase().replace(/_/g, "-"); | ||
|
|
@@ -487,9 +530,14 @@ | |
| service.annotations?.[FUNCTION_TARGET_ANNOTATION] || | ||
| service.annotations?.[FUNCTION_ID_ANNOTATION] || | ||
| id, | ||
|
|
||
| // TODO: trigger types. | ||
| httpsTrigger: {}, | ||
| ...(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", | ||
| 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); | ||
|
|
@@ -599,4 +647,4 @@ | |
|
|
||
| // TODO: other trigger types, service accounts, concurrency, etc. | ||
| return service; | ||
| } | ||
| } | ||
|
Check failure on line 650 in src/gcp/runv2.ts
|
||
Uh oh!
There was an error while loading. Please reload this page.