Tag: google cloud functions

使用谷歌云function来产生一个Python脚本

我需要执行一些python机器学习代码,希望能够通过Google Cloud Function中的节点进程执行它。 我想要使​​用节点,因为我有一些后续要运行的Firebasepipe理任务。 我也有一个我很满意的节点的部署工作stream程。 这可能吗? 如果是这样,你能指点我一个例子吗?

Request.body是空的对象

在我的客户端,我正在用这样的数据对我的Firebase node.js服务器上的webhook进行抓取。 const url = 'https://us-central1-<app>.cloudfunctions.net/addUserdata'; const data = { firstName: 'John', lastName: 'Doe', email: 'john.doe@email.com' } const request = new Request(url, { method: 'POST', body: data, mode: 'no-cors', headers: new Headers() }); fetch(request) .then(function(result) { console.log(result); }) 我只是试图抓住现在这样的数据。 exports.addUserdata = functions.https.onRequest((req, res) => { console.log(req.body); res.send(200); }); 不幸的是,我的要求是一个空的对象。 我失踪或做错了什么?

Firebase函数返回并承诺不会退出该函数

我仍然是Firebase世界的初学者,我一直在试图弄清楚下面的代码是什么问题,但是我没有任何可能的办法。 代码应该从数据库中的用户configuration文件中检索uid ,然后使用它来更新authenticationconfiguration文件,然后在authenticationconfiguration文件更新成功时再次更新数据库configuration文件。 在index.js我定义了一个导出的函数来处理来自HTML表单的POST参数。 下面的代码定义了另一个模块文件中的处理函数: exports.auUpdateUserByEmail = (req, res) => { // This handler function will retrieve the POSTed params of user profile // and will attempt to update the existing user authentication as well as // the database profiles. // // This function accepts the following params: // 1. User email // 2. Phone […]

对所有http请求使用Firebase函数ENOTFOUND

我试图设置一个函数,使用Express和发出HTTP请求,但我总是得到一个ENOTFOUND错误,无论我的要求。 我已经尝试使用4个不同的库(https,request,request-promise,requestify)提出请求,但是都给出了相同的错误。 我遵循这个例子来设置系统: minimal-webhook + authorized-https-endpoint 。 我的基本testingfunction,那也抛出了错误: "use strict"; const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(functions.config().firebase); const express = require("express"); const app = express(); const https = require("https"); app.get("*", (req, res) => { var testReq = https.request({ host: "www.google.com", path: "/recaptcha/api/siteverify" }, (res) => { console.log("Finished with response " + res); }); […]

如何检查https云function的身份validation?

我想弄清楚是否可以从客户端检查auth对象,调用firebase https云function来完成以下任务: 1)只允许validation过的电子邮件用户呼叫https端点,否则返回403。 2)以某种方式访问​​调用函数的客户端的uid,以便在数据库中设置节点像characters/:uid 。 原因是不允许重复的字符。 我可以在req.body中手动传递uid ,但这意味着任何人都可以摆弄这个,并通过发送任何types的uid作为req.body载荷来创build100个不同的字符。 只有解决方法我可以想到这是改变这种逻辑到数据库触发器,即客户端写入数据库void/characters/uid节点(数据库规则做这个整个validation),然后函数监听数据库中的这种变化,处理数据,并推动它characters/uid 但这意味着需要额外的逻辑,例如删除节点后,我不知道如何发回错误或成功的响应回到客户端,就像使用https函数,我们可以res.send(200)或发回错误。

如何授权访问Google云端函数中的目录API

有没有人有一个关于如何从谷歌云function访问Google的目录API的代码示例? 更具体地说,我想使用3LO刷新令牌来生成访问令牌,该令牌有权访问目录API,可能使用“googleapis”库。

Promise.all()替代,允许失败?

据我所知,Promise.all()并行地执行所有的事情,并在任何一个Promise中的第一个错误实例中返回一个错误。 现在如果我想同时运行所有的承诺,并等待他们完成,即使他们中的一个失败了呢? 有一个Promise方法或模块,我应该使用? 我发送一堆用户并行FCM推送通知和.then()排队如果其中任何一个失败是不是打算。 我正在做我的代码 //then chain .then(()=>{ let startChatPromises = []; for (let i = 0 ; i < queue_length ; i ++){ startChatPromises.push(matchUsers(some_key,some_key)); } return Promise.all(startChatPromises); }).then(()=>{// Continue processing even after failure ?}); let matchUsers = (room_id,…user_ids) => { let chat_key = admin.database().ref().child("chats").child(room_id).push().key; let participants = {}; user_ids.forEach(user_id=> { participants[`${user_id}`] = true; }); […]

为什么Firebase的云端function需要25秒?

为了清楚起见,我有其他的云function,它们都是间歇性地运行的(例如,从大约2-6秒的“冷”开始,并且全部使用相同的样板设置来导入pipe理实例并将该function作为模块输出) 我见过其他类似的post,但这实在是在烦扰我。 我有这样的云function: const admin = require('../AdminConfig'); const { reportError } = require('../ReportError'); module.exports = (event) => { const uid = event.params.uid; const snapshot = event.data; if (snapshot._newData === null ) { return null; } console.log('Create org begin running: ', Date.now()); const organisation = event.data.val(); const rootRef = admin.database().ref(); const ref = rootRef.child('/organisations').push(); const oid […]

Google Cloudfunction:支持Google Cloud KMS

我正在使用带有Pubsub触发器的Google Cloud Function(GCF),该触发器向第三方API发送HTTP请求。 GCF接收来自Pubsub主题的通知,该主题由不应该知道第三方API的服务使用。 第三方API需要使用基本HTTP身份validation进行身份validation。 为了不必在源代码中对密码进行硬编码,我每次部署我的函数时都使用Google KMS生成新的encryption密钥。 每次实例化函数时,我都使用Google Cloud KMS来解密秘密。 对于使用KMS解密,我必须为NodeJS Google API提供服务帐户的私钥。 我今天的主要问题是,如果我希望GCF正常工作,我必须将我的私钥推送到GCloud Bucket。 是否可以通过使用Runtime Configurator或Deployment Manager来configurationGoogle Cloud Function的机密? 谢谢。

带有Gmail“发件人:地址”的Nodemailer不会更改

我正尝试将电子邮件发送给我的邮件列表中的任何新订阅者。 一切都很好,但“发件人”的电子邮件地址不会改变为“noreplay”,它仍然是我authentication的电子邮件,在这种情况下,我的工作邮件。例如,如果我将“from”设置为“noreply @ example .com“发送来自”jaafar@example.com“的邮件,这是我的代码: if (snapshot.child("subscribed").val() === 'true') { var value = snapshot.child("email").val(); //ignore this var key = snapshot.key; //ignore this var mailHtml = val.htmlText1 + httpLink + key + val.htmlText2; //ignore this let mailOptions = { from: '"JaafarsCompany" <noreply@jaafarsCompany.io>', // sender address to: value, // list of receivers subject: 'Hello', // Subject line […]