You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/06/01 18:10:11 UTC

[GitHub] [couchdb] nickva commented on a change in pull request #3586: Improve basic auth credentials handling in replicator

nickva commented on a change in pull request #3586:
URL: https://github.com/apache/couchdb/pull/3586#discussion_r643373557



##########
File path: src/couch_replicator/src/couch_replicator_utils.erl
##########
@@ -191,6 +194,99 @@ ejson_state_info(Info) ->
     {[{<<"error">>, ErrMsg}]}.
 
 
+-spec get_basic_auth_creds(#httpdb{}) ->
+    {string(), string()} | {undefined, undefined}.
+get_basic_auth_creds(#httpdb{auth_props = AuthProps}) ->
+    case couch_util:get_value(<<"basic">>, AuthProps) of
+        undefined ->
+            {undefined, undefined};
+        {UserPass} when is_list(UserPass)  ->
+            User = couch_util:get_value(<<"username">>, UserPass),
+            Pass = couch_util:get_value(<<"password">>, UserPass),
+            case {User, Pass} of
+                _ when is_binary(User), is_binary(Pass) ->
+                    {binary_to_list(User), binary_to_list(Pass)};
+                _Other ->
+                    {undefined, undefined}
+            end;
+        _Other ->
+            {undefined, undefined}
+    end.
+
+
+-spec remove_basic_auth_creds(#httpd{}) -> #httpdb{}.
+remove_basic_auth_creds(#httpdb{auth_props = Props} = HttpDb) ->
+    Props1 = lists:keydelete(<<"basic">>, 1, Props),
+    HttpDb#httpdb{auth_props = Props1}.
+
+
+-spec set_basic_auth_creds(string(), string(), #httpd{}) -> #httpdb{}.
+set_basic_auth_creds(undefined, undefined, #httpdb{} = HttpDb) ->
+    HttpDb;
+

Review comment:
       Good catch!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org