Skip to content

Commit

Permalink
Add %p to express sockport
Browse files Browse the repository at this point in the history
  • Loading branch information
HJianBo authored and turtleDeng committed Dec 20, 2019
1 parent 50b01e0 commit 400d0d1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ rebar.lock
rebar3.crashdump
etc/emqx_auth_http.conf.rendered
.rebar3/
*.swp
2 changes: 2 additions & 0 deletions etc/emqx_auth_http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
## - %a: ipaddress
## - %r: protocol
## - %P: password
## - %p: sockport of server accepted
## - %C: common name of client TLS cert
## - %d: subject of client TLS cert
##
Expand All @@ -51,6 +52,7 @@ auth.http.auth_req.params = clientid=%c,username=%u,password=%P
## - %a: ipaddress
## - %r: protocol
## - %P: password
## - %p: sockport of server accepted
## - %C: common name of client TLS cert
## - %d: subject of client TLS cert
##
Expand Down
4 changes: 3 additions & 1 deletion src/emqx_acl_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl").

-logger_header("[ACL http]").

-import(emqx_auth_http_cli,
[ request/5
, feedvar/2
Expand Down Expand Up @@ -62,7 +64,7 @@ do_check_acl(ClientInfo, PubSub, Topic, _AclResult, #{acl_req := AclReq,
{ok, 200, _Body} -> {stop, allow};
{ok, _Code, _Body} -> {stop, deny};
{error, Error} ->
?LOG(error, "[ACL http] do_check_acl url ~s Error: ~p",
?LOG(error, "Request ACL url ~s, error: ~p",
[AclReq#http_request.url, Error]),
ok
end.
Expand Down
8 changes: 5 additions & 3 deletions src/emqx_auth_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/types.hrl").

-logger_header("[Auth http]").

-import(emqx_auth_http_cli,
[ request/5
, feedvar/2
Expand Down Expand Up @@ -58,13 +60,13 @@ check(ClientInfo, AuthResult, #{auth_req := AuthReq,
anonymous => false,
mountpoint => mountpoint(Body, ClientInfo)}};
{ok, Code, _Body} ->
?LOG(error, "[Auth http] check_auth Url: ~p login failed. result ~p",
?LOG(error, "Deny connection from url: ~s, response http code: ~p",
[AuthReq#http_request.url, Code]),
emqx_metrics:inc('auth.http.failure'),
{stop, AuthResult#{auth_result => http_to_connack_error(Code),
anonymous => false}};
{error, Error} ->
?LOG(error, "[Auth http] check_auth Url: ~p Error: ~p",
?LOG(error, "Request auth url: ~s, error: ~p",
[AuthReq#http_request.url, Error]),
emqx_metrics:inc('auth.http.failure'),
%%FIXME later: server_unavailable is not right.
Expand Down Expand Up @@ -94,7 +96,7 @@ is_superuser(#http_request{method = Method,
case request(Method, Url, feedvar(Params, ClientInfo), HttpOpts, RetryOpts) of
{ok, 200, _Body} -> true;
{ok, _Code, _Body} -> false;
{error, Error} -> ?LOG(error, "[Auth HTTP] is_superuser ~s Error: ~p", [Url, Error]),
{error, Error} -> ?LOG(error, "Request superuser url ~s, error: ~p", [Url, Error]),
false
end.

Expand Down
1 change: 1 addition & 0 deletions src/emqx_auth_http_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ feedvar(Params, ClientInfo = #{username := Username,
({Param, "%r"}) -> {Param, Protocol};
({Param, "%a"}) -> {Param, inet:ntoa(Peerhost)};
({Param, "%P"}) -> {Param, maps:get(password, ClientInfo, undefined)};
({Param, "%p"}) -> {Param, maps:get(sockport, ClientInfo, undefined)};
({Param, "%C"}) -> {Param, maps:get(cn, ClientInfo, undefined)};
({Param, "%d"}) -> {Param, maps:get(dn, ClientInfo, undefined)};
({Param, "%A"}) -> {Param, maps:get(access, ClientInfo, undefined)};
Expand Down
1 change: 1 addition & 0 deletions test/emqx_auth_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

-module(emqx_auth_http_SUITE).

-compile(nowarn_export_all).
-compile(export_all).

-include_lib("emqx/include/emqx.hrl").
Expand Down

0 comments on commit 400d0d1

Please sign in to comment.