简体   繁体   English

FireBase sendMessage Function 更新到 v1 Google Cloud Endpoint

[英]FireBase sendMessage Function update to v1 Google Cloud Endpoint

So... this morning... I got an email saying:所以......今天早上......我得到了一个 email 说:

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.我们的记录显示,您拥有的项目包含仍在调用 App Engine 和 Cloud Functions 元数据服务器的 pre-GA v0.1 和 v1beta1 端点的 App Engine 应用程序或 Cloud Functions。

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.我们写信通知您,这些旧端点计划于 2020 年 4 月 30 日被拒绝。2020 年 4 月 30 日之后,将不再支持对 v0.1 和 v1beta1 端点的请求,并且可能会返回 HTTP 404未找到回复。

I'm only using Firebase Functions to send messages... and the email went on to identify my sendMessage function as the culprit.我只使用 Firebase 函数来发送消息......并且 email 继续将我的 sendMessage function 识别为罪魁祸首。 But I can't... for the life of me... figure out WHERE I need to update the endpoints.但我不能……为了我的一生……弄清楚我需要在哪里更新端点。 My sendMessage function is as follows:我的 sendMessage function 如下:

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我已经尝试遵循此链接中的一些 Curl 建议: 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' curl:(6)无法解析主机'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.任何帮助,将不胜感激。

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 .就我而言,罪魁祸首是firebase-admin I was using version 7.3.0, and I found this gem:我使用的是 7.3.0 版,我发现了这个 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 :因此,我更新了我的 Cloud Functions 库,如下所示

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.然后我重新部署并解决了问题。

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.我搜索了https://github.com/firebase/firebase-functions repo 最新版本(3.3.0),找到了文件:spec/fixtures/https.ts。 Inside this file there are some mock functions, which use the old: /computeMetadata/v1beta1 endpoint.在这个文件中有一些模拟函数,它们使用旧的:/computeMetadata/v1beta1 端点。

This might mean that firebase-functions modules package should be updated to use the /computeMetadata/v1 endpoint instead.这可能意味着应该更新 firebase-functions 模块 package 以使用 /computeMetadata/v1 端点。

Fwiw I found this old dependency in package.json was dragging in other very old packages: Fwiw 我发现package.json中的这个旧依赖项正在拖入其他非常旧的包:

"@google-cloud/functions-emulator": "^1.0.0-beta.6",

In particular it brought in gcs-resumable-upload v 0.10.2, which is below the v 0.13.0 recommended by google (see https://cloud.google.com/compute/docs/migrating-to-v1-metadata-server#apps-to-update ).特别是它引入了gcs-resumable-upload v 0.10.2,低于谷歌推荐的 v 0.13.0(参见https://cloud.google.com/compute/docs/migrating-to-v1-metadata-服务器#apps-to-update )。 Probably others too.可能其他人也一样。

The fix was to either:解决方法是:

  • remove @google-cloud/functions-emulator , or删除@google-cloud/functions-emulator ,或
  • switch to its modern replacement, @google-cloud/functions-framework切换到它的现代替代品@google-cloud/functions-framework

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM