chore(gw): adapt to authn config format

This commit is contained in:
JianBo He 2021-08-04 14:42:24 +08:00
parent 1b2f732f13
commit 94e33c3917
3 changed files with 28 additions and 18 deletions

View File

@ -16,6 +16,8 @@ gateway: {
password: "${Packet.headers.passcode}" password: "${Packet.headers.passcode}"
} }
authentication: {
enable: true
authenticators: [ authenticators: [
{ {
name: "authenticator1" name: "authenticator1"
@ -24,6 +26,7 @@ gateway: {
user_id_type: clientid user_id_type: clientid
} }
] ]
}
listener.tcp.1: { listener.tcp.1: {
bind: 61613 bind: 61613
@ -36,7 +39,7 @@ gateway: {
coap.1: { coap.1: {
enable_stats: false enable_stats: false
authenticators: [] authentication.enable: false
heartbeat: 30s heartbeat: 30s
resource: mqtt resource: mqtt
notify_type: qos notify_type: qos
@ -49,7 +52,7 @@ gateway: {
coap.2: { coap.2: {
enable_stats: false enable_stats: false
authenticators: [] authentication.enable:false
heartbeat: 30s heartbeat: 30s
resource: pubsub resource: pubsub
notify_type: non notify_type: non
@ -121,7 +124,7 @@ gateway: {
#ssl.cacertfile: #ssl.cacertfile:
} }
authenticators: [] authentication.enable: false
listener.tcp.1: { listener.tcp.1: {
bind: 7993 bind: 7993

View File

@ -104,10 +104,12 @@ init([Insta, Ctx0, _GwDscrptr]) ->
end. end.
do_init_context(InstaId, RawConf, Ctx) -> do_init_context(InstaId, RawConf, Ctx) ->
Auth = case maps:get(authenticators, RawConf, []) of Auth = case maps:get(authentication, RawConf, #{enable => false}) of
[] -> undefined; #{enable := true,
AuthCfgs when is_list(AuthCfgs) -> authenticators := AuthCfgs} when is_list(AuthCfgs) ->
create_authenticators_for_gateway_insta(InstaId, AuthCfgs) create_authenticators_for_gateway_insta(InstaId, AuthCfgs);
_ ->
undefined
end, end,
Ctx#{auth => Auth}. Ctx#{auth => Auth}.

View File

@ -46,7 +46,7 @@ fields(stomp) ->
fields(stomp_structs) -> fields(stomp_structs) ->
[ {frame, t(ref(stomp_frame))} [ {frame, t(ref(stomp_frame))}
, {clientinfo_override, t(ref(clientinfo_override))} , {clientinfo_override, t(ref(clientinfo_override))}
, {authenticators, fun emqx_authn_schema:authenticators/1} , {authentication, t(ref(authentication))}
, {listener, t(ref(tcp_listener_group))} , {listener, t(ref(tcp_listener_group))}
]; ];
@ -97,7 +97,7 @@ fields(exproto) ->
fields(exproto_structs) -> fields(exproto_structs) ->
[ {server, t(ref(exproto_grpc_server))} [ {server, t(ref(exproto_grpc_server))}
, {handler, t(ref(exproto_grpc_handler))} , {handler, t(ref(exproto_grpc_handler))}
, {authenticators, fun emqx_authn_schema:authenticators/1} , {authentication, t(ref(authentication))}
, {listener, t(ref(udp_tcp_listener_group))} , {listener, t(ref(udp_tcp_listener_group))}
]; ];
@ -111,6 +111,11 @@ fields(exproto_grpc_handler) ->
%% TODO: ssl %% TODO: ssl
]; ];
fields(authentication) ->
[ {enable, #{type => boolean(), default => false}}
, {authenticators, fun emqx_authn_schema:authenticators/1}
];
fields(clientinfo_override) -> fields(clientinfo_override) ->
[ {username, t(string())} [ {username, t(string())}
, {password, t(string())} , {password, t(string())}
@ -209,7 +214,7 @@ fields(coap) ->
fields(coap_structs) -> fields(coap_structs) ->
[ {enable_stats, t(boolean(), undefined, true)} [ {enable_stats, t(boolean(), undefined, true)}
, {authenticators, fun emqx_authn_schema:authenticators/1} , {authentication, t(ref(authentication))}
, {heartbeat, t(duration(), undefined, "15s")} , {heartbeat, t(duration(), undefined, "15s")}
, {resource, t(union([mqtt, pubsub]), undefined, mqtt)} , {resource, t(union([mqtt, pubsub]), undefined, mqtt)}
, {notify_type, t(union([non, con, qos]), undefined, qos)} , {notify_type, t(union([non, con, qos]), undefined, qos)}