You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/02/04 16:49:39 UTC
[2/4] couch commit: updated refs/heads/master to aa36a18
config:get/3 is more strict now
The config:get/3 supports only following types for default argument
- atom `undefined`
- string (list)
- boolean
- float
- integer
COUCDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/f21e78ec
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/f21e78ec
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/f21e78ec
Branch: refs/heads/master
Commit: f21e78ec69ceb376d52d4edfb1813877bcce1850
Parents: eee3044
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 29 12:41:26 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 05:57:20 2015 -0800
----------------------------------------------------------------------
src/couch_drv.erl | 4 ++--
src/couch_external_manager.erl | 4 ++--
src/couch_httpd.erl | 37 ++++++++++++++++++---------------
src/couch_httpd_auth.erl | 12 +++++------
src/couch_httpd_misc_handlers.erl | 12 +++++------
src/couch_os_daemons.erl | 4 ++--
src/couch_server.erl | 4 ++--
src/couch_sup.erl | 4 ++--
test/couchdb_attachments_tests.erl | 11 +++++++---
9 files changed, 50 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_drv.erl
----------------------------------------------------------------------
diff --git a/src/couch_drv.erl b/src/couch_drv.erl
index 0379264..f2ff2ac 100644
--- a/src/couch_drv.erl
+++ b/src/couch_drv.erl
@@ -55,8 +55,8 @@ code_change(_OldVsn, State, _Extra) ->
% private API
util_driver_dir() ->
- case config:get("couchdb", "util_driver_dir", null) of
- null ->
+ case config:get("couchdb", "util_driver_dir", undefined) of
+ undefined ->
couch_util:priv_dir();
LibDir0 ->
LibDir0
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_external_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_external_manager.erl b/src/couch_external_manager.erl
index a2eedbb..32bf3bd 100644
--- a/src/couch_external_manager.erl
+++ b/src/couch_external_manager.erl
@@ -65,8 +65,8 @@ terminate(_Reason, Handlers) ->
handle_call({get, UrlName}, _From, Handlers) ->
case ets:lookup(Handlers, UrlName) of
[] ->
- case config:get("external", UrlName, nil) of
- nil ->
+ case config:get("external", UrlName, undefined) of
+ undefined ->
Msg = lists:flatten(
io_lib:format("No server configured for ~p.", [UrlName])),
{reply, {error, {unknown_external_server, ?l2b(Msg)}}, Handlers};
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index d298b94..8e5555c 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -38,20 +38,20 @@ start_link(http) ->
start_link(?MODULE, [{port, Port}]);
start_link(https) ->
Port = config:get("ssl", "port", "6984"),
- {ok, Ciphers} = couch_util:parse_term(config:get("ssl", "ciphers", "nil")),
- {ok, Versions} = couch_util:parse_term(config:get("ssl", "tls_versions", "nil")),
- {ok, SecureRenegotiate} = couch_util:parse_term(config:get("ssl", "secure_renegotiate", "nil")),
+ {ok, Ciphers} = couch_util:parse_term(config:get("ssl", "ciphers", undefined)),
+ {ok, Versions} = couch_util:parse_term(config:get("ssl", "tls_versions", undefined)),
+ {ok, SecureRenegotiate} = couch_util:parse_term(config:get("ssl", "secure_renegotiate", undefined)),
ServerOpts0 =
- [{cacertfile, config:get("ssl", "cacert_file", nil)},
- {keyfile, config:get("ssl", "key_file", nil)},
- {certfile, config:get("ssl", "cert_file", nil)},
- {password, config:get("ssl", "password", nil)},
+ [{cacertfile, config:get("ssl", "cacert_file", undefined)},
+ {keyfile, config:get("ssl", "key_file", undefined)},
+ {certfile, config:get("ssl", "cert_file", undefined)},
+ {password, config:get("ssl", "password", undefined)},
{secure_renegotiate, SecureRenegotiate},
{versions, Versions},
{ciphers, Ciphers}],
- case (couch_util:get_value(keyfile, ServerOpts0) == nil orelse
- couch_util:get_value(certfile, ServerOpts0) == nil) of
+ case (couch_util:get_value(keyfile, ServerOpts0) == undefined orelse
+ couch_util:get_value(certfile, ServerOpts0) == undefined) of
true ->
couch_log:error("SSL enabled but PEM certificates are missing", []),
throw({error, missing_certs});
@@ -59,7 +59,7 @@ start_link(https) ->
ok
end,
- ServerOpts = [Opt || {_, V}=Opt <- ServerOpts0, V /= nil],
+ ServerOpts = [Opt || {_, V}=Opt <- ServerOpts0, V /= undefined],
ClientOpts = case config:get("ssl", "verify_ssl_certificates", "false") of
"false" ->
@@ -73,8 +73,8 @@ start_link(https) ->
"ssl_certificate_max_depth", "1"))},
{fail_if_no_peer_cert, FailIfNoPeerCert},
{verify, verify_peer}] ++
- case config:get("ssl", "verify_fun", nil) of
- nil -> [];
+ case config:get("ssl", "verify_fun", undefined) of
+ undefined -> [];
SpecStr ->
[{verify_fun, make_arity_3_fun(SpecStr)}]
end
@@ -87,7 +87,7 @@ start_link(https) ->
{ssl_opts, SslOpts}],
start_link(https, Options).
start_link(Name, Options) ->
- BindAddress = config:get("httpd", "bind_address", any),
+ BindAddress = with_default(config:get("httpd", "bind_address"), any),
validate_bind_address(BindAddress),
DefaultSpec = "{couch_httpd_db, handle_request}",
DefaultFun = make_arity_1_fun(
@@ -854,14 +854,14 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) ->
% this is where the basic auth popup is triggered
case MochiReq:get_header_value("X-CouchDB-WWW-Authenticate") of
undefined ->
- case config:get("httpd", "WWW-Authenticate", nil) of
- nil ->
+ case config:get("httpd", "WWW-Authenticate", undefined) of
+ undefined ->
% If the client is a browser and the basic auth popup isn't turned on
% redirect to the session page.
case ErrorStr of
<<"unauthorized">> ->
- case config:get("couch_httpd_auth", "authentication_redirect", nil) of
- nil -> {Code, []};
+ case config:get("couch_httpd_auth", "authentication_redirect", undefined) of
+ undefined -> {Code, []};
AuthRedirect ->
case config:get("couch_httpd_auth", "require_valid_user", "false") of
"true" ->
@@ -1091,3 +1091,6 @@ validate_bind_address(Address) ->
{ok, _} -> ok;
_ -> throw({error, invalid_bind_address})
end.
+
+with_default(undefined, Default) -> Default;
+with_default(Value, _) -> Value.
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_auth.erl b/src/couch_httpd_auth.erl
index 74e8ee9..9dfa539 100644
--- a/src/couch_httpd_auth.erl
+++ b/src/couch_httpd_auth.erl
@@ -158,8 +158,8 @@ proxy_auth_user(Req) ->
end,
case config:get("couch_httpd_auth", "proxy_use_secret", "false") of
"true" ->
- case config:get("couch_httpd_auth", "secret", nil) of
- nil ->
+ case config:get("couch_httpd_auth", "secret", undefined) of
+ undefined ->
Req#httpd{user_ctx=#user_ctx{name=?l2b(UserName), roles=Roles}};
Secret ->
ExpectedToken = couch_util:to_hex(crypto:sha_mac(Secret, UserName)),
@@ -195,8 +195,8 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req, AuthModule) ->
end,
% Verify expiry and hash
CurrentTime = make_cookie_time(),
- case config:get("couch_httpd_auth", "secret", nil) of
- nil ->
+ case config:get("couch_httpd_auth", "secret", undefined) of
+ undefined ->
couch_log:debug("cookie auth secret is not set",[]),
Req;
SecretStr ->
@@ -260,8 +260,8 @@ cookie_auth_cookie(Req, User, Secret, TimeStamp) ->
[{path, "/"}] ++ cookie_scheme(Req) ++ max_age()).
ensure_cookie_auth_secret() ->
- case config:get("couch_httpd_auth", "secret", nil) of
- nil ->
+ case config:get("couch_httpd_auth", "secret", undefined) of
+ undefined ->
NewSecret = ?b2l(couch_uuids:random()),
config:set("couch_httpd_auth", "secret", NewSecret),
NewSecret;
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_httpd_misc_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_misc_handlers.erl b/src/couch_httpd_misc_handlers.erl
index e90140f..8447245 100644
--- a/src/couch_httpd_misc_handlers.erl
+++ b/src/couch_httpd_misc_handlers.erl
@@ -177,8 +177,8 @@ handle_config_req(#httpd{method='GET', path_parts=[_,Section]}=Req) ->
% GET /_config/Section/Key
handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
ok = couch_httpd:verify_is_server_admin(Req),
- case config:get(Section, Key, null) of
- null ->
+ case config:get(Section, Key, undefined) of
+ undefined ->
throw({not_found, unknown_config_value});
Value ->
send_json(Req, 200, list_to_binary(Value))
@@ -193,8 +193,8 @@ handle_config_req(#httpd{method=Method, path_parts=[_, Section, Key]}=Req)
when (Method == 'PUT') or (Method == 'DELETE') ->
ok = couch_httpd:verify_is_server_admin(Req),
Persist = couch_httpd:header_value(Req, "X-Couch-Persist") /= "false",
- case config:get(<<"httpd">>, <<"config_whitelist">>, null) of
- null ->
+ case config:get("httpd", "config_whitelist", undefined) of
+ undefined ->
% No whitelist; allow all changes.
handle_approved_config_req(Req, Persist);
WhitelistValue ->
@@ -295,8 +295,8 @@ handle_approved_config_req(#httpd{method='PUT'}=Req, _Persist, UseRawValue) ->
% DELETE /_config/Section/Key
handle_approved_config_req(#httpd{method='DELETE',path_parts=[_,Section,Key]}=Req,
Persist, _UseRawValue) ->
- case config:get(Section, Key, null) of
- null ->
+ case config:get(Section, Key, undefined) of
+ undefined ->
throw({not_found, unknown_config_value});
OldValue ->
config:delete(Section, Key, Persist),
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_os_daemons.erl
----------------------------------------------------------------------
diff --git a/src/couch_os_daemons.erl b/src/couch_os_daemons.erl
index 60dbcc3..cbacdbd 100644
--- a/src/couch_os_daemons.erl
+++ b/src/couch_os_daemons.erl
@@ -241,8 +241,8 @@ handle_port_message(#daemon{port=Port}=Daemon, [<<"get">>, Section]) ->
port_command(Port, <<Json/binary, "\n">>),
{ok, Daemon};
handle_port_message(#daemon{port=Port}=Daemon, [<<"get">>, Section, Key]) ->
- Value = case config:get(Section, Key, null) of
- null -> null;
+ Value = case config:get(Section, Key, undefined) of
+ undefined -> null;
String -> ?l2b(String)
end,
Json = iolist_to_binary(?JSON_ENCODE(Value)),
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 598df6a..5a4db2e 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -59,8 +59,8 @@ get_version(short) ->
get_uuid() ->
- case config:get("couchdb", "uuid", nil) of
- nil ->
+ case config:get("couchdb", "uuid", undefined) of
+ undefined ->
UUID = couch_uuids:random(),
config:set("couchdb", "uuid", ?b2l(UUID)),
UUID;
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/src/couch_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_sup.erl b/src/couch_sup.erl
index c941a60..2926a0f 100644
--- a/src/couch_sup.erl
+++ b/src/couch_sup.erl
@@ -112,8 +112,8 @@ write_pidfile() ->
write_uris() ->
- case config:get("couchdb", "uri_file", null) of
- null ->
+ case config:get("couchdb", "uri_file", undefined) of
+ undefined ->
ok;
UriFile ->
Lines = [io_lib:format("~s~n", [Uri]) || Uri <- get_uris()],
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f21e78ec/test/couchdb_attachments_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_attachments_tests.erl b/test/couchdb_attachments_tests.erl
index 78f9f49..71d685a 100644
--- a/test/couchdb_attachments_tests.erl
+++ b/test/couchdb_attachments_tests.erl
@@ -40,7 +40,7 @@ setup() ->
DbName = ?tempdb(),
{ok, Db} = couch_db:create(DbName, []),
ok = couch_db:close(Db),
- Addr = config:get("httpd", "bind_address", any),
+ Addr = config:get("httpd", "bind_address", "127.0.0.1"),
Port = mochiweb_socket_server:get(couch_httpd, port),
Host = Addr ++ ":" ++ ?i2l(Port),
{Host, ?b2l(DbName)}.
@@ -542,11 +542,16 @@ chunked_body([Chunk | Rest], Acc) ->
get_socket() ->
Options = [binary, {packet, 0}, {active, false}],
- Addr = config:get("httpd", "bind_address", any),
Port = mochiweb_socket_server:get(couch_httpd, port),
- {ok, Sock} = gen_tcp:connect(Addr, Port, Options),
+ {ok, Sock} = gen_tcp:connect(bind_address(), Port, Options),
Sock.
+bind_address() ->
+ case config:get("httpd", "bind_address") of
+ undefined -> any;
+ Address -> Address
+ end.
+
request(Method, Url, Headers, Body) ->
RequestHead = [Method, " ", Url, " HTTP/1.1"],
RequestHeaders = [[string:join([Key, Value], ": "), "\r\n"]