summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-07-16 14:26:11 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-07-31 11:55:30 -0500
commitd5a5426ea10482b3c07128d443b7ad658260eb5c (patch)
tree6053f5a0a1c7c353488f78b4b11f6be0265ec155
parent24c864d2692afd844d96123180cbf4e728403449 (diff)
downloadcouchdb-d5a5426ea10482b3c07128d443b7ad658260eb5c.tar.gz
Expose the is_replicator_db and is_user_db logic
This exposes a single place where we can check for whether a given database or database name is a replicator or users database.
-rw-r--r--src/fabric/src/fabric2_db.erl37
-rw-r--r--src/fabric/src/fabric2_util.erl6
2 files changed, 31 insertions, 12 deletions
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 3c3b7d3a5..c926da9e0 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -55,6 +55,8 @@
is_partitioned/1,
is_system_db/1,
is_system_db_name/1,
+ is_replicator_db/1,
+ is_users_db/1,
set_revs_limit/2,
%% set_purge_infos_limit/2,
@@ -379,6 +381,29 @@ is_system_db_name(DbName) when is_binary(DbName) ->
end.
+is_replicator_db(#{name := DbName}) ->
+ is_replicator_db(DbName);
+
+is_replicator_db(DbName) when is_binary(DbName) ->
+ fabric2_util:dbname_ends_with(DbName, <<"_replicator">>).
+
+
+is_users_db(#{name := DbName}) ->
+ is_users_db(DbName);
+
+is_users_db(DbName) when is_binary(DbName) ->
+ AuthenticationDb = config:get("chttpd_auth", "authentication_db"),
+ CfgUsersSuffix = config:get("couchdb", "users_db_suffix", "_users"),
+
+ IsAuthCache = if AuthenticationDb == undefined -> false; true ->
+ DbName == ?l2b(AuthenticationDb)
+ end,
+ IsCfgUsersDb = fabric2_util:dbname_ends_with(DbName, ?l2b(CfgUsersSuffix)),
+ IsGlobalUsersDb = fabric2_util:dbname_ends_with(DbName, <<"_users">>),
+
+ IsAuthCache orelse IsCfgUsersDb orelse IsGlobalUsersDb.
+
+
set_revs_limit(#{} = Db, RevsLimit) ->
check_is_admin(Db),
RevsLimBin = ?uint2bin(RevsLimit),
@@ -734,16 +759,8 @@ fold_changes(Db, SinceSeq, UserFun, UserAcc, Options) ->
maybe_add_sys_db_callbacks(Db) ->
- IsReplicatorDb = fabric2_util:dbname_ends_with(Db, <<"_replicator">>),
-
- AuthenticationDb = config:get("chttpd_auth", "authentication_db"),
- IsAuthCache = if AuthenticationDb == undefined -> false; true ->
- name(Db) == ?l2b(AuthenticationDb)
- end,
- CfgUsersSuffix = config:get("couchdb", "users_db_suffix", "_users"),
- IsCfgUsersDb = fabric2_util:dbname_ends_with(Db, ?l2b(CfgUsersSuffix)),
- IsGlobalUsersDb = fabric2_util:dbname_ends_with(Db, <<"_users">>),
- IsUsersDb = IsAuthCache orelse IsCfgUsersDb orelse IsGlobalUsersDb,
+ IsReplicatorDb = is_replicator_db(Db),
+ IsUsersDb = is_users_db(Db),
{BDU, ADR} = if
IsReplicatorDb ->
diff --git a/src/fabric/src/fabric2_util.erl b/src/fabric/src/fabric2_util.erl
index 48bf7d143..2b8e49ebf 100644
--- a/src/fabric/src/fabric2_util.erl
+++ b/src/fabric/src/fabric2_util.erl
@@ -124,8 +124,10 @@ validate_json_list_of_strings(Member, Props) ->
end.
-dbname_ends_with(#{} = Db, Suffix) when is_binary(Suffix) ->
- DbName = fabric2_db:name(Db),
+dbname_ends_with(#{} = Db, Suffix) ->
+ dbname_ends_with(fabric2_db:name(Db), Suffix);
+
+dbname_ends_with(DbName, Suffix) when is_binary(DbName), is_binary(Suffix) ->
Suffix == filename:basename(DbName).