Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FireBase sendMessage Function update to v1 Google Cloud Endpoint

So... this morning... I got an email saying:

Our records show that you own projects with App Engine applications or Cloud Functions that are still calling the pre-GA v0.1 and v1beta1 endpoints of the App Engine and Cloud Functions metadata server.

We’re writing to let you know that these legacy endpoints are scheduled to be turned down on April 30, 2020. After April 30, 2020, requests to the v0.1 and v1beta1 endpoints will no longer be supported, and may return HTTP 404 NOT FOUND responses.

I'm only using Firebase Functions to send messages... and the email went on to identify my sendMessage function as the culprit. But I can't... for the life of me... figure out WHERE I need to update the endpoints. My sendMessage function is as follows:

exports.sendMessage = functions.database.ref('/messages/{receiverUid}/{senderUid}/{msgId}')
    .onWrite(async (change, context) => {
      const message = change.after.val().body;
      const receiverUid = change.after.val().receiverUid;
      const senderUid = change.after.val().senderUid;
      const msgId = change.after.val().msgId;
      if (!change.after.val()) {
        return console.log('Sender ', senderUid, 'receiver ', receiverUid, 'message ', message);
      }
      console.log('We have a new message: ', message, 'for: ', receiverUid);

I've tried following some of the Curl suggestions from this link: https://cloud.google.com/compute/docs/migrating-to-v1-metadata-server

...but every time I try one of them I get:

curl: (6) Couldn't resolve host 'metadata.google.internal'

So... at this point... I have no idea what it is I'm supposed to change or where I'm supposed to look. Any help would be appreciated.

like image 961
mystic cola Avatar asked Nov 08 '19 03:11

mystic cola


2 Answers

I had this same problem, and didn't see any of the libraries I was using listed here.

In my case, the culprit turned out to be firebase-admin. I was using version 7.3.0, and I found this gem:

$ grep -rni "computeMetadata/" *
firebase-admin/lib/auth/credential.js:30:var GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1beta1/instance/service-accounts/default/token';

So, I updated my Cloud Functions libraries as shown here:

npm install firebase-functions@latest --save
npm install firebase-admin@latest --save-exact

and then, voila!

$ grep -rni "computeMetadata/" *
node_modules/firebase-admin/lib/auth/credential.js:30:var GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1/instance/service-accounts/default/token';

Then I redeployed and problem solved.

like image 53
Codiak Avatar answered Nov 15 '22 07:11

Codiak


I searched at the https://github.com/firebase/firebase-functions repo latest version (3.3.0), and I found the file: spec/fixtures/https.ts. Inside this file there are some mock functions, which use the old: /computeMetadata/v1beta1 endpoint.

This might mean that firebase-functions modules package should be updated to use the /computeMetadata/v1 endpoint instead.

like image 43
Antonis S Avatar answered Nov 15 '22 06:11

Antonis S