You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/10/30 21:56:00 UTC

[couchdb] branch master updated: Show source and target proxies in _scheduler/docs output

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 18db801  Show source and target proxies in _scheduler/docs output
18db801 is described below

commit 18db801b751d9aeb22cb99783eee252bc3cf82d1
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Wed Oct 30 15:45:44 2019 -0400

    Show source and target proxies in _scheduler/docs output
    
    Since we have separate proxies for source and target
    (https://github.com/apache/couchdb/commit/053d494e698181ae3b0b0698055f5a24e7995172),
    show them in _scheduler/docs endpoint as separate as well. Previously we just
    read the proxy value from the source.
    
    When formatting the proxy url for output, make sure `socks5` schema is handled
    by the url credentials stripping code to avoid exposing user credentials.
---
 src/couch/src/couch_util.erl                       |  4 +--
 .../src/couch_replicator_scheduler.erl             | 31 ++++++++++++++++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index 62e17ce..e2885a1 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -529,8 +529,8 @@ reorder_results(Keys, SortedResults) ->
 
 url_strip_password(Url) ->
     re:replace(Url,
-        "http(s)?://([^:]+):[^@]+@(.*)$",
-        "http\\1://\\2:*****@\\3",
+        "(http|https|socks5)://([^:]+):[^@]+@(.*)$",
+        "\\1://\\2:*****@\\3",
         [{return, list}]).
 
 encode_doc_id(#doc{id = Id}) ->
diff --git a/src/couch_replicator/src/couch_replicator_scheduler.erl b/src/couch_replicator/src/couch_replicator_scheduler.erl
index 52d362b..c9da377 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler.erl
@@ -165,7 +165,8 @@ job_summary(JobId, HealthThreshold) ->
                 {last_updated, last_updated(History)},
                 {start_time,
                     couch_replicator_utils:iso8601(Rep#rep.start_time)},
-                {proxy, job_proxy_url(Rep#rep.source)}
+                {source_proxy, job_proxy_url(Rep#rep.source)},
+                {target_proxy, job_proxy_url(Rep#rep.target)}
             ];
         {error, not_found} ->
             nil  % Job might have just completed
@@ -1068,7 +1069,8 @@ scheduler_test_() ->
             t_job_summary_running(),
             t_job_summary_pending(),
             t_job_summary_crashing_once(),
-            t_job_summary_crashing_many_times()
+            t_job_summary_crashing_many_times(),
+            t_job_summary_proxy_fields()
          ]
     }.
 
@@ -1479,6 +1481,31 @@ t_job_summary_crashing_many_times() ->
     end).
 
 
+t_job_summary_proxy_fields() ->
+    ?_test(begin
+        Job =  #job{
+            id = job1,
+            history = [started(10), added()],
+            rep = #rep{
+                source = #httpdb{
+                    url = "https://s",
+                    proxy_url = "http://u:p@sproxy:12"
+                },
+                target = #httpdb{
+                    url = "http://t",
+                    proxy_url = "socks5://u:p@tproxy:34"
+                }
+            }
+        },
+        setup_jobs([Job]),
+        Summary = job_summary(job1, ?DEFAULT_HEALTH_THRESHOLD_SEC),
+        ?assertEqual(<<"http://u:*****@sproxy:12">>,
+            proplists:get_value(source_proxy, Summary)),
+        ?assertEqual(<<"socks5://u:*****@tproxy:34">>,
+            proplists:get_value(target_proxy, Summary))
+    end).
+
+
 % Test helper functions
 
 setup() ->