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