couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject chttpd commit: updated refs/heads/2491-refactor-couch-httpd-auth to f9b549e
Date Thu, 04 Dec 2014 19:20:26 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/2491-refactor-couch-httpd-auth [created] f9b549e68


Update chttpd_auth_cache for new couch_auth_cache

This updates the interface to chttpd_auth_cache to match the new
callback API expected by couch_httpd_auth. Specifically this allows for
the upgraded user documents to be written back to the correct user
database.

COUCHDB-2491


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

Branch: refs/heads/2491-refactor-couch-httpd-auth
Commit: f9b549e68d40df01683867de22779d21fe0b90d0
Parents: b44515f
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Thu Dec 4 13:13:42 2014 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Thu Dec 4 13:19:18 2014 -0600

----------------------------------------------------------------------
 src/chttpd_auth_cache.erl | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f9b549e6/src/chttpd_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_auth_cache.erl b/src/chttpd_auth_cache.erl
index a78ab9e..a830aef 100644
--- a/src/chttpd_auth_cache.erl
+++ b/src/chttpd_auth_cache.erl
@@ -13,7 +13,7 @@
 -module(chttpd_auth_cache).
 -behaviour(gen_server).
 
--export([start_link/0, get_user_creds/1]).
+-export([start_link/0, get_user_creds/2, update_user_creds/3]).
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
 	 code_change/3]).
 -export([listen_for_changes/1, changes_callback/2]).
@@ -33,10 +33,10 @@
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
 
-get_user_creds(UserName) when is_list(UserName) ->
-    get_user_creds(?l2b(UserName));
-get_user_creds(UserName) when is_binary(UserName) ->
-    case couch_auth_cache:get_admin(UserName) of
+get_user_creds(Req, UserName) when is_list(UserName) ->
+    get_user_creds(Req, ?l2b(UserName));
+get_user_creds(_Req, UserName) when is_binary(UserName) ->
+    Resp = case couch_auth_cache:get_admin(UserName) of
     nil ->
         get_from_cache(UserName);
     Props ->
@@ -47,6 +47,26 @@ get_user_creds(UserName) when is_binary(UserName) ->
             couch_auth_cache:add_roles(Props,
 	        couch_util:get_value(<<"roles">>, UserProps))
         end
+    end,
+    case Resp of
+        nil -> nil;
+        _ -> {ok, Resp, nil}
+    end.
+
+update_user_creds(_Req, UserDoc, _Ctx) ->
+    {_, Ref} = spawn_monitor(fun() ->
+        case fabric:update_doc(dbname(), UserDoc, []) of
+            {ok, _} ->
+                exit(ok);
+            Else ->
+                exit(Else)
+        end
+    end),
+    receive
+        {'DOWN', Ref, _, _, ok} ->
+            ok;
+        {'DOWN', Ref, _, _, Else} ->
+            Else
     end.
 
 get_from_cache(UserName) ->


Mime
View raw message