1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00

Add socket pool and fix pattern matching (#830)

Signed-off-by: drasko <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2019-09-01 21:53:04 +02:00 committed by GitHub
parent 2d1347eee3
commit a8836d67e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,8 +39,11 @@ identify(Password) ->
URL = [list_to_binary(AuthUrl), <<"/identify">>],
ReqBody = jsone:encode(#{<<"token">> => Password}),
ReqHeaders = [{<<"Content-Type">>, <<"application/json">>}],
Payload = <<>>,
Options = [{pool, default}],
error_logger:info_msg("identify: ~p", [URL]),
{ok, Status, _, Ref} = hackney:request(post, URL, ReqHeaders, ReqBody),
case hackney:request(post, URL, ReqHeaders, ReqBody, Payload, Options) of
{ok, Status, _, Ref} ->
case Status of
200 ->
case hackney:body(Ref) of
@ -55,8 +58,12 @@ identify(Password) ->
{error, invalid_credentials};
_ ->
{error, auth_error}
end;
{error,checkout_timeout} ->
{error,checkout_timeout};
_ ->
{error,authn_req_error}
end.
access(UserName, ChannelId) ->
error_logger:info_msg("access: ~p ~p", [UserName, ChannelId]),
[{_, AuthUrl}] = ets:lookup(mfx_cfg, auth_url),
@ -64,7 +71,10 @@ access(UserName, ChannelId) ->
error_logger:info_msg("URL: ~p", [URL]),
ReqBody = jsone:encode(#{<<"thing_id">> => UserName}),
ReqHeaders = [{<<"Content-Type">>, <<"application/json">>}],
{ok, Status, _RespHeaders, _ClientRef} = hackney:request(post, URL, ReqHeaders, ReqBody),
Payload = <<>>,
Options = [{pool, default}],
case hackney:request(post, URL, ReqHeaders, ReqBody, Payload, Options) of
{ok, Status, _RespHeaders, _ClientRef} ->
case Status of
200 ->
ok;
@ -72,8 +82,12 @@ access(UserName, ChannelId) ->
{error, forbidden};
_ ->
{error, authz_error}
end;
{error,checkout_timeout} ->
{error,checkout_timeout};
_ ->
{error,authz_req_error}
end.
auth_on_register({_IpAddr, _Port} = Peer, {_MountPoint, _ClientId} = SubscriberId, UserName, Password, CleanSession) ->
error_logger:info_msg("auth_on_register: ~p ~p ~p ~p ~p", [Peer, SubscriberId, UserName, Password, CleanSession]),
%% do whatever you like with the params, all that matters