couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewall...@apache.org
Subject ddoc-cache commit: updated refs/heads/2452-users-db-security-on-clustered-interface to 6ff1520
Date Tue, 11 Nov 2014 00:24:56 GMT
Repository: couchdb-ddoc-cache
Updated Branches:
  refs/heads/2452-users-db-security-on-clustered-interface [created] 6ff152058


Teach ddoc_cache about user context

This commit teaches ddoc_cache to accept a user_ctx which is
passed through to the call to open the design doc. This is required
so that admins can view design docs in the authentication DB when
it is on the clustered interface.

COUCHDB-2452


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

Branch: refs/heads/2452-users-db-security-on-clustered-interface
Commit: 6ff15205870c514ec5a885cf995fb772abb2a80a
Parents: 4ffc6b0
Author: Mike Wallace <mikewallace@apache.org>
Authored: Mon Nov 10 23:51:06 2014 +0000
Committer: Mike Wallace <mikewallace@apache.org>
Committed: Mon Nov 10 23:51:06 2014 +0000

----------------------------------------------------------------------
 src/ddoc_cache.erl        | 24 ++++++++++++++++--------
 src/ddoc_cache_opener.erl | 27 +++++++++++++++++----------
 2 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/6ff15205/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index 6aa3efd..dbde33f 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -24,7 +24,8 @@
     evict/2,
 
     %% deprecated
-    open/2
+    open/2,
+    open/3
 ]).
 
 start() ->
@@ -34,19 +35,21 @@ stop() ->
     application:stop(ddoc_cache).
 
 open_doc(DbName, DocId) ->
-    Key = {DbName, DocId, '_'},
+    open_doc(DbName, DocId, []).
+
+open_doc(DbName, DocId, Options) when is_list(Options) ->
+    Key = {DbName, DocId, '_', Options},
     case ddoc_cache_opener:match_newest(Key) of
         {ok, _} = Resp ->
             couch_stats:increment_counter([ddoc_cache, hit]),
             Resp;
         missing ->
             couch_stats:increment_counter([ddoc_cache, miss]),
-            ddoc_cache_opener:open_doc(DbName, DocId);
+            ddoc_cache_opener:open_doc(DbName, DocId, Options);
         recover ->
             couch_stats:increment_counter([ddoc_cache, recovery]),
-            ddoc_cache_opener:recover_doc(DbName, DocId)
-    end.
-
+            ddoc_cache_opener:recover_doc(DbName, DocId, Options)
+    end;
 open_doc(DbName, DocId, RevId) ->
     Key = {DbName, DocId, RevId},
     case ddoc_cache_opener:lookup(Key) of
@@ -82,6 +85,11 @@ evict(ShardDbName, DDocIds) ->
 open(DbName, validation_funs) ->
     open_validation_funs(DbName);
 open(DbName, <<"_design/", _/binary>>=DDocId) when is_binary(DbName) ->
-    open_doc(DbName, DDocId);
+    open(DbName, DDocId, []);
 open(DbName, DDocId) when is_binary(DDocId) ->
-    open_doc(DbName, <<"_design/", DDocId/binary>>).
+    open(DbName, DDocId, []).
+
+open(DbName, <<"_design/", _/binary>>=DDocId, Options) when is_binary(DbName)
->
+    open_doc(DbName, DDocId, Options);
+open(DbName, DDocId, Options) when is_binary(DDocId) ->
+    open_doc(DbName, <<"_design/", DDocId/binary>>, Options).

http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/6ff15205/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 1ef3ec8..d9567de 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -73,12 +73,14 @@ start_link() ->
 
 -spec open_doc(dbname(), docid()) -> {ok, #doc{}}.
 open_doc(DbName, DocId) ->
-    Resp = gen_server:call(?MODULE, {open, {DbName, DocId}}, infinity),
-    handle_open_response(Resp).
+    open_doc(DbName, DocId, []).
 
--spec open_doc(dbname(), docid(), revision()) -> {ok, #doc{}}.
+-spec open_doc(dbname(), docid(), revision() | list()) -> {ok, #doc{}}.
+open_doc(DbName, DocId, Options) when is_list(Options) ->
+    Resp = gen_server:call(?MODULE, {open, {DbName, DocId, Options}}, infinity),
+    handle_open_response(Resp);
 open_doc(DbName, DocId, Rev) ->
-    Resp = gen_server:call(?MODULE, {open, {DbName, DocId, Rev}}, infinity),
+    Resp = gen_server:call(?MODULE, {open, {DbName, DocId, Rev, []}}, infinity),
     handle_open_response(Resp).
 
 -spec open_validation_funs(dbname()) -> {ok, [fun()]}.
@@ -117,10 +119,15 @@ match_newest(Key) ->
     end.
 
 recover_doc(DbName, DDocId) ->
-    fabric:open_doc(DbName, DDocId, [ejson_body]).
+    recover_doc(DbName, DDocId, []).
 
+recover_doc(DbName, DDocId, Options) when is_list(Options) ->
+    fabric:open_doc(DbName, DDocId, [ejson_body | Options]);
 recover_doc(DbName, DDocId, Rev) ->
-    {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [Rev], [ejson_body]),
+    recover_doc(DbName, DDocId, Rev, []).
+
+recover_doc(DbName, DDocId, Rev, Options) ->
+    {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [Rev], [ejson_body | Options]),
     Resp.
 
 recover_validation_funs(DbName) ->
@@ -236,8 +243,8 @@ fetch_doc_data({DbName, validation_funs}=OpenerKey) ->
     {ok, Funs} = recover_validation_funs(DbName),
     ok = ets_lru:insert(?CACHE, OpenerKey, Funs),
     exit({open_ok, OpenerKey, {ok, Funs}});
-fetch_doc_data({DbName, DocId}=OpenerKey) ->
-    try recover_doc(DbName, DocId) of
+fetch_doc_data({DbName, DocId, Options}=OpenerKey) ->
+    try recover_doc(DbName, DocId, Options) of
         {ok, Doc} ->
             {RevDepth, [RevHash| _]} = Doc#doc.revs,
             Rev = {RevDepth, RevHash},
@@ -249,8 +256,8 @@ fetch_doc_data({DbName, DocId}=OpenerKey) ->
         Type:Reason ->
             exit({open_error, OpenerKey, Type, Reason})
     end;
-fetch_doc_data({DbName, DocId, Rev}=OpenerKey) ->
-    try recover_doc(DbName, DocId, Rev) of
+fetch_doc_data({DbName, DocId, Rev, Options}=OpenerKey) ->
+    try recover_doc(DbName, DocId, Rev, Options) of
         {ok, Doc} ->
             ok = ets_lru:insert(?CACHE, {DbName, DocId, Rev}, Doc),
             exit({open_ok, OpenerKey, {ok, Doc}});


Mime
View raw message