You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2012/11/16 14:45:48 UTC

[Couchdb Wiki] Trivial Update of "How_to_create_users_via_script" by DaveCottlehuber

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "How_to_create_users_via_script" page has been changed by DaveCottlehuber:
http://wiki.apache.org/couchdb/How_to_create_users_via_script?action=diff&rev1=1&rev2=2

- = Creating Users in CouchDB via script =
+ = Creating Users via script =
  
  <<Include(EditTheWiki)>>
  <<TableOfContents(3)>>
@@ -35, +35 @@

  > Accept: */*
  > Content-Type:application/json
  > Content-Length: 99
- > 
+ >
  < HTTP/1.1 201 Created
  < Server: CouchDB/1.2.0 (Erlang OTP/R15B01)
  < Location: http://localhost:5984/_users/org.couchdb.user:wubble
@@ -44, +44 @@

  < Content-Type: text/plain; charset=utf-8
  < Content-Length: 86
  < Cache-Control: must-revalidate
- < 
+ <
  {"ok":true,"id":"org.couchdb.user:wubble","rev":"1-2e5fe1cfee2ab231788f73be8043acb5"}
  * Connection #0 to host localhost left intact
  * Closing connection #0
@@ -73, +73 @@

    "salt": "03f9e0f7e36d3b4c6f83a31c4c51868e"
  }
  
- $ curl -HContent-Type:application/json -vXPUT $COUCH/_users/org.couchdb.user:wibble --data-binary '{"_id": "org.couchdb.user:wibble","name": "wibble","roles": ["admin"],"type": "user","password": "tubble"}' 
+ $ curl -HContent-Type:application/json -vXPUT $COUCH/_users/org.couchdb.user:wibble --data-binary '{"_id": "org.couchdb.user:wibble","name": "wibble","roles": ["admin"],"type": "user","password": "tubble"}'
  * About to connect() to localhost port 5984 (#0)
  *   Trying ::1... Connection refused
  *   Trying 127.0.0.1... connected
@@ -84, +84 @@

  > Accept: */*
  > Content-Type:application/json
  > Content-Length: 106
- > 
+ >
  < HTTP/1.1 403 Forbidden
  < Server: CouchDB/1.2.0 (Erlang OTP/R15B01)
  < Date: Wed, 02 May 2012 11:49:49 GMT
  < Content-Type: text/plain; charset=utf-8
  < Content-Length: 59
  < Cache-Control: must-revalidate
- < 
+ <
  {
    "error": "forbidden",
    "reason": "Only _admin may set roles"
@@ -100, +100 @@

  * Closing connection #0
  }}}
  
+ = Creating per-user Databases via script =
+ 
+ A common pattern is to create a per-user database, that is only accessible by that user, for read & writing. You'll need to disable Admin Party by creating a server admin.
+ 
+  * Create a user:
+ 
+ {{{
+ COUCH=http://admin:passwd@localhost:5984
+ curl -HContent-Type:application/json \
+   -vXPUT $COUCH/_users/org.couchdb.user:me \
+   --data-binary '{"_id": "org.couchdb.user:me","name": "me","roles": [],"type": "user","password": "pwd"}'
+ }}}
+ 
+  * create the DB
+ 
+ {{{
+ curl -vX PUT $COUCH/me
+ }}}
+ 
+ 
+  * update the DB security object
+ 
+ {{{
+ curl -vX PUT $COUCH/me/_security  \
+    -Hcontent-type:application/json \
+     --data-binary '{"admins":{"names":[],"roles":[]},"members":{"names":["me"],"roles":[]}}'
+ }}}
+