【发布时间】:2022-01-14 07:39:03
【问题描述】:
function credential(secretFromVault) {
const creddetails = new ClientSecretCredential(clientId, tenantId, cleintSecret);
// Build the URL to reach your key vault
const url = `https://<vaultName>.vault.azure.net/`;
// Lastly, create our secrets client and connect to the service
const client = new SecretClient(url, creddetails);
const secretName = secretFromVault;
return new Promise(resolve => {
client.getSecret(secretName).then(latestSecret => {
console.log(`value from secret is`, latestSecret.value);
resolve(latestSecret.value)
})
})
}
const dbUserName = credential(constants.pgDbUserName)
const dbPassword = credential(constants.pgDbPassword)
const hostname = constants.pgHostname;
const port = constants.pgPort;
const dbName = constants.pgDbName;
const sequelize = new Sequelize(dbName, dbUserName, dbPassword, {
host: hostname,
port: port,
dialect: constants.dialectName,
logging: false,
pool: {
max: constants.pgMaxPoolConnections,
min: constants.pgMinPoolConnections,
acquire: constants.pgMakeConnectionTimeOut,
idle: constants.pgIdleTimeout
}
});
sequelize.authenticate()
.then(() => {
console.log('Successfully connected.');
User.sync();
Credentials.sync();
App.sync();
Entity.sync();
EntityField.sync();
Relationship.sync();
})
.catch(err => console.log('Error: ' + err))
我正在使用上面的代码连接到 postgres 数据库。但是我在执行节点索引命令时收到以下错误,这里没有附加 index.js。 我希望 dbUSerName 和 dbUserpassword 值在从 Vault 中获取后传递到 sequelize 连接字符串中。但这些价值观是我无法解决的承诺。
错误:uncaughtException:“字符串”参数必须是字符串类型或 Buffer 或 ArrayBuffer 的实例。收到一个 Promise 实例
【问题讨论】:
标签: javascript node.js async-await sequelize.js