Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// use IAM creds
credentials.use_iam = true
credentials.iam_apikey = process.env.CLOUDANT_IAM_APIKEY
credentials.iam_username = process.env.CLOUDANT_IAM_USERNAME
console.log("credentials.iam_apikey: " + credentials.iam_apikey)
console.log("credentials.iam_username: " + credentials.iam_username)
} else {
credentials.username = process.env.CLOUDANT_USERNAME
credentials.password = process.env.CLOUDANT_PASSWORD
console.log("credentials.username: " + credentials.username)
console.log("credentials.password: " + credentials.password)
}
if (credentials.use_iam) {
// use IAM creds
var cloudant = new Cloudant({
account: credentials.iam_username,
plugins: [
'promises',
{
iamauth: {
iamApiKey: credentials.iam_apikey
}
}
],
plugin: 'promises' // Using the promises plugin to allow use of async/await
})
} else {
// use traditional uname/pwd
cloudant = Cloudant({
account: credentials.username,
password: credentials.password,
// use IAM creds
var cloudant = new Cloudant({
account: credentials.iam_username,
plugins: [
'promises',
{
iamauth: {
iamApiKey: credentials.iam_apikey
}
}
],
plugin: 'promises' // Using the promises plugin to allow use of async/await
})
} else {
// use traditional uname/pwd
cloudant = Cloudant({
account: credentials.username,
password: credentials.password,
plugin: 'promises' // Using the promises plugin to allow use of async/await
})
}
return cloudant
}