Reputation: 1208
I am using firebase cloud functions with Node to send push notifications triggered by realtime database events.
I got this email from Google telling me to update my requests to use the v1 endpoint. The email states:
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.
Identify the projects, apps and functions which are making these requests. Attached to this message you will find the list of projects, applications and functions that you own that have made requests to the v0.1 and v1beta1 metadata server endpoints between Sept 26, 2019 and Nov 1, 2019. Comment: I know what project it is.
Upgrade your Google client libraries to the latest versions. See supported library versions for the list of Google SDKs that require an update. Comment: this I don't understand. Do I need to do this?
If you are making direct requests to the legacy Metadata Server endpoints: To ensure minimal interruption to your instances, please update your requests to the v1 endpoint before April 30, 2020. Comment: I don't know if I'm making direct requests
How to upgrade from v1beta1 request to v1 requests: If you are making direct requests to the v1beta1 URI, please follow the following steps to upgrade to the v1 URI: Change the request URI to use v1 instead of v1beta1 Add this header to your request: “Metadata-Flavor: Google” For example, if you’re currently making this request: curl "http://metadata.google.internal/computeMetadata/v1beta1/instance/id" Upgrade to v1 as follows: curl "http://metadata.google.internal/computeMetadata/v1/instance/id” -H "Metadata-Flavor: Google" How to upgrade from v0.1 requests to v1 requests: If you are making direct requests to the v0.1 URI, please follow the following steps to upgrade to the v1 URI: Change the request URI to use v1 instead of v0.1 Add this header to your request: “Metadata-Flavor: Google” Use these instructions to map the v0.1 properties to the v1 properties For example, if you’re currently making this request: curl "http://metadata.google.internal/0.1/meta-data/instance-id" Upgrade to v1 as follows: curl "http://metadata.google.internal/computeMetadata/v1/instance/id” -H "Metadata-Flavor: Google" Redeploy your application The steps above will require another application deployment to take effect.
I searched the Google Cloud support webb (as suggested in the email) and here on SO. But I don’t understand how to do this.
Please bare in mind I’m a complete novice. Any help or advice is greatly appreciated!
UPDATE Apparently this function has made requests to the v0.1 and v1beta1 metadata server endpoints:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendErrorInputWasSentPush = functions.database.ref('/errorInputs/{barcode}/{date}').onWrite((change, context) => {
const barcode = context.params.barcode
const dataAfter = change.after.val()
const input = dataAfter.input
const pushIDs = [
"",
""]
console.log(`Error input submitted.`)
const payload = {
notification: {
title: '',
body: '',
sound: "default"
}
};
const options = {
priority: "high",
timeToLive: 60 * 60 * 24
};
return admin.messaging().sendToDevice(pushIDs, payload, options);
});
Firebase versions:
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.2.0"
Upvotes: 6
Views: 1139
Reputation: 75930
If you never perform any query to http://metadata.google.internal/...
URL from your code or script, that changes nothing!
If you use this URL, paste your code, we could help you.
UPDATE
Thanks to your details, I found the problem in the file src/auth/credential.ts
of firebase-admin-node github project. Up to the version 8.1.0 the value of the line 32 is:
const GOOGLE_METADATA_SERVICE_PATH = '/computeMetadata/v1beta1/instance/service-accounts/default/token';
Use the version 8.2.0
or above to solve this
Upvotes: 12