fix(gw_jt808): split anonymous true/false conf schema
This commit is contained in:
parent
a5978aa39a
commit
1e9c978f36
|
@ -16,7 +16,7 @@
|
|||
|
||||
init(#{allow_anonymous := true}) ->
|
||||
#auth{registry = undefined, authentication = undefined, allow_anonymous = true};
|
||||
init(#{registry := Reg, authentication := Auth, allow_anonymous := Anonymous}) ->
|
||||
init(#{allow_anonymous := Anonymous = false, registry := Reg, authentication := Auth}) ->
|
||||
#auth{registry = Reg, authentication = Auth, allow_anonymous = Anonymous}.
|
||||
|
||||
register(_RegFrame, #auth{registry = undefined, allow_anonymous = true}) ->
|
||||
|
|
|
@ -153,7 +153,7 @@ init(
|
|||
Options = #{
|
||||
ctx := Ctx,
|
||||
message_queue_len := MessageQueueLen,
|
||||
proto := ProtoConf
|
||||
proto := #{auth := Auth} = ProtoConf
|
||||
}
|
||||
) ->
|
||||
% TODO: init rsa_key from user input
|
||||
|
@ -193,7 +193,7 @@ init(
|
|||
% TODO: init rsa_key from user input
|
||||
dn_topic = maps:get(dn_topic, ProtoConf, ?DEFAULT_DN_TOPIC),
|
||||
up_topic = maps:get(up_topic, ProtoConf, ?DEFAULT_UP_TOPIC),
|
||||
auth = emqx_jt808_auth:init(ProtoConf),
|
||||
auth = emqx_jt808_auth:init(Auth),
|
||||
inflight = emqx_inflight:new(128),
|
||||
mqueue = queue:new(),
|
||||
max_mqueue_len = MessageQueueLen,
|
||||
|
|
|
@ -49,24 +49,38 @@ fields(jt808_frame) ->
|
|||
];
|
||||
fields(jt808_proto) ->
|
||||
[
|
||||
{allow_anonymous, fun allow_anonymous/1},
|
||||
{registry, fun registry_url/1},
|
||||
{authentication, fun authentication_url/1},
|
||||
{auth,
|
||||
sc(
|
||||
hoconsc:union([
|
||||
ref(anonymous_true), ref(anonymous_false)
|
||||
])
|
||||
)},
|
||||
{up_topic, fun up_topic/1},
|
||||
{dn_topic, fun dn_topic/1}
|
||||
];
|
||||
fields(anonymous_true) ->
|
||||
[
|
||||
{allow_anonymous,
|
||||
sc(hoconsc:union([true]), #{desc => ?DESC(allow_anonymous), required => true})}
|
||||
];
|
||||
fields(anonymous_false) ->
|
||||
[
|
||||
{allow_anonymous,
|
||||
sc(hoconsc:union([false]), #{desc => ?DESC(allow_anonymous), required => true})},
|
||||
{registry, fun registry_url/1},
|
||||
{authentication, fun authentication_url/1}
|
||||
].
|
||||
|
||||
jt808_frame_max_length(type) -> non_neg_integer();
|
||||
jt808_frame_max_length(desc) -> ?DESC(?FUNCTION_NAME);
|
||||
jt808_frame_max_length(default) -> 8192;
|
||||
jt808_frame_max_length(required) -> false;
|
||||
jt808_frame_max_length(_) -> undefined.
|
||||
|
||||
allow_anonymous(type) -> boolean();
|
||||
allow_anonymous(desc) -> ?DESC(?FUNCTION_NAME);
|
||||
allow_anonymous(default) -> true;
|
||||
allow_anonymous(required) -> false;
|
||||
allow_anonymous(_) -> undefined.
|
||||
jt808_frame_max_length(type) ->
|
||||
non_neg_integer();
|
||||
jt808_frame_max_length(desc) ->
|
||||
?DESC(?FUNCTION_NAME);
|
||||
jt808_frame_max_length(default) ->
|
||||
8192;
|
||||
jt808_frame_max_length(required) ->
|
||||
false;
|
||||
jt808_frame_max_length(_) ->
|
||||
undefined.
|
||||
|
||||
registry_url(type) -> binary();
|
||||
registry_url(desc) -> ?DESC(?FUNCTION_NAME);
|
||||
|
|
|
@ -38,43 +38,35 @@
|
|||
%% <<"jt808/000123456789/000123456789/dn">>
|
||||
-define(JT808_DN_TOPIC, <<?JT808_MOUNTPOINT, ?JT808_PHONE, "/dn">>).
|
||||
|
||||
-define(CONF_DEFAULT, <<
|
||||
"\n"
|
||||
"gateway.jt808 {\n"
|
||||
" listeners.tcp.default {\n"
|
||||
" bind = "
|
||||
?PORT_STR
|
||||
"\n"
|
||||
" }\n"
|
||||
" proto {\n"
|
||||
" allow_anonymous = false\n"
|
||||
" registry = "
|
||||
"\""
|
||||
?PROTO_REG_SERVER_HOST
|
||||
?PROTO_REG_REGISTRY_PATH
|
||||
"\"\n"
|
||||
" authentication = "
|
||||
"\""
|
||||
?PROTO_REG_SERVER_HOST
|
||||
?PROTO_REG_AUTH_PATH
|
||||
"\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
>>).
|
||||
%% erlfmt-ignore
|
||||
-define(CONF_DEFAULT, <<"
|
||||
gateway.jt808 {
|
||||
listeners.tcp.default {
|
||||
bind = ", ?PORT_STR, "
|
||||
}
|
||||
proto {
|
||||
auth {
|
||||
allow_anonymous = false
|
||||
registry = \"", ?PROTO_REG_SERVER_HOST, ?PROTO_REG_REGISTRY_PATH, "\"
|
||||
authentication = \"", ?PROTO_REG_SERVER_HOST, ?PROTO_REG_AUTH_PATH, "\"
|
||||
}
|
||||
}
|
||||
}
|
||||
">>).
|
||||
|
||||
-define(CONF_ANONYMOUS, <<
|
||||
"\n"
|
||||
"gateway.jt808 {\n"
|
||||
" listeners.tcp.default {\n"
|
||||
" bind = "
|
||||
?PORT_STR
|
||||
"\n"
|
||||
" }\n"
|
||||
" proto {\n"
|
||||
" allow_anonymous = true\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
>>).
|
||||
%% erlfmt-ignore
|
||||
-define(CONF_ANONYMOUS, <<"
|
||||
gateway.jt808 {
|
||||
listeners.tcp.default {
|
||||
bind = ", ?PORT_STR, "
|
||||
}
|
||||
proto {
|
||||
auth {
|
||||
allow_anonymous = true
|
||||
}
|
||||
}
|
||||
}
|
||||
">>).
|
||||
|
||||
all() ->
|
||||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
|
Loading…
Reference in New Issue