benoitc/couchdbkit

BasicAuth CouchDB Example

Opened this issue · 1 comments

I looked around before posting this, but if I missed it in the channel, group, or another ticket, I apologise.

I noticed there was no example for authentication (cf. BasicAuth) against CouchDB. I was thinking it might be nice to put an official example of using BasicAuth up in the docs. I assume what I worked out is right, but I'm filing this here because there may already be a cleaner way, or this may be less than efficient for some reason. (And this probably belongs in docs, not on the wiki, but I'm happy to put it there if it's a better idea)

import couchdbkit
from restkit import BasicAuth

uri = "http://127.0.0.1:5984/"
username = "CouchDBUsername"
password = "CouchDBPassword"

CouchDBAuth = couchdbkit.resource.CouchdbResource(filters=[BasicAuth(username, password)])
CouchDBServer = couchdbkit.Server(uri, resource_instance=CouchDBAuth)

As the function is already in restkit, I assume there's no reason to configure helpers/wrappers for CouchDB to do this, and I also assume that OAuth is similar (though I wouldn't know and can't test, I only use BasicAuth for CouchDB at the moment).

Thanks for thar :) It could be on the wiki in a recipe part Imo waiting the big doc rewrite. Also you can do :

uri = "http://username:password@127.0.0.1:5984/"
CouchDBServer = couchdbkit.Server(uri)

It will works as well :)