A library to manage users for CouchDB.
You will need:
- CouchDB URL (running locally or on a server)
- CouchDB admin username/password (optional: but without it security is moot)
- Node & NPM
Simply go to terminal and type:
npm install couch-admin
Feel free to look at examples below to see how easy it is to use this library!
var admin = require('couch-admin')({
url: 'http://localhost:5984',
user: 'admin',
pass: 'mysecretpassword'
user_db: '_users', // Optional
});
admin.createUser('leander', 'unhackable password', function (err) {
// Added a user!
})
admin.changePassword('leander', 'new unhackable password', function (err) {
// Changed the password for leander.
})
admin.createDatabase('my_documents', function (err) {
// New database called 'my_documents' created!
})
admin.grantMembership('leander', 'my_documents', function (err) {
// User 'leander' was given membership access to my_documents.
})
admin.revokeMembership('leander', 'my_documents', function (err) {
// User 'leander' is no longer a member of my_documents :(
})
admin.grantAdmin('leander', 'my_documents', function (err) {
// User 'leander' was given admin access to my_documents.
})
admin.revokeAdmin('leander', 'my_documents', function (err) {
// User 'leander' is no longer an admin of my_documents :(
})
admin.removeUser('leander', function (err) {
// User 'leander' was deleted :(
})
admin.removeDatabase('my_documents', function (err) {
// Database 'my_documents' was deleted :(
})
Unless otherwise specified, cb
is a callback that contains errors in its first parameter, and
response as its second. The response comes from CouchDB, and varies depending on the call. Feel
free to learn more about these calls at the resources linked below.
The URL to the CouchDB instance. (default: http://localhost:5984
)
The username for the admin of the CouchDB instance. (default: admin
)
The password for the admin of the CouchDB instance. (default: mysecretpassword
)
The user id prefix for users. (default: org.couchdb.user
)
The database name for the authentication db of the CouchDB instance. (default: _users
)
The database name for the config db of the CouchDB instance. (default: _config
)
The database name for the session db of the CouchDB instance. (default: _session
)
Gets the user with the given username.
Verifies that the username/password combination is valid.
Adds a user with the given username and password.
Edits the username to have a new password.
Removes the user with the given username.
Adds a database (initially with no permissions.)
Removes the database.
Adds username as a member of the database. Members will have read/write access to the data in the database, but cannot change the design docs.
Adds username as an admin of the database. Admins will have read/write access to the data in the database, and also be able to add, edit and remove design docs.
Removes username as a member of the database.
Removes username as an admin of the database.
Feel free to file an issue if you notice there are problems, and submit pull requests to contribute to this simple little library!