我正在尝试将我的环境变量切换到Google Secrets Manager,但我遇到了一个问题。我正在运行expressjs api,试图建立一个数据库连接。但是不管我怎么尝试,它只返回Promise { <pending> },而不是等待异步函数完成。任何帮助都是非常感谢的!
gcloud.js
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient();
async function getSecret(name) {
const name = `projects/PROJECT-ID/secrets/${name}/versions/latest`;
const [version] = await client.accessSecretVersion({
name: name,
});
const payload = version.payload.data.toString();
return payload;
}
module.exports.getSecret = getSecret;config.js
const gcloud = require('./config/gcloud.js')
const config = {
authSecret: gcloud.getSecret(SECRET_NAME)
}
module.exports = config发布于 2021-03-20 01:30:30
您需要对gcloud.getSecret的结果执行await
// Not actually valid
const config = {
authSecret: await gcloud.getSecret(SECRET_NAME)
}但是,顶级等待尚未得到广泛支持,因此您需要在函数NodeJS Async / Await - Build configuration file with API call中构建配置
https://stackoverflow.com/questions/66712713
复制相似问题