You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by kl...@apache.org on 2015/08/10 21:46:27 UTC

[01/15] couchdb-peruser git commit: Make it compatible with Apache CouchDB 2.0

Repository: couchdb-peruser
Updated Branches:
  refs/heads/master 16bd1f92b -> bb95f4a28


Make it compatible with Apache CouchDB 2.0


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/8ccf57e4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/8ccf57e4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/8ccf57e4

Branch: refs/heads/master
Commit: 8ccf57e4ebbde2649c843df763fccd01ffcd7fbb
Parents: 16bd1f9
Author: Klaus Trainer <kl...@posteo.de>
Authored: Fri Mar 13 22:24:21 2015 +0100
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Fri Mar 13 23:03:14 2015 +0100

----------------------------------------------------------------------
 src/couchperuser.erl | 67 +++++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/8ccf57e4/src/couchperuser.erl
----------------------------------------------------------------------
diff --git a/src/couchperuser.erl b/src/couchperuser.erl
index a6ffa2c..27a7489 100644
--- a/src/couchperuser.erl
+++ b/src/couchperuser.erl
@@ -1,11 +1,16 @@
 -module(couchperuser).
 -behaviour(gen_server).
+-behaviour(config_listener).
 
 -include_lib("couch/include/couch_db.hrl").
 
+% gen_server callbacks
 -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2,
          terminate/2, code_change/3]).
 
+% config_listener callbacks
+-export([handle_config_change/5, handle_config_terminate/3]).
+
 -export([init_changes/2, change_filter/3]).
 
 %% Note that this doesn't actually depend on having a registered name
@@ -19,24 +24,29 @@ start_link() ->
     gen_server:start_link({local, ?NAME}, ?MODULE, [], []).
 
 init([]) ->
-    ?LOG_DEBUG("couchperuser daemon: starting link.", []),
-    Db_Name = ?l2b(couch_config:get(
+    couch_log:debug("couchperuser daemon: starting link.", []),
+    Db_Name = ?l2b(config:get(
                      "couch_httpd_auth", "authentication_db", "_users")),
-    ok = watch_config_changes(),
-    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [self(), Db_Name],
+    Server = self(),
+    ok = config:listen_for_changes(?MODULE, Server),
+    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, Db_Name],
                            [link, monitor]),
     {ok, #state{db_name=Db_Name,
                 changes_pid=Pid,
                 changes_ref=Ref}}.
 
-watch_config_changes() ->
-    Server = self(),
-    couch_config:register(
-      fun ("couch_httpd_auth", "authentication_db", _Value, _Persist) ->
-              gen_server:cast(Server, stop);
-          (_Section, _Key, _Value, _Persist) ->
-              ok
-      end).
+handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, State) ->
+   gen_server:cast(State, stop),
+   remove_handler;
+handle_config_change(_Section, _Key, _Value, _Persist, State) ->
+    {ok, State}.
+
+handle_config_terminate(_, stop, _) -> ok;
+handle_config_terminate(Self, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, Self)
+    end).
 
 admin_ctx() ->
     {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
@@ -44,7 +54,7 @@ admin_ctx() ->
 init_changes(Parent, Db_Name) ->
     {ok, Db} = couch_db:open_int(Db_Name, [admin_ctx(), sys_db]),
     FunAcc = {fun ?MODULE:change_filter/3, #filter{server=Parent}},
-    (couch_changes:handle_changes(
+    (couch_changes:handle_db_changes(
        #changes_args{feed="continuous", timeout=infinity},
        {json_req, null},
        Db))(FunAcc).
@@ -58,12 +68,8 @@ change_filter({change, {Doc}, _Prepend}, _ResType, Acc=#filter{}) ->
                     %% TODO: Let's not complicate this with GC for now!
                     Acc;
                 false ->
-                    {ok, Db} = ensure_user_db(User),
-                    try
-                        ensure_security(User, Db)
-                    after
-                        couch_db:close(Db)
-                    end,
+                    UserDb = ensure_user_db(User),
+                    ensure_security(User, UserDb),
                     Acc
             end;
         _ ->
@@ -78,13 +84,13 @@ terminate(_Reason, _State) ->
     ok.
 
 ensure_user_db(User) ->
-    User_Db = user_db_name(User),
-    case couch_db:open_int(User_Db, [admin_ctx(), nologifmissing]) of
-        Ok={ok, _Db} ->
-            Ok;
-        _Err ->
-            couch_db:create(User_Db, [admin_ctx()])
-    end.
+    UserDb = user_db_name(User),
+    try
+        fabric_db_info:go(UserDb)
+    catch error:database_does_not_exist ->
+        fabric_db_create:go(UserDb, [admin_ctx()])
+    end,
+    UserDb.
 
 add_user(User, Prop, {Modified, SecProps}) ->
     {PropValue} = couch_util:get_value(Prop, SecProps, {[]}),
@@ -102,8 +108,11 @@ add_user(User, Prop, {Modified, SecProps}) ->
                    {<<"names">>, [User | Names]})}})}
     end.
 
-ensure_security(User, Db) ->
-    {SecProps} = couch_db:get_security(Db),
+ensure_security(User, UserDb) ->
+    {ok, Shards} = fabric_db_meta:get_all_security(UserDb, [admin_ctx()]),
+    % We assume that all shards have the same security object, and
+    % therefore just pick the first one.
+    {_ShardInfo, {SecProps}} = hd(Shards),
     case lists:foldl(
            fun (Prop, SAcc) -> add_user(User, Prop, SAcc) end,
            {false, SecProps},
@@ -111,7 +120,7 @@ ensure_security(User, Db) ->
         {false, _} ->
             ok;
         {true, SecProps1} ->
-            couch_db:set_security(Db, {SecProps1})
+            fabric_db_meta:set_security(UserDb, {SecProps1}, [admin_ctx()])
     end.
 
 user_db_name(User) ->


[05/15] couchdb-peruser git commit: Remove obsolete installation instructions

Posted by kl...@apache.org.
Remove obsolete installation instructions


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/2fa347cc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/2fa347cc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/2fa347cc

Branch: refs/heads/master
Commit: 2fa347cc7d5bdd56a04b3b0cf615cc28c93879a8
Parents: 3d4942b
Author: Klaus Trainer <kl...@posteo.de>
Authored: Wed Apr 29 20:11:58 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Wed Apr 29 20:21:01 2015 +0200

----------------------------------------------------------------------
 README.md | 26 --------------------------
 1 file changed, 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/2fa347cc/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 5383af1..caacb75 100644
--- a/README.md
+++ b/README.md
@@ -19,29 +19,3 @@ correctly implement in just about any language, especially JavaScript
 and Erlang. Other encodings would be possible, but would require
 additional client and server-side code to support that encoding. This
 is the simplest scheme that is obviously correct.
-
-Installation
-----
-
-Install any dependencies. `couchperuser` requires `rebar`, e.g.
-
-    $ brew install rebar
-
-Ensure the `plugins` directory exists, e.g.
-
-    $ mkdir /usr/local/Cellar/couchdb/1.6.0_1/lib/couchdb/plugins
-
-Clone (download) the repo:
-
-    $ git clone https://github.com/etrepum/couchperuser.git
-
-Move the plugin files:
-
-    $ mv couchperuser /usr/local/Cellar/couchdb/1.6.0_1/lib/couchdb/plugins
-
-Build the plugin files:
-
-    $ cd /usr/local/Cellar/couchdb/1.6.0_1/lib/couchdb/plugins/couchperuser
-    $ make
-
-Restart couchdb


[07/15] couchdb-peruser git commit: Use macro for userdb prefix

Posted by kl...@apache.org.
Use macro for userdb prefix


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/cf274f08
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/cf274f08
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/cf274f08

Branch: refs/heads/master
Commit: cf274f08d10f3bab001d5a6bc550908d5fc3b242
Parents: e524b1e
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 12:21:38 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 12:28:34 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/cf274f08/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index 23d83d8..9eff36c 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -16,6 +16,8 @@
 
 -include_lib("couch/include/couch_db.hrl").
 
+-define(USERDB_PREFIX, "userdb-").
+
 % gen_server callbacks
 -export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2,
          terminate/2, code_change/3]).
@@ -137,7 +139,7 @@ ensure_security(User, UserDb) ->
 
 user_db_name(User) ->
     HexUser = list_to_binary([integer_to_list(X, 16) || <<X>> <= User]),
-    <<"userdb-", HexUser/binary>>.
+    <<?USERDB_PREFIX, HexUser/binary>>.
 
 handle_call(_Msg, _From, State) ->
     {reply, error, State}.


[04/15] couchdb-peruser git commit: Remove obsolete files

Posted by kl...@apache.org.
Remove obsolete files

The existing build system, the configuration, as well as the end-to-end
test don't work with current CouchDB master anymore.  It's easier to
remove the associated files and restart from scratch.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/3d4942b9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/3d4942b9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/3d4942b9

Branch: refs/heads/master
Commit: 3d4942b9826f057c7e2743219340f66918b3eddc
Parents: 6c6a10e
Author: Klaus Trainer <kl...@posteo.de>
Authored: Wed Apr 29 20:08:06 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Wed Apr 29 20:20:14 2015 +0200

----------------------------------------------------------------------
 Makefile                        |  22 ------
 end-to-end-test.sh              | 143 -----------------------------------
 priv/default.d/couchperuser.ini |   2 -
 rebar.config                    |   5 --
 rebar.config.script             |  27 -------
 5 files changed, 199 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/3d4942b9/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 8dcaf66..0000000
--- a/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-NAME=couchperuser
-ERL=$(shell couch-config --erl-bin)
-ERLANG_VERSION=$(shell couch-config --erlang-version)
-COUCHDB_VERSION=$(shell couch-config --couch-version | sed 's/\+.*//')
-VERSION=1.0.1
-PLUGIN_DIRS=ebin priv
-PLUGIN_VERSION_SLUG=$(NAME)-$(VERSION)-$(ERLANG_VERSION)-$(COUCHDB_VERSION)
-PLUGIN_DIST=$(PLUGIN_VERSION_SLUG)
-
-all: compile
-
-compile:
-	rebar compile
-
-test:
-	./end-to-end-test.sh
-
-plugin: compile
-	mkdir -p $(PLUGIN_DIST)
-	cp -r $(PLUGIN_DIRS) $(PLUGIN_DIST)
-	tar czf $(PLUGIN_VERSION_SLUG).tar.gz $(PLUGIN_DIST)
-	@$(ERL) -eval 'File = "$(PLUGIN_VERSION_SLUG).tar.gz", {ok, Data} = file:read_file(File),io:format("~s: ~s~n", [File, base64:encode(crypto:sha(Data))]),halt()' -noshell

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/3d4942b9/end-to-end-test.sh
----------------------------------------------------------------------
diff --git a/end-to-end-test.sh b/end-to-end-test.sh
deleted file mode 100755
index e752b00..0000000
--- a/end-to-end-test.sh
+++ /dev/null
@@ -1,143 +0,0 @@
-#!/bin/bash
-set -e
-# Send SIGTERM to process group on exit, ensures background tasks die
-# if script exits
-cleanup () {
-    kill -TERM 0
-    wait
-}
-HERE=$(pwd)
-PLUGIN="couchperuser"
-COUCHDB_SRC="${HERE}/.eunit/couchdb"
-COUCHDB_VER="1.6.1"
-COUCHDB_REL="apache-couchdb-${COUCHDB_VER}"
-COUCHDB_URL="http://apache.osuosl.org/couchdb/source/${COUCHDB_VER}/${COUCHDB_REL}.tar.gz"
-COUCHDB_PREFIX="${COUCHDB_SRC}/${COUCHDB_REL}-build"
-COUCHDB_PLUGINS="${COUCHDB_PREFIX}/lib/couchdb/plugins"
-COUCHDB_DATA="${COUCHDB_PREFIX}/var/lib/couchdb"
-couch () {
-    echo "http://$1:$2@127.0.0.1:5985$3"
-}
-if [ ! -d "${COUCHDB_SRC}" ]; then
-    echo "Downloading and unpacking ${COUCHDB_PREFIX}"
-    mkdir -p "${COUCHDB_SRC}"
-    pushd "${COUCHDB_SRC}"
-    curl -f "${COUCHDB_URL}" | tar zxf -
-    popd
-fi
-if [ ! -e "${COUCHDB_PREFIX}/bin/couchdb" ]; then
-    echo "Compiling ${COUCHDB_PREFIX}"
-    pushd "${COUCHDB_SRC}/${COUCHDB_REL}"
-    ./configure --prefix="${COUCHDB_PREFIX}"
-    make
-    make install
-    popd
-fi
-if [ ! -d "${COUCHDB_PLUGINS}/${PLUGIN}" ]; then
-    echo "Symlinking plugin dir"
-    if [ ! -d "${COUCHDB_PLUGINS}" ]; then
-        mkdir -p "${COUCHDB_PLUGINS}"
-    fi
-    ln -sf "${HERE}" "${COUCHDB_PLUGINS}/${PLUGIN}"
-fi
-PATH="${COUCHDB_PREFIX}/bin:${PATH}"
-rebar compile
-if [ -d "${COUCHDB_DATA}" ]; then
-    echo "Removing existing data files"
-    rm -rf "${COUCHDB_DATA}"
-fi
-echo "Writing local.ini"
-cat <<EOF > "${COUCHDB_PREFIX}/etc/couchdb/local.ini"
-[couchdb]
-uuid = 92a5cfcd7c8ad3a05b225e2fa8aba48f
-[httpd]
-port = 5985
-bind_address = 127.0.0.1
-[couch_httpd_auth]
-secret = d8c211410a5fb33d2458aba4b7bb593c
-[admins]
-; admin : password
-admin = -pbkdf2-341d6b96564af2f7a1a88fada73dbcd6ab7e061e,8aa4052c63662a4bf8cf575891513595,10
-EOF
-couchdb &
-trap 'cleanup' SIGINT SIGTERM EXIT
-while ! (curl -f -s "$(couch)" 2>&1 >/dev/null); do
-    sleep 0.1
-done
-secret_json () {
-    echo "{\"secret\":\"$1\"}"
-}
-to_hex () {
-    printf "%s" "$1" | xxd -ps
-}
-userdb () {
-    echo "/userdb-$(to_hex "$1")$2"
-}
-put_json () {
-    curl -f -s \
-         -HContent-Type:application/json \
-         -XPUT "$1" \
-         --data-binary "$2"
-}
-get_json () {
-    curl -f -s "$1"
-}
-create_user () {
-    put_json \
-        "$(couch "" "" "/_users/org.couchdb.user:$1")" \
-        "{\"_id\": \"org.couchdb.user:$1\",\"name\": \"$1\",\"roles\": [],\"type\": \"user\",\"password\": \"password\"}" \
-        >/dev/null
-}
-fail () {
-    printf "FAIL: %s\n" "$(printf "$@")" 1>&2
-    exit 1
-}
-create_user eve
-for user in alice bob; do
-    # Create users with no authentication
-    create_user "${user}"
-    # Expect database to exist, but give it some time to trigger the change
-    for x in $(seq 10); do
-        if ! (get_json "$(couch "${user}" "password" "$(userdb "${user}")")" > /dev/null); then
-            if [ "$x" -ge "10" ]; then
-                fail "Expected create of user %s to create db %s" "${user}" "$(userdb "{user}")"
-            else
-                sleep 0.2
-            fi
-        else
-            break
-        fi
-    done
-    # Write doc with correct authentication
-    if ! (put_json \
-        "$(couch "${user}" "password" $(userdb "${user}" "/secret"))" \
-        "$(secret_json "${user}")" \
-        >/dev/null); then
-        fail "User %s could not PUT %s" "${user}" "$(userdb "${user}" "/secret")"
-    fi
-    # Read doc with correct authentication
-    if ! (get_json "$(couch "${user}" "password" $(userdb "${user}" "/secret"))" >/dev/null); then
-        fail "User %s could not GET %s" "${user}" "$(userdb "${user}" "/secret")"
-    fi
-    # Try to read doc without authentication
-    if (get_json "$(couch "" "" $(userdb "${user}" "/secret"))" >/dev/null); then
-        fail "Expected unauthenticated read for %s database %s to fail" "${user}" "$(userdb "${user}" "/secret")"
-    fi
-    # Try to read doc with incorrect authentication
-    if (get_json "$(couch "eve" "password" $(userdb "${user}" "/secret"))" >/dev/null); then
-        fail "Expected %s read for %s database %s to fail" "eve" "${user}" "$(userdb "${user}" "/secret")"
-    fi
-    # Try to write doc without authentication
-    if (put_json "$(couch "" "" $(userdb "${user}" "/notsecret"))" "{\"secret\":\"oops\"}" >/dev/null); then
-        fail "Expected unauthenticated write for %s database %s to fail" "${user}" $(userdb "${user}" "/notsecret")
-    fi
-    # Try to write doc with incorrect authentication
-    if (put_json "$(couch "eve" "password" $(userdb "${user}" "/notsecret"))" "{\"secret\":\"oops\"}" >/dev/null); then
-        fail "Expected %s write for %s database %s to fail" "eve" "${user}" $(userdb "${user}" "/notsecret")
-    fi
-done
-trap - SIGINT SIGTERM EXIT
-for job in $(jobs -p); do
-    kill -SIGTERM $job
-done
-wait

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/3d4942b9/priv/default.d/couchperuser.ini
----------------------------------------------------------------------
diff --git a/priv/default.d/couchperuser.ini b/priv/default.d/couchperuser.ini
deleted file mode 100644
index 753d725..0000000
--- a/priv/default.d/couchperuser.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[daemons]
-couchperuser={couchperuser, start_link, []}

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/3d4942b9/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
deleted file mode 100644
index ed84264..0000000
--- a/rebar.config
+++ /dev/null
@@ -1,5 +0,0 @@
-%% -*- mode: erlang -*-
-{erl_opts, [warnings_as_errors]}.
-{cover_enabled, true}.
-{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
-{clean_files, ["*.eunit", "ebin/*.beam"]}.

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/3d4942b9/rebar.config.script
----------------------------------------------------------------------
diff --git a/rebar.config.script b/rebar.config.script
deleted file mode 100644
index 1565588..0000000
--- a/rebar.config.script
+++ /dev/null
@@ -1,27 +0,0 @@
-%% -*- mode: erlang -*-
-%%
-%% This doesn't change CONFIG. If couch isn't accessible to the code server,
-%% it adds paths from couch-config. This is equivalent to:
-%%
-%%   ERL_LIBS=$(couch-config --erl-libs-dir):$ERL_LIBS rebar compile
-%%
-case code:which(couch) of
-    non_existing ->
-        try
-            Cfg = os:cmd("couch-config --erl-libs-dir"),
-            [LibDir] = string:tokens(Cfg, "\n"),
-            true = filelib:is_dir(LibDir),
-            code:add_pathsa(
-              filelib:wildcard(filename:join([LibDir, "*", "ebin"]))),
-            false = (code:which(couch) =:= non_existing)
-        catch _Err:_What ->
-                io:format(
-                  "CONFIG ERROR:\n"
-                  "Failed to run couch-config --erl-libs-dir\n"
-                  "Ensure that couch-config is on the PATH, or set ERL_LIBS "
-                  "appropriately\n\n")
-        end;
-    _ ->
-        ok
-end,
-CONFIG.


[10/15] couchdb-peruser git commit: No need to register the `gen_server`

Posted by kl...@apache.org.
No need to register the `gen_server`


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/0dfee37c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/0dfee37c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/0dfee37c

Branch: refs/heads/master
Commit: 0dfee37c03b37f8c90c96822526e9e16a49cff0f
Parents: 50c153a
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 17:49:18 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 17:49:18 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/0dfee37c/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index f6cd59a..bdcf9b6 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -27,15 +27,13 @@
 
 -export([init_changes/2, change_filter/3]).
 
-%% Note that this doesn't actually depend on having a registered name
--define(NAME, ?MODULE).
 %% db_name and changes_pid are useful information to have, but unused
 -record(state, {db_name, changes_pid, changes_ref}).
 %% the entire filter state is currently unused, but may be useful later
 -record(filter, {server}).
 
 start_link() ->
-    gen_server:start_link({local, ?NAME}, ?MODULE, [], []).
+    gen_server:start_link(?MODULE, [], []).
 
 init([]) ->
     couch_log:debug("couchdb_peruser daemon: starting link.", []),


[11/15] couchdb-peruser git commit: Handle `couchdb_peruser` config changes

Posted by kl...@apache.org.
Handle `couchdb_peruser` config changes


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/59605188
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/59605188
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/59605188

Branch: refs/heads/master
Commit: 59605188af5ec4d37b4ef6a17923b5cfa15c5c82
Parents: 0dfee37
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 17:51:06 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 17:51:06 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/59605188/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index bdcf9b6..2abb56c 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -50,6 +50,9 @@ init([]) ->
 handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, State) ->
    gen_server:cast(State, stop),
    remove_handler;
+handle_config_change("couchdb_peruser", _Key, _Value, _Persist, State) ->
+   gen_server:cast(State, stop),
+   remove_handler;
 handle_config_change(_Section, _Key, _Value, _Persist, State) ->
     {ok, State}.
 


[03/15] couchdb-peruser git commit: Reflect change to Apache License, Version 2.0

Posted by kl...@apache.org.
Reflect change to Apache License, Version 2.0

See http://mail-archives.apache.org/mod_mbox/couchdb-dev/201503.mbox/%3CCAJ1bcfFJfP=v3VLsZJNDobAv7gNgP82S=XeEgU2rO50tahNDBg@mail.gmail.com%3E
and https://github.com/etrepum/couchperuser/issues/15


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/6c6a10ee
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/6c6a10ee
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/6c6a10ee

Branch: refs/heads/master
Commit: 6c6a10eed568873af13c08d4833e9da108c61aae
Parents: 0589d7b
Author: Klaus Trainer <kl...@posteo.de>
Authored: Wed Apr 29 20:04:15 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Wed Apr 29 20:04:15 2015 +0200

----------------------------------------------------------------------
 LICENSE                  | 221 ++++++++++++++++++++++++++++++++++++++----
 src/couchperuser.app.src |  13 ++-
 src/couchperuser.erl     |  12 +++
 3 files changed, 226 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/6c6a10ee/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index c0fa6dc..d645695 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,19 +1,202 @@
-Copyright (C) 2013 by Bob Ippolito <bo...@redivi.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/6c6a10ee/src/couchperuser.app.src
----------------------------------------------------------------------
diff --git a/src/couchperuser.app.src b/src/couchperuser.app.src
index 14a3aa1..703f716 100644
--- a/src/couchperuser.app.src
+++ b/src/couchperuser.app.src
@@ -1,4 +1,15 @@
-%% -*- mode: erlang -*-
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
 {application, couchperuser, [
     {description, "couchperuser - maintains per-user databases in CouchDB"},
     {vsn, "1.1.0"},

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/6c6a10ee/src/couchperuser.erl
----------------------------------------------------------------------
diff --git a/src/couchperuser.erl b/src/couchperuser.erl
index b7a1d5c..16e9a78 100644
--- a/src/couchperuser.erl
+++ b/src/couchperuser.erl
@@ -1,3 +1,15 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
 -module(couchperuser).
 -behaviour(gen_server).
 -behaviour(config_listener).


[14/15] couchdb-peruser git commit: Refactor and make it fully 2.0-ready :)

Posted by kl...@apache.org.
Refactor and make it fully 2.0-ready :)


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/7bfd9835
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/7bfd9835
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/7bfd9835

Branch: refs/heads/master
Commit: 7bfd98351626762a73a70bd6c621d45d29190975
Parents: 88a3146
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 21:37:19 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 21:44:57 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 95 ++++++++++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/7bfd9835/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index 8216d8c..e585e11 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -25,79 +25,92 @@
 % config_listener callbacks
 -export([handle_config_change/5, handle_config_terminate/3]).
 
--export([init_changes/2, change_filter/3]).
+-export([init_changes_handler/1, changes_handler/3]).
 
-%% db_name and changes_pid are useful information to have, but unused
--record(state, {db_name, changes_pid, changes_ref}).
-%% the entire filter state is currently unused, but may be useful later
--record(filter, {server}).
+-record(state, {parent, db_name, delete_dbs, changes_pid, changes_ref}).
 
 start_link() ->
     gen_server:start_link(?MODULE, [], []).
 
 init([]) ->
-    couch_log:debug("couchdb_peruser daemon: starting link.", []),
-    DbName = ?l2b(config:get(
-                     "couch_httpd_auth", "authentication_db", "_users")),
     Server = self(),
     ok = config:listen_for_changes(?MODULE, Server),
-    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, DbName],
-                           [link, monitor]),
-    {ok, #state{db_name=DbName,
-                changes_pid=Pid,
-                changes_ref=Ref}}.
-
-handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, State) ->
-   gen_server:cast(State, stop),
-   remove_handler;
-handle_config_change("couchdb_peruser", _Key, _Value, _Persist, State) ->
-   gen_server:cast(State, stop),
-   remove_handler;
-handle_config_change(_Section, _Key, _Value, _Persist, State) ->
-    {ok, State}.
+    case config:get_boolean("couchdb_peruser", "enable", false) of
+    false ->
+        {ok, #state{parent = Server}};
+    true ->
+        DbName = ?l2b(config:get(
+                         "couch_httpd_auth", "authentication_db", "_users")),
+        DeleteDbs = config:get_boolean("couchdb_peruser", "delete_dbs", false),
+        State = #state{parent = Server,
+                       db_name = DbName,
+                       delete_dbs = DeleteDbs},
+        {Pid, Ref} = spawn_opt(
+            ?MODULE, init_changes_handler, [State], [link, monitor]),
+        {ok, State#state{changes_pid=Pid, changes_ref=Ref}}
+    end.
+
+handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, Server) ->
+    gen_server:cast(Server, stop),
+    remove_handler;
+handle_config_change("couchdb_peruser", _Key, _Value, _Persist, Server) ->
+    gen_server:cast(Server, stop),
+    remove_handler;
+handle_config_change(_Section, _Key, _Value, _Persist, Server) ->
+    {ok, Server}.
 
-handle_config_terminate(_, stop, _) -> ok;
-handle_config_terminate(Self, _, _) ->
-    spawn(fun() ->
-        timer:sleep(5000),
-        config:listen_for_changes(?MODULE, Self)
-    end).
+handle_config_terminate(_Self, Reason, _Server) ->
+    {stop, Reason}.
 
 admin_ctx() ->
     {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
 
-init_changes(Parent, DbName) ->
-    {ok, Db} = couch_db:open_int(DbName, [admin_ctx(), sys_db]),
-    FunAcc = {fun ?MODULE:change_filter/3, #filter{server=Parent}},
+init_changes_handler(State) ->
+    {ok, Db} = couch_db:open_int(State#state.db_name, [admin_ctx(), sys_db]),
+    FunAcc = {fun ?MODULE:changes_handler/3, State},
     (couch_changes:handle_db_changes(
        #changes_args{feed="continuous", timeout=infinity},
        {json_req, null},
        Db))(FunAcc).
 
-change_filter({change, {Doc}, _Prepend}, _ResType, Acc=#filter{}) ->
+changes_handler({change, {Doc}, _Prepend}, _ResType, State=#state{}) ->
     Deleted = couch_util:get_value(<<"deleted">>, Doc, false),
     case lists:keyfind(<<"id">>, 1, Doc) of
         {_Key, <<"org.couchdb.user:", User/binary>>} ->
             case Deleted of
                 true ->
-                    %% TODO: Let's not complicate this with GC for now!
-                    Acc;
+                    case State#state.delete_dbs of
+                    true ->
+                        _UserDb = delete_user_db(User),
+                        State;
+                    false ->
+                        State
+                    end;
                 false ->
                     UserDb = ensure_user_db(User),
                     ensure_security(User, UserDb),
-                    Acc
+                    State
             end;
         _ ->
-            Acc
+            State
     end;
-change_filter(_Event, _ResType, Acc) ->
-    Acc.
+changes_handler(_Event, _ResType, State) ->
+    State.
 
 terminate(_Reason, _State) ->
     %% Everything should be linked or monitored, let nature
     %% take its course.
     ok.
 
+delete_user_db(User) ->
+    UserDb = user_db_name(User),
+    try
+        fabric_db_delete:go(UserDb, [admin_ctx()])
+    catch error:database_does_not_exist ->
+        ok
+    end,
+    UserDb.
+
 ensure_user_db(User) ->
     UserDb = user_db_name(User),
     try
@@ -127,7 +140,9 @@ ensure_security(User, UserDb) ->
     {ok, Shards} = fabric_db_meta:get_all_security(UserDb, [admin_ctx()]),
     {_ShardInfo, {SecProps}} = hd(Shards),
     % assert that shards have the same security object
-    true = lists:all(fun(Shard) -> {_, {SecProps}} =:= Shard end, Shards),
+    true = lists:all(fun({_, {SecProps1}}) ->
+        SecProps =:= SecProps1
+    end, Shards),
     case lists:foldl(
            fun(Prop, SAcc) -> add_user(User, Prop, SAcc) end,
            {false, SecProps},
@@ -147,6 +162,8 @@ handle_call(_Msg, _From, State) ->
     {reply, error, State}.
 
 handle_cast(stop, State) ->
+    % we don't want to have multiple changes handler at the same time
+    exit(State#state.changes_pid, kill),
     {stop, normal, State};
 handle_cast(_Msg, State) ->
     {noreply, State}.


[06/15] couchdb-peruser git commit: Rename to `couchdb_peruser`

Posted by kl...@apache.org.
Rename to `couchdb_peruser`


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/e524b1e7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/e524b1e7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/e524b1e7

Branch: refs/heads/master
Commit: e524b1e798dec59ae78aa96eba05e3c6891e4579
Parents: 2fa347c
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 12:16:58 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 12:28:29 2015 +0200

----------------------------------------------------------------------
 README.md                   |   6 +-
 src/couchdb_peruser.app.src |  20 +++++
 src/couchdb_peruser.erl     | 156 +++++++++++++++++++++++++++++++++++++++
 src/couchperuser.app.src    |  20 -----
 src/couchperuser.erl        | 156 ---------------------------------------
 5 files changed, 179 insertions(+), 179 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/e524b1e7/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index caacb75..7b2a4eb 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
-couchperuser
-============
+couchdb_peruser
+===============
 
-couchperuser is a CouchDB daemon that ensures that a private per-user
+couchdb_peruser is a CouchDB daemon that ensures that a private per-user
 database exists for each document in _users. These databases are
 writable only by the corresponding user.
 

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/e524b1e7/src/couchdb_peruser.app.src
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.app.src b/src/couchdb_peruser.app.src
new file mode 100644
index 0000000..9255068
--- /dev/null
+++ b/src/couchdb_peruser.app.src
@@ -0,0 +1,20 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{application, couchdb_peruser, [
+    {description, "couchdb_peruser - maintains per-user databases in CouchDB"},
+    {vsn, "1.1.0"},
+    {modules, []},
+    {registered, [couchdb_peruser]},
+    {applications, [kernel, stdlib]},
+    {env, []}
+]}.

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/e524b1e7/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
new file mode 100644
index 0000000..23d83d8
--- /dev/null
+++ b/src/couchdb_peruser.erl
@@ -0,0 +1,156 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couchdb_peruser).
+-behaviour(gen_server).
+-behaviour(config_listener).
+
+-include_lib("couch/include/couch_db.hrl").
+
+% gen_server callbacks
+-export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2,
+         terminate/2, code_change/3]).
+
+% config_listener callbacks
+-export([handle_config_change/5, handle_config_terminate/3]).
+
+-export([init_changes/2, change_filter/3]).
+
+%% Note that this doesn't actually depend on having a registered name
+-define(NAME, ?MODULE).
+%% db_name and changes_pid are useful information to have, but unused
+-record(state, {db_name, changes_pid, changes_ref}).
+%% the entire filter state is currently unused, but may be useful later
+-record(filter, {server}).
+
+start_link() ->
+    gen_server:start_link({local, ?NAME}, ?MODULE, [], []).
+
+init([]) ->
+    couch_log:debug("couchdb_peruser daemon: starting link.", []),
+    Db_Name = ?l2b(config:get(
+                     "couch_httpd_auth", "authentication_db", "_users")),
+    Server = self(),
+    ok = config:listen_for_changes(?MODULE, Server),
+    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, Db_Name],
+                           [link, monitor]),
+    {ok, #state{db_name=Db_Name,
+                changes_pid=Pid,
+                changes_ref=Ref}}.
+
+handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, State) ->
+   gen_server:cast(State, stop),
+   remove_handler;
+handle_config_change(_Section, _Key, _Value, _Persist, State) ->
+    {ok, State}.
+
+handle_config_terminate(_, stop, _) -> ok;
+handle_config_terminate(Self, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, Self)
+    end).
+
+admin_ctx() ->
+    {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
+
+init_changes(Parent, Db_Name) ->
+    {ok, Db} = couch_db:open_int(Db_Name, [admin_ctx(), sys_db]),
+    FunAcc = {fun ?MODULE:change_filter/3, #filter{server=Parent}},
+    (couch_changes:handle_db_changes(
+       #changes_args{feed="continuous", timeout=infinity},
+       {json_req, null},
+       Db))(FunAcc).
+
+change_filter({change, {Doc}, _Prepend}, _ResType, Acc=#filter{}) ->
+    Deleted = couch_util:get_value(<<"deleted">>, Doc, false),
+    case lists:keyfind(<<"id">>, 1, Doc) of
+        {_Key, <<"org.couchdb.user:", User/binary>>} ->
+            case Deleted of
+                true ->
+                    %% TODO: Let's not complicate this with GC for now!
+                    Acc;
+                false ->
+                    UserDb = ensure_user_db(User),
+                    ensure_security(User, UserDb),
+                    Acc
+            end;
+        _ ->
+            Acc
+    end;
+change_filter(_Event, _ResType, Acc) ->
+    Acc.
+
+terminate(_Reason, _State) ->
+    %% Everything should be linked or monitored, let nature
+    %% take its course.
+    ok.
+
+ensure_user_db(User) ->
+    UserDb = user_db_name(User),
+    try
+        fabric_db_info:go(UserDb)
+    catch error:database_does_not_exist ->
+        fabric_db_create:go(UserDb, [admin_ctx()])
+    end,
+    UserDb.
+
+add_user(User, Prop, {Modified, SecProps}) ->
+    {PropValue} = couch_util:get_value(Prop, SecProps, {[]}),
+    Names = couch_util:get_value(<<"names">>, PropValue, []),
+    case lists:member(User, Names) of
+        true ->
+            {Modified, SecProps};
+        false ->
+            {true,
+             lists:keystore(
+               Prop, 1, SecProps,
+               {Prop,
+                {lists:keystore(
+                   <<"names">>, 1, PropValue,
+                   {<<"names">>, [User | Names]})}})}
+    end.
+
+ensure_security(User, UserDb) ->
+    {ok, Shards} = fabric_db_meta:get_all_security(UserDb, [admin_ctx()]),
+    % We assume that all shards have the same security object, and
+    % therefore just pick the first one.
+    {_ShardInfo, {SecProps}} = hd(Shards),
+    case lists:foldl(
+           fun (Prop, SAcc) -> add_user(User, Prop, SAcc) end,
+           {false, SecProps},
+           [<<"admins">>, <<"members">>]) of
+        {false, _} ->
+            ok;
+        {true, SecProps1} ->
+            fabric_db_meta:set_security(UserDb, {SecProps1}, [admin_ctx()])
+    end.
+
+user_db_name(User) ->
+    HexUser = list_to_binary([integer_to_list(X, 16) || <<X>> <= User]),
+    <<"userdb-", HexUser/binary>>.
+
+handle_call(_Msg, _From, State) ->
+    {reply, error, State}.
+
+handle_cast(stop, State) ->
+    {stop, normal, State};
+handle_cast(_Msg, State) ->
+    {noreply, State}.
+
+handle_info({'DOWN', Ref, _, _, _Reason}, State=#state{changes_ref=Ref}) ->
+    {stop, normal, State};
+handle_info(_Msg, State) ->
+    {noreply, State}.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/e524b1e7/src/couchperuser.app.src
----------------------------------------------------------------------
diff --git a/src/couchperuser.app.src b/src/couchperuser.app.src
deleted file mode 100644
index 703f716..0000000
--- a/src/couchperuser.app.src
+++ /dev/null
@@ -1,20 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-{application, couchperuser, [
-    {description, "couchperuser - maintains per-user databases in CouchDB"},
-    {vsn, "1.1.0"},
-    {modules, []},
-    {registered, [couchperuser]},
-    {applications, [kernel, stdlib]},
-    {env, []}
-]}.

http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/e524b1e7/src/couchperuser.erl
----------------------------------------------------------------------
diff --git a/src/couchperuser.erl b/src/couchperuser.erl
deleted file mode 100644
index 16e9a78..0000000
--- a/src/couchperuser.erl
+++ /dev/null
@@ -1,156 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couchperuser).
--behaviour(gen_server).
--behaviour(config_listener).
-
--include_lib("couch/include/couch_db.hrl").
-
-% gen_server callbacks
--export([start_link/0, init/1, handle_call/3, handle_cast/2, handle_info/2,
-         terminate/2, code_change/3]).
-
-% config_listener callbacks
--export([handle_config_change/5, handle_config_terminate/3]).
-
--export([init_changes/2, change_filter/3]).
-
-%% Note that this doesn't actually depend on having a registered name
--define(NAME, ?MODULE).
-%% db_name and changes_pid are useful information to have, but unused
--record(state, {db_name, changes_pid, changes_ref}).
-%% the entire filter state is currently unused, but may be useful later
--record(filter, {server}).
-
-start_link() ->
-    gen_server:start_link({local, ?NAME}, ?MODULE, [], []).
-
-init([]) ->
-    couch_log:debug("couchperuser daemon: starting link.", []),
-    Db_Name = ?l2b(config:get(
-                     "couch_httpd_auth", "authentication_db", "_users")),
-    Server = self(),
-    ok = config:listen_for_changes(?MODULE, Server),
-    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, Db_Name],
-                           [link, monitor]),
-    {ok, #state{db_name=Db_Name,
-                changes_pid=Pid,
-                changes_ref=Ref}}.
-
-handle_config_change("couch_httpd_auth", "authentication_db", _Value, _Persist, State) ->
-   gen_server:cast(State, stop),
-   remove_handler;
-handle_config_change(_Section, _Key, _Value, _Persist, State) ->
-    {ok, State}.
-
-handle_config_terminate(_, stop, _) -> ok;
-handle_config_terminate(Self, _, _) ->
-    spawn(fun() ->
-        timer:sleep(5000),
-        config:listen_for_changes(?MODULE, Self)
-    end).
-
-admin_ctx() ->
-    {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-init_changes(Parent, Db_Name) ->
-    {ok, Db} = couch_db:open_int(Db_Name, [admin_ctx(), sys_db]),
-    FunAcc = {fun ?MODULE:change_filter/3, #filter{server=Parent}},
-    (couch_changes:handle_db_changes(
-       #changes_args{feed="continuous", timeout=infinity},
-       {json_req, null},
-       Db))(FunAcc).
-
-change_filter({change, {Doc}, _Prepend}, _ResType, Acc=#filter{}) ->
-    Deleted = couch_util:get_value(<<"deleted">>, Doc, false),
-    case lists:keyfind(<<"id">>, 1, Doc) of
-        {_Key, <<"org.couchdb.user:", User/binary>>} ->
-            case Deleted of
-                true ->
-                    %% TODO: Let's not complicate this with GC for now!
-                    Acc;
-                false ->
-                    UserDb = ensure_user_db(User),
-                    ensure_security(User, UserDb),
-                    Acc
-            end;
-        _ ->
-            Acc
-    end;
-change_filter(_Event, _ResType, Acc) ->
-    Acc.
-
-terminate(_Reason, _State) ->
-    %% Everything should be linked or monitored, let nature
-    %% take its course.
-    ok.
-
-ensure_user_db(User) ->
-    UserDb = user_db_name(User),
-    try
-        fabric_db_info:go(UserDb)
-    catch error:database_does_not_exist ->
-        fabric_db_create:go(UserDb, [admin_ctx()])
-    end,
-    UserDb.
-
-add_user(User, Prop, {Modified, SecProps}) ->
-    {PropValue} = couch_util:get_value(Prop, SecProps, {[]}),
-    Names = couch_util:get_value(<<"names">>, PropValue, []),
-    case lists:member(User, Names) of
-        true ->
-            {Modified, SecProps};
-        false ->
-            {true,
-             lists:keystore(
-               Prop, 1, SecProps,
-               {Prop,
-                {lists:keystore(
-                   <<"names">>, 1, PropValue,
-                   {<<"names">>, [User | Names]})}})}
-    end.
-
-ensure_security(User, UserDb) ->
-    {ok, Shards} = fabric_db_meta:get_all_security(UserDb, [admin_ctx()]),
-    % We assume that all shards have the same security object, and
-    % therefore just pick the first one.
-    {_ShardInfo, {SecProps}} = hd(Shards),
-    case lists:foldl(
-           fun (Prop, SAcc) -> add_user(User, Prop, SAcc) end,
-           {false, SecProps},
-           [<<"admins">>, <<"members">>]) of
-        {false, _} ->
-            ok;
-        {true, SecProps1} ->
-            fabric_db_meta:set_security(UserDb, {SecProps1}, [admin_ctx()])
-    end.
-
-user_db_name(User) ->
-    HexUser = list_to_binary([integer_to_list(X, 16) || <<X>> <= User]),
-    <<"userdb-", HexUser/binary>>.
-
-handle_call(_Msg, _From, State) ->
-    {reply, error, State}.
-
-handle_cast(stop, State) ->
-    {stop, normal, State};
-handle_cast(_Msg, State) ->
-    {noreply, State}.
-
-handle_info({'DOWN', Ref, _, _, _Reason}, State=#state{changes_ref=Ref}) ->
-    {stop, normal, State};
-handle_info(_Msg, State) ->
-    {noreply, State}.
-
-code_change(_OldVsn, State, _Extra) ->
-    {ok, State}.


[15/15] couchdb-peruser git commit: Fix whitespace

Posted by kl...@apache.org.
Fix whitespace


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/bb95f4a2
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/bb95f4a2
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/bb95f4a2

Branch: refs/heads/master
Commit: bb95f4a2822238735f2f2898451975448c26dfc4
Parents: 7bfd983
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 21:44:25 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 21:45:34 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 60 ++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/bb95f4a2/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index e585e11..34b0027 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -69,30 +69,30 @@ init_changes_handler(State) ->
     {ok, Db} = couch_db:open_int(State#state.db_name, [admin_ctx(), sys_db]),
     FunAcc = {fun ?MODULE:changes_handler/3, State},
     (couch_changes:handle_db_changes(
-       #changes_args{feed="continuous", timeout=infinity},
-       {json_req, null},
-       Db))(FunAcc).
+         #changes_args{feed="continuous", timeout=infinity},
+         {json_req, null},
+         Db))(FunAcc).
 
 changes_handler({change, {Doc}, _Prepend}, _ResType, State=#state{}) ->
     Deleted = couch_util:get_value(<<"deleted">>, Doc, false),
     case lists:keyfind(<<"id">>, 1, Doc) of
-        {_Key, <<"org.couchdb.user:", User/binary>>} ->
-            case Deleted of
-                true ->
-                    case State#state.delete_dbs of
-                    true ->
-                        _UserDb = delete_user_db(User),
-                        State;
-                    false ->
-                        State
-                    end;
-                false ->
-                    UserDb = ensure_user_db(User),
-                    ensure_security(User, UserDb),
-                    State
+    {_Key, <<"org.couchdb.user:", User/binary>>} ->
+        case Deleted of
+        true ->
+            case State#state.delete_dbs of
+            true ->
+                _UserDb = delete_user_db(User),
+                State;
+            false ->
+                State
             end;
-        _ ->
+        false ->
+            UserDb = ensure_user_db(User),
+            ensure_security(User, UserDb),
             State
+        end;
+    _ ->
+        State
     end;
 changes_handler(_Event, _ResType, State) ->
     State.
@@ -124,14 +124,14 @@ add_user(User, Prop, {Modified, SecProps}) ->
     {PropValue} = couch_util:get_value(Prop, SecProps, {[]}),
     Names = couch_util:get_value(<<"names">>, PropValue, []),
     case lists:member(User, Names) of
-        true ->
-            {Modified, SecProps};
-        false ->
-            {true,
-             lists:keystore(
-               Prop, 1, SecProps,
-               {Prop,
-                {lists:keystore(
+    true ->
+        {Modified, SecProps};
+    false ->
+        {true,
+         lists:keystore(
+             Prop, 1, SecProps,
+             {Prop,
+              {lists:keystore(
                    <<"names">>, 1, PropValue,
                    {<<"names">>, [User | Names]})}})}
     end.
@@ -147,10 +147,10 @@ ensure_security(User, UserDb) ->
            fun(Prop, SAcc) -> add_user(User, Prop, SAcc) end,
            {false, SecProps},
            [<<"admins">>, <<"members">>]) of
-        {false, _} ->
-            ok;
-        {true, SecProps1} ->
-            fabric_db_meta:set_security(UserDb, {SecProps1}, [admin_ctx()])
+    {false, _} ->
+        ok;
+    {true, SecProps1} ->
+        fabric_db_meta:set_security(UserDb, {SecProps1}, [admin_ctx()])
     end.
 
 user_db_name(User) ->


[13/15] couchdb-peruser git commit: s/Db_Name/DbName/g

Posted by kl...@apache.org.
s/Db_Name/DbName/g


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/88a3146a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/88a3146a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/88a3146a

Branch: refs/heads/master
Commit: 88a3146a4a55ddaf268eab7411e79c65cfbaf24c
Parents: ac8094f
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 18:18:42 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 18:18:42 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/88a3146a/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index 370be31..8216d8c 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -37,13 +37,13 @@ start_link() ->
 
 init([]) ->
     couch_log:debug("couchdb_peruser daemon: starting link.", []),
-    Db_Name = ?l2b(config:get(
+    DbName = ?l2b(config:get(
                      "couch_httpd_auth", "authentication_db", "_users")),
     Server = self(),
     ok = config:listen_for_changes(?MODULE, Server),
-    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, Db_Name],
+    {Pid, Ref} = spawn_opt(?MODULE, init_changes, [Server, DbName],
                            [link, monitor]),
-    {ok, #state{db_name=Db_Name,
+    {ok, #state{db_name=DbName,
                 changes_pid=Pid,
                 changes_ref=Ref}}.
 
@@ -66,8 +66,8 @@ handle_config_terminate(Self, _, _) ->
 admin_ctx() ->
     {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
 
-init_changes(Parent, Db_Name) ->
-    {ok, Db} = couch_db:open_int(Db_Name, [admin_ctx(), sys_db]),
+init_changes(Parent, DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, [admin_ctx(), sys_db]),
     FunAcc = {fun ?MODULE:change_filter/3, #filter{server=Parent}},
     (couch_changes:handle_db_changes(
        #changes_args{feed="continuous", timeout=infinity},


[02/15] couchdb-peruser git commit: Don't unnecessarily depend on mochiweb

Posted by kl...@apache.org.
Don't unnecessarily depend on mochiweb


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/0589d7b9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/0589d7b9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/0589d7b9

Branch: refs/heads/master
Commit: 0589d7b94cbb94d4e2fb1f0430f52d14fdec6275
Parents: 8ccf57e
Author: Klaus Trainer <kl...@posteo.de>
Authored: Wed Mar 18 22:04:03 2015 +0100
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Wed Mar 18 22:04:03 2015 +0100

----------------------------------------------------------------------
 src/couchperuser.erl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/0589d7b9/src/couchperuser.erl
----------------------------------------------------------------------
diff --git a/src/couchperuser.erl b/src/couchperuser.erl
index 27a7489..b7a1d5c 100644
--- a/src/couchperuser.erl
+++ b/src/couchperuser.erl
@@ -124,7 +124,8 @@ ensure_security(User, UserDb) ->
     end.
 
 user_db_name(User) ->
-    <<"userdb-", (iolist_to_binary(mochihex:to_hex(User)))/binary>>.
+    HexUser = list_to_binary([integer_to_list(X, 16) || <<X>> <= User]),
+    <<"userdb-", HexUser/binary>>.
 
 handle_call(_Msg, _From, State) ->
     {reply, error, State}.


[08/15] couchdb-peruser git commit: Remove legacy information from README

Posted by kl...@apache.org.
Remove legacy information from README


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/70146b47
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/70146b47
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/70146b47

Branch: refs/heads/master
Commit: 70146b470e92805ba4b8ac46260e8fd903569f1a
Parents: cf274f0
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 13:00:08 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 13:00:08 2015 +0200

----------------------------------------------------------------------
 README.md | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/70146b47/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 7b2a4eb..4ada11c 100644
--- a/README.md
+++ b/README.md
@@ -3,10 +3,7 @@ couchdb_peruser
 
 couchdb_peruser is a CouchDB daemon that ensures that a private per-user
 database exists for each document in _users. These databases are
-writable only by the corresponding user.
-
-Currently this is very much purpose-built for CodeCosmos. Databases are
-in the form:
+writable only by the corresponding user. Databases are in the form:
 
   userdb-{hex encoded username}
 


[09/15] couchdb-peruser git commit: Fix `user_db_name/1`

Posted by kl...@apache.org.
Fix `user_db_name/1`

Alphabetic characters must be in lower case.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/50c153ac
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/50c153ac
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/50c153ac

Branch: refs/heads/master
Commit: 50c153ac17fdb8f212d6505141588c2215e8d3fd
Parents: 70146b4
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 17:45:04 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 17:45:04 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/50c153ac/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index 9eff36c..f6cd59a 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -138,7 +138,8 @@ ensure_security(User, UserDb) ->
     end.
 
 user_db_name(User) ->
-    HexUser = list_to_binary([integer_to_list(X, 16) || <<X>> <= User]),
+    HexUser = list_to_binary(
+        [string:to_lower(integer_to_list(X, 16)) || <<X>> <= User]),
     <<?USERDB_PREFIX, HexUser/binary>>.
 
 handle_call(_Msg, _From, State) ->


[12/15] couchdb-peruser git commit: Assert that shards have the same security object

Posted by kl...@apache.org.
Assert that shards have the same security object


Project: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/commit/ac8094fa
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/tree/ac8094fa
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-peruser/diff/ac8094fa

Branch: refs/heads/master
Commit: ac8094fa098a25726801f05480c172dc4c03188a
Parents: 5960518
Author: Klaus Trainer <kl...@posteo.de>
Authored: Mon Aug 10 18:01:50 2015 +0200
Committer: Klaus Trainer <kl...@posteo.de>
Committed: Mon Aug 10 18:04:04 2015 +0200

----------------------------------------------------------------------
 src/couchdb_peruser.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-peruser/blob/ac8094fa/src/couchdb_peruser.erl
----------------------------------------------------------------------
diff --git a/src/couchdb_peruser.erl b/src/couchdb_peruser.erl
index 2abb56c..370be31 100644
--- a/src/couchdb_peruser.erl
+++ b/src/couchdb_peruser.erl
@@ -125,11 +125,11 @@ add_user(User, Prop, {Modified, SecProps}) ->
 
 ensure_security(User, UserDb) ->
     {ok, Shards} = fabric_db_meta:get_all_security(UserDb, [admin_ctx()]),
-    % We assume that all shards have the same security object, and
-    % therefore just pick the first one.
     {_ShardInfo, {SecProps}} = hd(Shards),
+    % assert that shards have the same security object
+    true = lists:all(fun(Shard) -> {_, {SecProps}} =:= Shard end, Shards),
     case lists:foldl(
-           fun (Prop, SAcc) -> add_user(User, Prop, SAcc) end,
+           fun(Prop, SAcc) -> add_user(User, Prop, SAcc) end,
            {false, SecProps},
            [<<"admins">>, <<"members">>]) of
         {false, _} ->