我已经为此工作了 2 天,对进展感到非常沮丧,任何关于我的理解/代码/方法可能有问题的指导将不胜感激!
我正在尝试使用 node.js 从秘密管理器获取版本值,下面的脚本在 GCE 上运行良好,但是每当我在 Cloud 函数上运行它时它都会失败。
// My script on GCE, it works fine
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const secretManagerServiceClient = new SecretManagerServiceClient();
const name = 'projects/moonhome/secrets/moonFirstSecret/versions/latest';
testSecretManager = async () => {
const [version] = await secretManagerServiceClient.accessSecretVersion({ name });
const payload = version.payload.data.toString();
console.debug(`Payload: ${payload}`);
};
testSecretManager();
// My index.js on Cloud Function
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const secretManagerServiceClient = new SecretManagerServiceClient();
const name = 'projects/moonhome/secrets/moonFirstSecret/versions/latest';
testSecretManager = async () => {
const [version] = await secretManagerServiceClient.accessSecretVersion({ name });
const payload = version.payload.data.toString();
console.debug(`Payload: ${payload}`);
};
exports.helloHttp = (req, res) => {
testSecretManager();
res.send("noooo1");
};
// One of many versions of packaga.json I tried on Cloud function
{
"dependencies": {
"@google-cloud/secret-manager": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/@google-cloud/secret-manager/-/secret-manager-3.1.0.tgz",
"integrity": "sha512-/9IOWEhKAz/r3kSyp16kjudELkEJSRhwFfzukKbzQehVRZ3RceNDzjn+Rti1TivODJHEEIBZVsQFsKp7cLfUgQ==",
"requires": {
"google-gax": "^2.1.0"
}
}
}
}
以下是我的问题:
我注意到 Cloud Function 中的 node.js 运行时上有一个可用系统包的列表,所以我想知道这是否是原因。我已经提交了添加
@google-cloud/secret-manager
到 node.js 运行时的请求。但是,在 Cloud Function 文档中有一个使用的示例,escape-html
该列表中也没有该示例。我的问题是,在我的情况下,我是否应该请求将 secret-manager 包添加到 node.js 运行时?由于 Cloud Function 需要一个事件触发器,我还尝试
testSecretManager
用一个简单的函数来包装它来处理 http 请求,并在我的浏览器的端点上对其进行测试。简单的函数本身工作正常,但是每当我将与秘密管理器相关的任何内容插入该函数时,该函数都会失败或页面显示它Error: could not handle the request
。我的问题是,我是否必须testSecretManager
使用 HTTP 请求或任何其他事件处理函数来触发 Cloud Function 中的目标函数?我
package.json
对云函数上的文件很困惑,当我在 GCE 中使用秘密管理器时,package-lock.json
有 600 多行,所以我尝试package.json
在云函数上处理这些行,但它不起作用.....我的问题是,当我想要的只是包时,我应该在 package.json 中包含@google-cloud/secret-manager
什么?