Skip to content

Commit

Permalink
Update GCF v2 API call to include filter condition for listing v2 fun…
Browse files Browse the repository at this point in the history
…ctions. (#5001)
  • Loading branch information
taeold committed Sep 22, 2022
1 parent 673c6ab commit a2b9389
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/gcp/cloudfunctionsv2.ts
@@ -1,6 +1,6 @@
import * as clc from "colorette";

import { Client } from "../apiv2";
import { Client, ClientVerbOptions } from "../apiv2";
import { FirebaseError } from "../error";
import { functionsV2Origin } from "../api";
import { logger } from "../logger";
Expand All @@ -19,7 +19,7 @@ import {
HASH_LABEL,
} from "../functions/constants";

export const API_VERSION = "v2alpha";
export const API_VERSION = "v2";

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

0 comments on commit a2b9389

Please sign in to comment.