couchdb_connector v0.5.0 Couchdb.Connector.Admin
The Admin module provides functions to create and update users in the CouchDB server given by the database properties.
Examples
db_props = %{protocol: "http", hostname: "localhost",database: "couchdb_connector_test", port: 5984}
%{database: "couchdb_connector_test", hostname: "localhost", port: 5984, protocol: "http"}
Couchdb.Connector.Admin.create_user(db_props, "jan", "relax", ["couchdb contributor"])
{:ok,
"{\"ok\":true,\"id\":\"org.couchdb.user:jan\",\"rev\":\"1-1d509578d1bc8cba3a6690fca5e7a9fd\"}\n",
[{"Server", "CouchDB/1.6.1 (Erlang OTP/18)"},
{"Location", "http://localhost:5984/_users/org.couchdb.user:jan"},
{"ETag", "\"1-1d509578d1bc8cba3a6690fca5e7a9fd\""},
{"Date", "Thu, 31 Mar 2016 21:50:04 GMT"},
{"Content-Type", "text/plain; charset=utf-8"}, {"Content-Length", "83"},
{"Cache-Control", "must-revalidate"}]}
Couchdb.Connector.Admin.create_user(db_props, "jan", "relax", ["couchdb contributor"])
{:error,
"{\"error\":\"conflict\",\"reason\":\"Document update conflict.\"}\n",
[{"Server", "CouchDB/1.6.1 (Erlang OTP/18)"},
{"Date", "Thu, 31 Mar 2016 21:50:06 GMT"},
{"Content-Type", "text/plain; charset=utf-8"}, {"Content-Length", "58"},
{"Cache-Control", "must-revalidate"}]}
Couchdb.Connector.Admin.user_info(db_props, "jan")
{:ok,
"{\"_id\":\"org.couchdb.user:jan\",\"_rev\":\"1-...\",
\"password_scheme\":\"pbkdf2\",\"iterations\":10,\"type\":\"user\",
\"roles\":[\"couchdb contributor\"],\"name\":\"jan\",
\"derived_key\":\"a294518...\",\"salt\":\"70869...\"}\n"}
Couchdb.Connector.Admin.destroy_user(db_props, "jan")
{:ok,
"{\"ok\":true,\"id\":\"org.couchdb.user:jan\",\"rev\":\"2-429e8839208ed64cd58eae75957cc0d4\"}\n"}
Couchdb.Connector.Admin.user_info(db_props, "jan")
{:error, "{\"error\":\"not_found\",\"reason\":\"deleted\"}\n"}
Couchdb.Connector.Admin.destroy_user(db_props, "jan")
{:error, "{\"error\":\"not_found\",\"reason\":\"deleted\"}\n"}
Summary
Functions
Returns hashed information for the given admin or an error in case the admin does not exist or if the given credentials are wrong
Create a new admin with given username and password. In case of success, the function will respond with an empty body. In case of failures (e.g. if admin already exists), the response will be {:error, body, headers}
Create a new user with given username, password and roles. In case of success, the function will respond with {:ok, body, headers}. In case of failures (e.g. if user already exists), the response will be {:error, body, headers}. Please note that the credentials used in db_properties must be the credentials of an admin user
Deletes the given admin from the database server or returns an error in case the admin cannot be found
Deletes the given user from the database server or returns an error in case the user cannot be found. Requires admin basic auth credentials
Set the security object for a given database. Security object includes admins and members for the database
Returns the public information for the given user or an error in case the user does not exist
Functions
admin_info(Couchdb.Connector.Types.db_properties) :: {:ok, String.t} | {:error, String.t}
Returns hashed information for the given admin or an error in case the admin does not exist or if the given credentials are wrong.
create_admin(Couchdb.Connector.Types.db_properties, Couchdb.Connector.Types.user_info) :: {:ok, String.t, Couchdb.Connector.Types.headers} | {:error, String.t, Couchdb.Connector.Types.headers}
Create a new admin with given username and password. In case of success, the function will respond with an empty body. In case of failures (e.g. if admin already exists), the response will be {:error, body, headers}.
Create a new user with given username, password and roles. In case of success, the function will respond with {:ok, body, headers}. In case of failures (e.g. if user already exists), the response will be {:error, body, headers}. Please note that the credentials used in db_properties must be the credentials of an admin user.
destroy_admin(Couchdb.Connector.Types.db_properties, String.t, String.t) :: {:ok, String.t} | {:error, String.t}
Deletes the given admin from the database server or returns an error in case the admin cannot be found.
destroy_user(Couchdb.Connector.Types.db_properties, String.t) :: {:ok, String.t} | {:error, String.t}
Deletes the given user from the database server or returns an error in case the user cannot be found. Requires admin basic auth credentials.
set_security(Couchdb.Connector.Types.db_properties, [String.t], [String.t]) :: {:ok, String.t} | {:error, String.t}
Set the security object for a given database. Security object includes admins and members for the database.
user_info(Couchdb.Connector.Types.db_properties, String.t) :: {:ok, String.t} | {:error, String.t}
Returns the public information for the given user or an error in case the user does not exist.