错误:无法加载默认凭据

时间:2020-01-01 19:32:42

标签: node.js firebase google-cloud-functions

我有一些通过邮递员使用的Firebase功能。直到几天前,它一直有效,我唯一想到的就是我为CI / CD管道创建了一个Firebase CI令牌,以便在部署到Firebase托管时使用它的CI / CD管道。

一切都部署良好,但是在执行我的一个功能时遇到此错误:

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.getApplicationDefaultAsync (/srv/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)

此特殊功能可与Mail Chimp联系,以将用户添加到邮件列表中。

这是我的Firebase功能的index.js:

const admin = require('firebase-admin')
const adminKey = require('./key/admin.json');

admin.initializeApp({
  credential: admin.credential.cert(adminKey),
  databaseURL: "https://PROJECT-ID.firebaseio.com"
});


// Functions ----------
exports.general = require('./categories/general/index')
...

我已经在其他Stackoverflow帖子以及Firebase文档中看到了这种方法。

这是实际的功能代码本身:

const functions = require('firebase-functions')
const axios = require('axios')
const { Logging } = require('@google-cloud/logging')
const cors = require('cors')({origin: true});

const logging = new Logging()
const log = logging.log('general')
const METADATA = {
  resource: {
    type: 'cloud_function',
    labels: {
      function_name: 'general-addNewSubscriber',
      region: 'us-central1'
    }
  }
}


module.exports = functions.https.onRequest(async (req, res) => {
    return cors(req, res, async () => {
        try {
            const logOne = log.entry(METADATA, { event: 'addNewSubscriber:started', value: 'started', message: 'general-addNewSubscriber:started' })
            await log.write(logOne)

            const result = await axios({
                method: 'post',
                url: 'API ENDPOINT',
                auth: {
                    username: 'username',
                    password: 'password'
                },
                data: {
                    email_address: req.body.email_address,
                    status: req.body.status
                }
            })

            const logTwo = log.entry(METADATA, { event: 'addNewSubscriber:response', value: result, message: 'general-addNewSubscriber:response' })
            await log.write(logTwo)

            res.send(result)
        } catch (err) {
            const errOne = log.error(METADATA, { event: 'addNewSubscriber:error', value: err, message: 'general-addNewSubscriber:error' })
            await log.write(errOne)

            res.send(err)
        }
    })
})

有什么建议吗?

修改 当我删除日志记录时,错误消失了。还有更多...

0 个答案:

没有答案