[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170109817
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170109817
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170107966
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
 
 Review comment:
   Because part of updating headers could be refreshing the cookie, which is an 
IO operation. Even if it calls during `process_response` gen_server could be 
talking to a session endpoint refreshing a cookie. HTTP requests inherit  the 
timeout value used in the replication doc / config settings so those will be 
bounded by that.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170109817
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170117693
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
 
 Review comment:
   But what's the downside of letting start_link fail with an error vs doing 
the manual proc_lib trick?
   
   Looking at docs at http://erlang.org/doc/man/gen_server.html#start_link-3 
`{error, Reason}` seems like it would do what we want?
   
   > If the gen_server process is successfully created and initialized, the 
function returns {ok,Pid}, where Pid is the pid of the gen_server process. If 
Module:init/1 fails with Reason, the function returns {error,Reason}. If 
Module:init/1 returns {stop,Reason} or ignore, the process is terminated and 
the function returns {error,Reason} or ignore, respectively.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170117693
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
 
 Review comment:
   But what's the downside of letting start_link fail with an error vs doing 
the manual proc_lib trick?
   
   Looking at docs at http://erlang.org/doc/man/gen_server.html#start_link-3 
`{error, Reason}` seems like it would do what we want?
   
   > If the gen_server process is successfully created and initialized, the 
function returns {ok,Pid}, where Pid is the pid of the gen_server process. If a 
process with the specified ServerName exists already, the function returns 
{error,{already_started,Pid}}, where Pid is the pid of that process.
   
   If Module:init/1 fails with Reason, the function returns {error,Reason}. If 
Module:init/1 returns {stop,Reason} or ignore, the process is terminated and 
the function returns {error,Reason} or ignore, respectively.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] wohali commented on issue #1178: Prevent chttpd multipart zombie processes

2018-02-22 Thread GitBox
wohali commented on issue #1178: Prevent chttpd multipart zombie processes
URL: https://github.com/apache/couchdb/pull/1178#issuecomment-367848644
 
 
   +1
   
   :postal_horn: :imp: :unicorn: 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170117693
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
 
 Review comment:
   But what's the downside of letting start_link fail with an error vs doing 
the manual proc_lib trick?
   
   Looking at docs at http://erlang.org/doc/man/gen_server.html#start_link-3 
`{error, Reason}` seems like it would do what we want?
   
   ```
   If the gen_server process is successfully created and initialized, the 
function returns {ok,Pid}, where Pid is the pid of the gen_server process. If a 
process with the specified ServerName exists already, the function returns 
{error,{already_started,Pid}}, where Pid is the pid of that process.
   
   If Module:init/1 fails with Reason, the function returns {error,Reason}. If 
Module:init/1 returns {stop,Reason} or ignore, the process is terminated and 
the function returns {error,Reason} or ignore, respectively.
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170112999
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth.erl
 ##
 @@ -0,0 +1,100 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_auth).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+
+
+-define(DEFAULT_PLUGINS,
+"couch_replicator_auth_session,couch_replicator_auth_basic").
+
+
+% Behavior API
+
+-callback initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+
+-callback update_headers(term(), headers()) -> {headers(), term()}.
 
 Review comment:
   It was a practical decision by looking at some of authentications 
mechanisms. Most I could find seem to work with headers. OAuth2 adds the bearer 
token as a header. Session cookie is a header as well.
   
   Other things I could think of are the url itself, so it allows adding query 
params, and the body. I don't know if passing the body through it would be a 
good idea (thinking of large streaming attachments for example). And couldn't 
think of a practical use for updating the url.
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170112999
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth.erl
 ##
 @@ -0,0 +1,100 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_auth).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+
+
+-define(DEFAULT_PLUGINS,
+"couch_replicator_auth_session,couch_replicator_auth_basic").
+
+
+% Behavior API
+
+-callback initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+
+-callback update_headers(term(), headers()) -> {headers(), term()}.
 
 Review comment:
   It was a practical decision by looking at some of authentications 
mechanisms. Most I could find seem to work with headers. OAuth2 add the bearer 
token as a header. Session cookie is a header as well.
   
   Other things I could think of are the url itself, so it allows adding query 
params, and the body. I don't know if passing the body through it would be a 
good idea (thinking of large streaming attachments for example). And couldn't 
think of a practical use for updating the url.
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows Server 2016

2018-02-22 Thread GitBox
reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows 
Server 2016
URL: https://github.com/apache/couchdb/issues/698#issuecomment-367843082
 
 
   Gotcha. Thanks for super quick reply
   
   > On Feb 22, 2018, at 4:15 PM, Joan Touzet  wrote:
   > 
   > CouchDB binds to both ports 5984 (clustered interface) and 5986 
(localhost-only administrative interface).
   > 
   > ?
   > You are receiving this because you commented.
   > Reply to this email directly, view it on GitHub, or mute the thread.
   > 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170109875
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170109817
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170108164
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170108164
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,
+ 

[GitHub] davisp opened a new pull request #1178: Prevent chttpd multipart zombie processes

2018-02-22 Thread GitBox
davisp opened a new pull request #1178: Prevent chttpd multipart zombie 
processes
URL: https://github.com/apache/couchdb/pull/1178
 
 
   Occasionally it's possible to lose track of our RPC workers in the main
   multipart parsing code. This change monitors each worker process and
   then exits if all workers have exited before the parser considers itself
   finished.
   
   Fixes part of #745
   
   ## Testing recommendations
   
   This was tested under the conditions for 745 which are non-trivial but can 
be duplicated by reading that PR.
   
   ## Related Issues or Pull Requests
   
   Issue #745 was the original report for this issue
   
   ## Checklist
   
   - [x] Code is written and works correctly;
   - [ ] Changes are covered by tests;
   - [ ] Documentation reflects the changes;
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] davisp commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
davisp commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170098419
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
 
 Review comment:
   You want to use proc_lib:start_link, proc_lib:init_ack, and 
gen_server:enter_loop. Here's an example from config_listener_mon.erl:
   
   
https://github.com/apache/couchdb-config/blob/1.0.2/src/config_listener_mon.erl#L40-L57
   
   Basically, proc_lib:start_link/proc_lib:init_ack allow you to do a 
synchronous process startup and the new process can return anything it wants. 
If your gen_server state creation thing succeeds you can then just call 
gen_server:enter_loop to become a gen_server. Or else you just init_ack any 
error and return and the process dies.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] wohali commented on issue #698: CouchDB 2 service keeps restarting on Windows Server 2016

2018-02-22 Thread GitBox
wohali commented on issue #698: CouchDB 2 service keeps restarting on Windows 
Server 2016
URL: https://github.com/apache/couchdb/issues/698#issuecomment-367824436
 
 
   CouchDB binds to both ports 5984 (clustered interface) and 5986 
(localhost-only administrative interface).


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170086079
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth.erl
 ##
 @@ -0,0 +1,100 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_auth).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+
+
+-define(DEFAULT_PLUGINS,
+"couch_replicator_auth_session,couch_replicator_auth_basic").
+
+
+% Behavior API
+
+-callback initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+
+-callback update_headers(term(), headers()) -> {headers(), term()}.
 
 Review comment:
   this makes the (reasonable) assumption that all auth systems work via 
headers, but it isn't an ideal abstraction. The intention behind allowing a 
callback to update headers is to apply the authentication whatevers, so perhaps 
that would be a better shape?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170089423
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,

[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170086460
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_basic.erl
 ##
 @@ -0,0 +1,52 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_auth_basic).
 
 Review comment:
   that this module has no code in it implies the abstraction is a bit off. 
There's no basic auth logic here.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170088524
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,

[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170089748
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Headers1, {Pid, Epoch1}}.
+
+
+-spec handle_response(term(), code(), headers(), term()) ->
+{continue | retry, term()}.
+handle_response({Pid, Epoch}, Code, Headers, Body) ->
+Args =  {handle_response, Code, Headers, Body, Epoch},
+{Retry, Epoch1} = gen_server:call(Pid, Args, infinity),
+{Retry, {Pid, Epoch1}}.
+
+
+-spec cleanup(term()) -> ok.
+cleanup({Pid, _Epoch}) ->
+gen_server:call(Pid, stop, infinity).
+
+
+%% Definitions
+
+-define(MIN_UPDATE_INTERVAL, 5).
+
+
+%% gen_server state
+
+-record(state, {
+epoch = 0 :: non_neg_integer(),
+cookie :: string() | undefined,
+user :: string() | undefined,
+pass :: string() | undefined,

[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170086765
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
 
 Review comment:
   talk to @davisp, there's a defined pattern to follow for gen_servers that 
might fail at startup.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170086911
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
 
 Review comment:
   `extract_creds` maybe better, given it not only removes them but returns 
them.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170087462
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth_session.erl
 ##
 @@ -0,0 +1,545 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+% This is the replicator session auth plugin. It implements session based
+% authentication for the replicator. The only public API are the functions from
+% the couch_replicator_auth behaviour. Most of the logic and state is in the
+% gen_server. An instance of a gen_server could be spawned for the source and
+% target endpoints of each replication jobs.
+%
+% The workflow is roughly this:
+%
+%  * On initialization, try to get a cookie in `refresh/1` If an error occurs,
+%the crash. If `_session` endpoint fails with a 404 (not found), return
+%`ignore` assuming session authentication is not support or we simply hit a
+%non-CouchDb server.
+%
+%  * Before each request, auth framework calls `update_headers` API function.
+%Before updating the headers and returning, check if need to refresh again.
+%The check looks `next_refresh` time. If that time is set (not `infinity`)
+%and just expired, then obtain a new cookie, then update headers and
+%return.
+%
+%  * After each request, auth framework calls `handle_response` function. If
+%request was successful check if a new cookie was sent by the server in the
+%`Set-Cookie` header. If it was then then that becomes the current cookie.
+%
+%  * If last request has an auth failure, check if request used a stale cookie
+%In this case nothing is done, and the client is told to retry. Next time
+%it updates its headers befor the request it should pick up the latest
+%cookie.
+%
+%  * If last request failed and cookie was the latest known cookie, schedule a
+%refresh and tell client to retry. However, if the cookie was just updated,
+%tell the client to continue such that it will handle the auth failure on
+%its own via a set of retries with exponential backoffs. This is it to
+%ensure if something goes wrong and one of the endpoints issues invalid
+%cookies, replicator won't be stuck in a busy loop refreshing them.
+
+
+-module(couch_replicator_auth_session).
+
+
+-behaviour(couch_replicator_auth).
+-behaviour(gen_server).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+-export([
+init/1,
+terminate/2,
+handle_call/3,
+handle_cast/2,
+handle_info/2,
+code_change/3,
+format_status/2
+]).
+
+
+-include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
+
+
+-type headers() :: [{string(), string()}].
+-type code() :: non_neg_integer().
+-type creds() :: {string() | undefined, string() | undefined}.
+
+
+% Behavior API callbacks
+
+
+-spec initialize(#httpdb{}) -> {ok, #httpdb{}, term()} | ignore.
+initialize(#httpdb{} = HttpDb) ->
+case remove_creds(HttpDb) of
+{ok, User, Pass, HttpDb1} ->
+case gen_server:start_link(?MODULE, [User, Pass, HttpDb1], []) of
+{ok, Pid} ->
+{ok, HttpDb1, {Pid, 0}};
+ignore ->
+ignore;
+{error, Error} ->
+{error, Error}
+end;
+{error, missing_credentials} ->
+ignore;
+{error, Error} ->
+{error, Error}
+end.
+
+
+-spec update_headers(term(), headers()) -> {headers(), term()}.
+update_headers({Pid, Epoch}, Headers) ->
+Args = {update_headers, Headers, Epoch},
+{Headers1, Epoch1} = gen_server:call(Pid, Args, infinity),
 
 Review comment:
   why infinity here when the only thing this call can do is an http request 
with a defined timeout? infinity for :call is used in couchdb where we do disk 
i/o as that's truly hard to predict, but best avoided if we can put a 
reasonable finite bound instead.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows Server 2016

2018-02-22 Thread GitBox
reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows 
Server 2016
URL: https://github.com/apache/couchdb/issues/698#issuecomment-367805522
 
 
   Thanks but CouchDB uses specifically 5984 so why the issue still? Also FYI, 
on AWS no issues whatsoever. Only GCP
   

   
   Rey Jimenez
   
 r...@askrey.com
   

   

   
   From: Joan Touzet [mailto:notificati...@github.com] 
   Sent: Thursday, February 22, 2018 2:03 PM
   To: apache/couchdb 
   Cc: reyj007 ; Comment 
   Subject: Re: [apache/couchdb] CouchDB 2 service keeps restarting on Windows 
Server 2016 (#698)
   

   
   https://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx
   
   WinRM 2.0:  The default HTTP port is 5985, and the default HTTPS port is 
5986.
   
   You can change the port to fix this problem if desired.
   
   ?
   You are receiving this because you commented.
   Reply to this email directly, view it on GitHub 
 , or mute 
the thread 

 .  

 
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170064480
 
 

 ##
 File path: src/couch_replicator/include/couch_replicator_api_wrap.hrl
 ##
 @@ -26,13 +26,6 @@
 httpc_pool = nil,
 http_connections,
 first_error_timestamp = nil,
-proxy_url
-}).
-
--record(oauth, {
-consumer_key,
-token,
-token_secret,
-consumer_secret,
-signature_method
+proxy_url,
+auth_context = nil
 
 Review comment:
   We never pass #httpd{} record between nodes


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170064207
 
 

 ##
 File path: src/couch_replicator/include/couch_replicator_api_wrap.hrl
 ##
 @@ -26,13 +26,6 @@
 httpc_pool = nil,
 http_connections,
 first_error_timestamp = nil,
-proxy_url
-}).
-
--record(oauth, {
-consumer_key,
-token,
-token_secret,
-consumer_secret,
-signature_method
+proxy_url,
+auth_context = nil
 
 Review comment:
   before I go deeper, we're changing the default for one field and adding an 
extra property. Are we sure there's no upgrade problem here? I think we never 
pass httpdb's between nodes but this would be bad if we did.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170064480
 
 

 ##
 File path: src/couch_replicator/include/couch_replicator_api_wrap.hrl
 ##
 @@ -26,13 +26,6 @@
 httpc_pool = nil,
 http_connections,
 first_error_timestamp = nil,
-proxy_url
-}).
-
--record(oauth, {
-consumer_key,
-token,
-token_secret,
-consumer_secret,
-signature_method
+proxy_url,
+auth_context = nil
 
 Review comment:
   I was of that. We never pass #httpd{} record between nodes


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170064480
 
 

 ##
 File path: src/couch_replicator/include/couch_replicator_api_wrap.hrl
 ##
 @@ -26,13 +26,6 @@
 httpc_pool = nil,
 http_connections,
 first_error_timestamp = nil,
-proxy_url
-}).
-
--record(oauth, {
-consumer_key,
-token,
-token_secret,
-consumer_secret,
-signature_method
+proxy_url,
+auth_context = nil
 
 Review comment:
   We never pass #httpd{} record between nodes


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rnewson commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
rnewson commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r170064207
 
 

 ##
 File path: src/couch_replicator/include/couch_replicator_api_wrap.hrl
 ##
 @@ -26,13 +26,6 @@
 httpc_pool = nil,
 http_connections,
 first_error_timestamp = nil,
-proxy_url
-}).
-
--record(oauth, {
-consumer_key,
-token,
-token_secret,
-consumer_secret,
-signature_method
+proxy_url,
+auth_context = nil
 
 Review comment:
   before I go deeper, we're changing the default for one field and adding an 
extra property. Are we sure there's no upgrade problem here? I think we never 
pass httpdb's between nodes but this would be bad if we did.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] wohali commented on issue #698: CouchDB 2 service keeps restarting on Windows Server 2016

2018-02-22 Thread GitBox
wohali commented on issue #698: CouchDB 2 service keeps restarting on Windows 
Server 2016
URL: https://github.com/apache/couchdb/issues/698#issuecomment-367785530
 
 
   https://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx
   
   ```
   WinRM 2.0:  The default HTTP port is 5985, and the default HTTPS port is 
5986.
   ```
   
   You can change the port to fix this problem if desired.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows Server 2016

2018-02-22 Thread GitBox
reyj007 commented on issue #698: CouchDB 2 service keeps restarting on Windows 
Server 2016
URL: https://github.com/apache/couchdb/issues/698#issuecomment-367757892
 
 
   callum-spartan - been searching high and low for resolving this issue. I was 
working w both 2012 & 2016 instances on GCP and could not get around the 
service starting, restarting until I saw your "Windows Remote Management " 
comment. That did it! Now to figure out what "Windows Remote Management" does?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] nickva commented on a change in pull request #1176: Implement pluggable authentication and session support for replicator

2018-02-22 Thread GitBox
nickva commented on a change in pull request #1176: Implement pluggable 
authentication and session support for replicator
URL: https://github.com/apache/couchdb/pull/1176#discussion_r169982469
 
 

 ##
 File path: src/couch_replicator/src/couch_replicator_auth.erl
 ##
 @@ -0,0 +1,100 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_auth).
+
+
+-export([
+initialize/1,
+update_headers/2,
+handle_response/4,
+cleanup/1
+]).
+
+
+-include("couch_replicator_api_wrap.hrl").
 
 Review comment:
   Good point, Jay. I'll update the PR.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services