From 400d0d1ef8e12638f404f139520fc7a0e960ef25 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 19 Dec 2019 14:09:52 +0800 Subject: [PATCH] Add %p to express sockport --- .gitignore | 1 + etc/emqx_auth_http.conf | 2 ++ src/emqx_acl_http.erl | 4 +++- src/emqx_auth_http.erl | 8 +++++--- src/emqx_auth_http_cli.erl | 1 + test/emqx_auth_http_SUITE.erl | 1 + 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 26a07ac..557a3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ rebar.lock rebar3.crashdump etc/emqx_auth_http.conf.rendered .rebar3/ +*.swp diff --git a/etc/emqx_auth_http.conf b/etc/emqx_auth_http.conf index 8bc25b8..a8f1374 100644 --- a/etc/emqx_auth_http.conf +++ b/etc/emqx_auth_http.conf @@ -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 ## @@ -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 ## diff --git a/src/emqx_acl_http.erl b/src/emqx_acl_http.erl index 665f9ac..77b8f1e 100644 --- a/src/emqx_acl_http.erl +++ b/src/emqx_acl_http.erl @@ -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 @@ -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. diff --git a/src/emqx_auth_http.erl b/src/emqx_auth_http.erl index 4c0e8c0..8a7e13f 100644 --- a/src/emqx_auth_http.erl +++ b/src/emqx_auth_http.erl @@ -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 @@ -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. @@ -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. diff --git a/src/emqx_auth_http_cli.erl b/src/emqx_auth_http_cli.erl index ff44016..2d447ba 100644 --- a/src/emqx_auth_http_cli.erl +++ b/src/emqx_auth_http_cli.erl @@ -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)}; diff --git a/test/emqx_auth_http_SUITE.erl b/test/emqx_auth_http_SUITE.erl index 8474ac4..b0d633f 100644 --- a/test/emqx_auth_http_SUITE.erl +++ b/test/emqx_auth_http_SUITE.erl @@ -14,6 +14,7 @@ -module(emqx_auth_http_SUITE). +-compile(nowarn_export_all). -compile(export_all). -include_lib("emqx/include/emqx.hrl").