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"
Google Cloud Platform provides a metadata server that knows details about your App Engine instance, such as its containing project ID, service accounts, and tokens used by the service accounts. You can access this data using simple HTTP requests: no client libraries are required.
The SAS Metadata Server is a multi-user server that enables users to read metadata from and write metadata to one or more SAS Metadata Repositories. This server is a centralized resource for storing, managing, and delivering metadata for all SAS applications across the enterprise.
The metadata for a VM contains information about the VM (such as the name, description, and Universally Unique Identifier (UUID), VM configuration (such as the amount of virtual memory and the number of virtual CPUs), and information about the use of resources on the host or Resource Pool (such as Virtual Networks, ...
Cloud Functions removes the work of managing servers, configuring software, updating frameworks, and patching operating systems. The software and infrastructure are fully managed by Google so that you just add code. Furthermore, provisioning of resources happens automatically in response to events.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With