Skip to content

Commit a2b9389

Browse files
authored
Update GCF v2 API call to include filter condition for listing v2 functions. (#5001)
1 parent 673c6ab commit a2b9389

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/gcp/cloudfunctionsv2.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as clc from "colorette";
22

3-
import { Client } from "../apiv2";
3+
import { Client, ClientVerbOptions } from "../apiv2";
44
import { FirebaseError } from "../error";
55
import { functionsV2Origin } from "../api";
66
import { logger } from "../logger";
@@ -19,7 +19,7 @@ import {
1919
HASH_LABEL,
2020
} from "../functions/constants";
2121

22-
export const API_VERSION = "v2alpha";
22+
export const API_VERSION = "v2";
2323

2424
const client = new Client({
2525
urlPrefix: functionsV2Origin,
@@ -351,7 +351,11 @@ async function listFunctionsInternal(
351351
let pageToken = "";
352352
while (true) {
353353
const url = `projects/${projectId}/locations/${region}/functions`;
354-
const opts = pageToken === "" ? {} : { queryParams: { pageToken } };
354+
// V2 API returns both V1 and V2 Functions. Add filter condition to return only V2 functions.
355+
const opts: ClientVerbOptions = { queryParams: { filter: `environment="GEN_2"` } };
356+
if (pageToken !== "") {
357+
opts.queryParams = { ...opts.queryParams, pageToken };
358+
}
355359
const res = await client.get<Response>(url, opts);
356360
functions.push(...(res.body.functions || []));
357361
for (const region of res.body.unreachable || []) {

0 commit comments

Comments
 (0)