Last active
August 29, 2015 14:01
-
-
Save joshisa/9e3a657fbd41732259cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cloudantCreds = { | |
username: 'cloudantusername', | |
password: 'cloudantpassword' | |
}; | |
var dbname = 'cloudantdbname'; | |
var auth = 'Basic ' + new Buffer( cloudantCreds.username + ':' + cloudantCreds.password).toString('base64'); | |
var options = { | |
hostname: cloudantCreds.username + '.cloudant.com', | |
port: 443, | |
path: '/' + dbname + '/_security', | |
method: 'GET', | |
headers: { | |
'Authorization' : auth, | |
'Content-Type': 'application/json' | |
} | |
}; | |
var request=https.request(options, function(response) { | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
if (JSON.parse(chunk).ok === true) { | |
console.log('Users for ' + dbname.toUpperCase() + 'successfully enumerated.'); | |
var users = JSON.parse(chunk).cloudant; | |
for(var username in users) { | |
if (users.hasOwnProperty(username)) { | |
if (users[username] == '_writer' && username !== '_reader') { | |
console.log('API Key user with _writer permissions: ' + username + ' found.'); | |
var apikeyuser = username; | |
} | |
} | |
} | |
} else { | |
console.log("Failed to enumerate database users"); | |
console.log(JSON.parse(chunk).ok); | |
console.log('Body: ' + chunk); | |
} | |
}); | |
}); | |
request.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment