diff --git a/2nd-gen/taskqueues-backup-images/README.md b/2nd-gen/taskqueues-backup-images/README.md index a6787477a3..cfa20bd27e 100644 --- a/2nd-gen/taskqueues-backup-images/README.md +++ b/2nd-gen/taskqueues-backup-images/README.md @@ -77,12 +77,12 @@ gcloud projects add-iam-policy-binding $PROJECT_ID \ Please follow Google Cloud IAM documentation to add App Engine default service account as user of App Engine default service account. ``` -* Identity used to trigger the Task Queue function needs `cloudfunctions.functions.invoke` permission. +* Identity used to trigger the Task Queue function needs `run.routes.invoke` permission. * In our sample, this is the [Compute Engine default service account](https://cloud.google.com/compute/docs/access/service-accounts). ``` gcloud functions add-iam-policy-binding backupapod \ --region=us-central1 \ --member=serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com \ - --role=roles/cloudfunctions.invoker + --role=roles/run.invoker ``` \ No newline at end of file diff --git a/2nd-gen/taskqueues-backup-images/functions/index.js b/2nd-gen/taskqueues-backup-images/functions/index.js index 7600168578..1d62bcb8e5 100644 --- a/2nd-gen/taskqueues-backup-images/functions/index.js +++ b/2nd-gen/taskqueues-backup-images/functions/index.js @@ -22,7 +22,6 @@ const {onRequest} = require("firebase-functions/v2/https"); const {initializeApp} = require("firebase-admin/app"); const {getFunctions} = require("firebase-admin/functions"); const {getStorage} = require("firebase-admin/storage"); -const {GoogleAuth} = require("google-auth-library"); const logger = functions.logger; const HttpsError = functions.https.HttpsError; initializeApp(); @@ -99,41 +98,10 @@ exports.backupapod = onTaskDispatched( }); -let auth; - -// [START v2GetFunctionUri] -/** - * Get the URL of a given v2 cloud function. - * - * @param {string} name the function's name - * @param {string} location the function's location - * @return {Promise<string>} The URL of the function - */ -async function getFunctionUrl(name, location="us-central1") { - if (!auth) { - auth = new GoogleAuth({ - scopes: "https://www.googleapis.com/auth/cloud-platform", - }); - } - const projectId = await auth.getProjectId(); - const url = "https://cloudfunctions.googleapis.com/v2beta/" + - `projects/${projectId}/locations/${location}/functions/${name}`; - - const client = await auth.getClient(); - const res = await client.request({url}); - const uri = res.data?.serviceConfig?.uri; - if (!uri) { - throw new Error(`Unable to retreive uri for function at ${url}`); - } - return uri; -} -// [END v2GetFunctionUri] - // [START v2EnqueueTasks] exports.enqueuebackuptasks = onRequest( async (_request, response) => { const queue = getFunctions().taskQueue("backupapod"); - const targetUri = await getFunctionUrl("backupapod"); const enqueues = []; for (let i = 0; i <= BACKUP_COUNT; i += 1) { @@ -149,7 +117,6 @@ exports.enqueuebackuptasks = onRequest( queue.enqueue({date}, { scheduleDelaySeconds, dispatchDeadlineSeconds: 60 * 5, // 5 minutes - uri: targetUri, }), ); } diff --git a/2nd-gen/taskqueues-backup-images/functions/package.json b/2nd-gen/taskqueues-backup-images/functions/package.json index b6ab316f1f..339fffc51f 100644 --- a/2nd-gen/taskqueues-backup-images/functions/package.json +++ b/2nd-gen/taskqueues-backup-images/functions/package.json @@ -18,7 +18,6 @@ "dependencies": { "firebase-admin": "^11.5.0", "firebase-functions": "^4.2.1", - "google-auth-library": "^8.6.0", "node-fetch": "^2.6.7" }, "devDependencies": {