Can I use PouchDB to configure couchdb database _security settings?

49 views
Skip to first unread message

theOzarker

unread,
May 3, 2020, 3:12:29 PM5/3/20
to PouchDB
Using a perl script, I can set the "permissions" for a couchdb like so:

my $addSecurity = `curl -vX PUT $db_url/$name/_security -Hcontent-type:application/json --data-binary '{"admins":{"names":["admin"],"roles":["author"]},"members":{"names":["$name", "admin"],"roles":[]}}'`;

Is there a way to do that with PouchDB after I use it to create a new database on a CouchDB?

Sinan Gabel

unread,
May 5, 2020, 4:57:54 AM5/5/20
to PouchDB
Not sure about pouchdb directly but you can use fetch in javascript in browser or node-fetch in nodejs.


theOzarker

unread,
May 18, 2020, 6:08:49 PM5/18/20
to pou...@googlegroups.com
Thank you Sinan!

I didn't even know there was a "fetch" method in JS.

Took me a bit but I finally got with this:

var admin_name =  $("#admin_name").val();
var admin_password = $("#admin_password").val();
var name = $("#name").val();
var password = $("#password").val();

const data = {

 "admins": {"names":["admin"],"roles":["author"]},  
 "members": {"names":[""+name+"", "admin"],"roles":[]}
};

fetch('http://localhost:5984/'+name+'/_security', {
 method: 'PUT',
 headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(admin_name + ":" + admin_password),
 },
 body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
 console.log('Success:', data);
})
.catch((error) => {
 console.error('Error:', error);
});

Reply all
Reply to author
Forward
0 new messages