chore(gw): add examples for gw&client api
This commit is contained in:
parent
d735e2e755
commit
0eff5358ca
|
@ -80,8 +80,8 @@ gateway(post, Request) ->
|
|||
_ ->
|
||||
GwConf = maps:without([<<"name">>], Body),
|
||||
case emqx_gateway_conf:load_gateway(GwName, GwConf) of
|
||||
ok ->
|
||||
{204};
|
||||
{ok, NGwConf} ->
|
||||
{201, NGwConf};
|
||||
{error, Reason} ->
|
||||
return_http_error(500, Reason)
|
||||
end
|
||||
|
@ -131,8 +131,8 @@ gateway_insta(put, #{body := GwConf,
|
|||
}) ->
|
||||
with_gateway(Name0, fun(GwName, _) ->
|
||||
case emqx_gateway_conf:update_gateway(GwName, GwConf) of
|
||||
ok ->
|
||||
{204};
|
||||
{ok, Gateway} ->
|
||||
{200, Gateway};
|
||||
{error, Reason} ->
|
||||
return_http_error(500, Reason)
|
||||
end
|
||||
|
@ -201,7 +201,7 @@ schema("/gateway/:name/stats") ->
|
|||
|
||||
params_gateway_name_in_path() ->
|
||||
[{name,
|
||||
mk(binary(),
|
||||
mk(string(),
|
||||
#{ in => path
|
||||
, desc => <<"Gateway Name">>
|
||||
})}
|
||||
|
@ -209,7 +209,7 @@ params_gateway_name_in_path() ->
|
|||
|
||||
params_gateway_status_in_qs() ->
|
||||
[{status,
|
||||
mk(binary(),
|
||||
mk(string(),
|
||||
#{ in => query
|
||||
, nullable => true
|
||||
, desc => <<"Gateway Status">>
|
||||
|
@ -270,7 +270,7 @@ fields(Gw) when Gw == stomp; Gw == mqttsn;
|
|||
Gw == coap; Gw == lwm2m;
|
||||
Gw == exproto ->
|
||||
[{name,
|
||||
mk(string(), #{ desc => <<"Gateway Name">>})}
|
||||
mk(hoconsc:union([Gw]), #{ desc => <<"Gateway Name">>})}
|
||||
] ++ convert_listener_struct(emqx_gateway_schema:fields(Gw));
|
||||
fields(Listener) when Listener == tcp_listener;
|
||||
Listener == ssl_listener;
|
||||
|
@ -330,21 +330,130 @@ examples_gateway_confs() ->
|
|||
#{ summary => <<"A simple STOMP gateway configs">>
|
||||
, value =>
|
||||
#{ enable => true
|
||||
, name => <<"stomp">>
|
||||
, enable_stats => true
|
||||
, idle_timeout => <<"30s">>
|
||||
, mountpoint => <<"stomp/">>
|
||||
, frame =>
|
||||
#{ max_header => 10
|
||||
, make_header_length => 1024
|
||||
#{ max_headers => 10
|
||||
, max_headers_length => 1024
|
||||
, max_body_length => 65535
|
||||
}
|
||||
, listeners =>
|
||||
[ #{ type => <<"tcp">>
|
||||
, name => <<"default">>
|
||||
, bind => <<"61613">>
|
||||
, max_connections => 1024000
|
||||
, max_conn_rate => 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
, mqttsn_gateway =>
|
||||
#{ summary => <<"A simple MQTT-SN gateway configs">>
|
||||
, value =>
|
||||
#{ enable => true
|
||||
, name => <<"mqttsn">>
|
||||
, enable_stats => true
|
||||
, idle_timeout => <<"30s">>
|
||||
, mountpoint => <<"mqttsn/">>
|
||||
, gateway_id => 1
|
||||
, broadcast => true
|
||||
, enable_qos3 => true
|
||||
, predefined =>
|
||||
[ #{ id => <<"1001">>
|
||||
, topic => <<"pred/1001">>
|
||||
}
|
||||
, #{ id => <<"1002">>
|
||||
, topic => <<"pred/1002">>
|
||||
}
|
||||
]
|
||||
, listeners =>
|
||||
[ #{ type => <<"udp">>
|
||||
, name => <<"default">>
|
||||
, bind => <<"1884">>
|
||||
, max_connections => 1024000
|
||||
, max_conn_rate => 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
, coap_gateway =>
|
||||
#{ summary => <<"A simple CoAP gateway configs">>
|
||||
, value =>
|
||||
#{ enable => true
|
||||
, name => <<"coap">>
|
||||
, enable_stats => true
|
||||
, idle_timeout => <<"30s">>
|
||||
, mountpoint => <<"coap/">>
|
||||
, heartbeat => <<"30s">>
|
||||
, connection_required => false
|
||||
, notify_type => <<"qos">>
|
||||
, subscribe_qos => <<"coap">>
|
||||
, publish_qos => <<"coap">>
|
||||
, listeners =>
|
||||
[ #{ type => <<"udp">>
|
||||
, name => <<"coap">>
|
||||
, bind => <<"5683">>
|
||||
, max_connections => 1024000
|
||||
, max_conn_rate => 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
, lwm2m_gateway =>
|
||||
#{ summary => <<"A simple LwM2M gateway configs">>
|
||||
, value =>
|
||||
#{ enable => true
|
||||
, name => <<"lwm2m">>
|
||||
, enable_stats => true
|
||||
, idle_timeout => <<"30s">>
|
||||
, mountpoint => <<"lwm2m/">>
|
||||
, xml_dir => <<"etc/lwm2m_xml">>
|
||||
, lifetime_min => <<"1s">>
|
||||
, lifetime_max => <<"86400s">>
|
||||
, qmode_time_window => <<"22s">>
|
||||
, auto_observe => false
|
||||
, update_msg_publish_condition => <<"always">>
|
||||
, translators =>
|
||||
#{ command => #{topic => <<"/dn/#">>}
|
||||
, response => #{topic => <<"/up/resp">>}
|
||||
, notify => #{topic => <<"/up/notify">>}
|
||||
, register => #{topic => <<"/up/resp">>}
|
||||
, update => #{topic => <<"/up/resp">>}
|
||||
}
|
||||
, listeners =>
|
||||
[ #{ type => <<"udp">>
|
||||
, name => <<"lwm2m">>
|
||||
, bind => <<"5783">>
|
||||
, max_connections => 1024000
|
||||
, max_conn_rate => 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
, exproto_gateway =>
|
||||
#{ summary => <<"A simple ExProto gateway configs">>
|
||||
, value =>
|
||||
#{ enable => true
|
||||
, name => <<"exproto">>
|
||||
, enable_stats => true
|
||||
, idle_timeout => <<"30s">>
|
||||
, mountpoint => <<"exproto/">>
|
||||
, server =>
|
||||
#{ bind => <<"9100">>
|
||||
}
|
||||
, handler =>
|
||||
#{ address => <<"http://127.0.0.1:9001">>
|
||||
}
|
||||
, listeners =>
|
||||
[ #{ type => <<"tcp">>
|
||||
, name => <<"default">>
|
||||
, bind => <<"7993">>
|
||||
, max_connections => 1024000
|
||||
, max_conn_rate => 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}.
|
||||
|
|
|
@ -412,10 +412,7 @@ schema("/gateway/:name/clients") ->
|
|||
#{ description => <<"Get the gateway client list">>
|
||||
, parameters => params_client_query()
|
||||
, responses =>
|
||||
?STANDARD_RESP(
|
||||
#{ 200 => emqx_dashboard_swagger:schema_with_examples(
|
||||
hoconsc:array(ref(client)),
|
||||
examples_client_list())})
|
||||
?STANDARD_RESP(#{200 => schema_client_list()})
|
||||
}
|
||||
};
|
||||
schema("/gateway/:name/clients/:clientid") ->
|
||||
|
@ -424,10 +421,7 @@ schema("/gateway/:name/clients/:clientid") ->
|
|||
#{ description => <<"Get the gateway client infomation">>
|
||||
, parameters => params_client_insta()
|
||||
, responses =>
|
||||
?STANDARD_RESP(
|
||||
#{ 200 => emqx_dashboard_swagger:schema_with_examples(
|
||||
ref(client),
|
||||
examples_client())})
|
||||
?STANDARD_RESP(#{200 => schema_client()})
|
||||
}
|
||||
, delete =>
|
||||
#{ description => <<"Kick out the gateway client">>
|
||||
|
@ -443,7 +437,7 @@ schema("/gateway/:name/clients/:clientid/subscriptions") ->
|
|||
, parameters => params_client_insta()
|
||||
, responses =>
|
||||
?STANDARD_RESP(
|
||||
#{ 200 => emqx_dashboard_swagger:schema_with_examples(
|
||||
#{200 => emqx_dashboard_swagger:schema_with_examples(
|
||||
hoconsc:array(ref(subscription)),
|
||||
examples_subsctiption_list())})
|
||||
}
|
||||
|
@ -567,13 +561,85 @@ params_topic_name_in_path() ->
|
|||
%%--------------------------------------------------------------------
|
||||
%% schemas
|
||||
|
||||
schema_client_list() ->
|
||||
emqx_dashboard_swagger:schema_with_examples(
|
||||
hoconsc:union([hoconsc:array(ref(?MODULE, stomp_client)),
|
||||
hoconsc:array(ref(?MODULE, mqttsn_client)),
|
||||
hoconsc:array(ref(?MODULE, coap_client)),
|
||||
hoconsc:array(ref(?MODULE, lwm2m_client)),
|
||||
hoconsc:array(ref(?MODULE, exproto_client))
|
||||
]),
|
||||
examples_client_list()
|
||||
).
|
||||
|
||||
schema_client() ->
|
||||
emqx_dashboard_swagger:schema_with_examples(
|
||||
hoconsc:union([ref(?MODULE, stomp_client),
|
||||
ref(?MODULE, mqttsn_client),
|
||||
ref(?MODULE, coap_client),
|
||||
ref(?MODULE, lwm2m_client),
|
||||
ref(?MODULE, exproto_client)
|
||||
]),
|
||||
examples_client()
|
||||
).
|
||||
|
||||
roots() ->
|
||||
[ client
|
||||
[ stomp_client
|
||||
, mqttsn_client
|
||||
, coap_client
|
||||
, lwm2m_client
|
||||
, exproto_client
|
||||
, subscription
|
||||
].
|
||||
|
||||
fields(client) ->
|
||||
%% XXX: enum for every protocol's client
|
||||
fields(test) ->
|
||||
[{key, mk(string(), #{ desc => <<"Desc">>})}];
|
||||
|
||||
fields(stomp_client) ->
|
||||
common_client_props();
|
||||
fields(mqttsn_client) ->
|
||||
common_client_props();
|
||||
fields(coap_client) ->
|
||||
common_client_props();
|
||||
fields(lwm2m_client) ->
|
||||
[ {endpoint_name,
|
||||
mk(string(),
|
||||
#{ desc => <<"The LwM2M client endpoint name">>})}
|
||||
, {lifetime,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Life time">>})}
|
||||
] ++ common_client_props();
|
||||
fields(exproto_client) ->
|
||||
common_client_props();
|
||||
|
||||
fields(subscription) ->
|
||||
[ {topic,
|
||||
mk(string(),
|
||||
#{ desc => <<"Topic Fillter">>})}
|
||||
, {qos,
|
||||
mk(integer(),
|
||||
#{ desc => <<"QoS level, enum: 0, 1, 2">>})}
|
||||
, {nl,
|
||||
mk(integer(), %% FIXME: why not boolean?
|
||||
#{ desc => <<"No Local option, enum: 0, 1">>})}
|
||||
, {rap,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Retain as Published option, enum: 0, 1">>})}
|
||||
, {rh,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Retain Handling option, enum: 0, 1, 2">>})}
|
||||
, {sub_props,
|
||||
mk(ref(extra_sub_props),
|
||||
#{desc => <<"Subscription properties">>})}
|
||||
];
|
||||
fields(extra_sub_props) ->
|
||||
[ {subid,
|
||||
mk(string(),
|
||||
#{ desc => <<"Only stomp protocol, an uniquely identity for "
|
||||
"the subscription. range: 1-65535.">>})}
|
||||
].
|
||||
|
||||
common_client_props() ->
|
||||
[ {node,
|
||||
mk(string(),
|
||||
#{ desc => <<"Name of the node to which the client is "
|
||||
|
@ -699,45 +765,114 @@ fields(client) ->
|
|||
, {reductions,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Erlang reduction">>})}
|
||||
];
|
||||
fields(subscription) ->
|
||||
[ {topic,
|
||||
mk(string(),
|
||||
#{ desc => <<"Topic Fillter">>})}
|
||||
, {qos,
|
||||
mk(integer(),
|
||||
#{ desc => <<"QoS level, enum: 0, 1, 2">>})}
|
||||
, {nl,
|
||||
mk(integer(), %% FIXME: why not boolean?
|
||||
#{ desc => <<"No Local option, enum: 0, 1">>})}
|
||||
, {rap,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Retain as Published option, enum: 0, 1">>})}
|
||||
, {rh,
|
||||
mk(integer(),
|
||||
#{ desc => <<"Retain Handling option, enum: 0, 1, 2">>})}
|
||||
, {sub_props,
|
||||
mk(ref(extra_sub_props),
|
||||
#{desc => <<"Subscription properties">>})}
|
||||
];
|
||||
fields(extra_sub_props) ->
|
||||
[ {subid,
|
||||
mk(string(),
|
||||
#{ desc => <<"Only stomp protocol, an uniquely identity for "
|
||||
"the subscription. range: 1-65535.">>})}
|
||||
].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% examples
|
||||
|
||||
examples_client_list() ->
|
||||
#{}.
|
||||
#{ general_client_list =>
|
||||
#{ summary => <<"General Client List">>
|
||||
, value => [example_general_client()]
|
||||
}
|
||||
, lwm2m_client_list =>
|
||||
#{ summary => <<"LwM2M Client List">>
|
||||
, value => [example_lwm2m_client()]
|
||||
}
|
||||
}.
|
||||
|
||||
examples_client() ->
|
||||
#{}.
|
||||
#{ general_client =>
|
||||
#{ summary => <<"General Client Info">>
|
||||
, value => example_general_client()
|
||||
}
|
||||
, lwm2m_client =>
|
||||
#{ summary => <<"LwM2M Client Info">>
|
||||
, value => example_lwm2m_client()
|
||||
}
|
||||
}.
|
||||
|
||||
examples_subsctiption_list() ->
|
||||
#{}.
|
||||
#{ general_subscription_list =>
|
||||
#{ summary => <<"A General Subscription List">>
|
||||
, value => [example_general_subscription()]
|
||||
}
|
||||
, stomp_subscription_list =>
|
||||
#{ summary => <<"The Stomp Subscription List">>
|
||||
, value => [example_stomp_subscription]
|
||||
}
|
||||
}.
|
||||
|
||||
examples_subsctiption() ->
|
||||
#{}.
|
||||
#{ general_subscription =>
|
||||
#{ summary => <<"A General Subscription">>
|
||||
, value => example_general_subscription()
|
||||
}
|
||||
, stomp_subscription =>
|
||||
#{ summary => <<"A Stomp Subscription">>
|
||||
, value => example_stomp_subscription()
|
||||
}
|
||||
}.
|
||||
|
||||
example_lwm2m_client() ->
|
||||
maps:merge(
|
||||
example_general_client(),
|
||||
#{ proto_name => <<"LwM2M">>
|
||||
, proto_ver => <<"1.0">>
|
||||
, endpoint_name => <<"urn:imei:154928475237123">>
|
||||
, lifetime => 86400
|
||||
}).
|
||||
|
||||
example_general_client() ->
|
||||
#{ clientid => <<"MzAyMzEzNTUwNzk1NDA1MzYyMzIwNzUxNjQwMTY1NzQ0NjE">>
|
||||
, username => <<"guest">>
|
||||
, node => <<"emqx@127.0.0.1">>
|
||||
, proto_name => "STOMP"
|
||||
, proto_ver => <<"1.0">>
|
||||
, ip_address => <<"127.0.0.1">>
|
||||
, port => 50675
|
||||
, clean_start => true
|
||||
, connected => true
|
||||
, is_bridge => false
|
||||
, keepalive => 0
|
||||
, expiry_interval => 0
|
||||
, subscriptions_cnt => 0
|
||||
, subscriptions_max => <<"infinity">>
|
||||
, awaiting_rel_cnt => 0
|
||||
, awaiting_rel_max => <<"infinity">>
|
||||
, mqueue_len => 0
|
||||
, mqueue_max => <<"infinity">>
|
||||
, mqueue_dropped => 0
|
||||
, inflight_cnt => 0
|
||||
, inflight_max => <<"infinity">>
|
||||
, heap_size => 4185
|
||||
, recv_oct => 56
|
||||
, recv_cnt => 1
|
||||
, recv_pkt => 1
|
||||
, recv_msg => 0
|
||||
, send_oct => 61
|
||||
, send_cnt => 1
|
||||
, send_pkt => 1
|
||||
, send_msg => 0
|
||||
, reductions => 72022
|
||||
, mailbox_len => 0
|
||||
, created_at => <<"2021-12-07T10:44:02.721+08:00">>
|
||||
, connected_at => <<"2021-12-07T10:44:02.721+08:00">>
|
||||
, disconnected_at => null
|
||||
}.
|
||||
|
||||
example_stomp_subscription() ->
|
||||
maps:merge(
|
||||
example_general_subscription(),
|
||||
#{ topic => <<"stomp/topic">>
|
||||
, sub_props => #{subid => <<"10">>}
|
||||
}).
|
||||
|
||||
example_general_subscription() ->
|
||||
#{ topic => <<"test/topic">>
|
||||
, qos => 1
|
||||
, nl => 0
|
||||
, rap => 0
|
||||
, rh => 0
|
||||
, sub_props => #{}
|
||||
}.
|
||||
|
|
|
@ -79,15 +79,14 @@ unload() ->
|
|||
%%--------------------------------------------------------------------
|
||||
%% APIs
|
||||
|
||||
-spec load_gateway(atom_or_bin(), map()) -> ok_or_err().
|
||||
-spec load_gateway(atom_or_bin(), map()) -> map_or_err().
|
||||
load_gateway(GwName, Conf) ->
|
||||
NConf = case maps:take(<<"listeners">>, Conf) of
|
||||
error -> Conf;
|
||||
{Ls, Conf1} ->
|
||||
Conf1#{<<"listeners">> => unconvert_listeners(Ls)}
|
||||
end,
|
||||
%% TODO:
|
||||
ret_ok_err(update({?FUNCTION_NAME, bin(GwName), NConf})).
|
||||
ret_gw(GwName, update({?FUNCTION_NAME, bin(GwName), NConf})).
|
||||
|
||||
%% @doc convert listener array to map
|
||||
unconvert_listeners(Ls) when is_list(Ls) ->
|
||||
|
@ -108,13 +107,12 @@ maps_key_take([K | Ks], M, Acc) ->
|
|||
maps_key_take(Ks, M1, [V | Acc])
|
||||
end.
|
||||
|
||||
-spec update_gateway(atom_or_bin(), map()) -> ok_or_err().
|
||||
-spec update_gateway(atom_or_bin(), map()) -> map_or_err().
|
||||
update_gateway(GwName, Conf0) ->
|
||||
Exclude0 = [listeners, ?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME_ATOM],
|
||||
Exclude1 = [atom_to_binary(K, utf8) || K <- Exclude0],
|
||||
Conf = maps:without(Exclude0 ++ Exclude1, Conf0),
|
||||
|
||||
ret_ok_err(update({?FUNCTION_NAME, bin(GwName), Conf})).
|
||||
ret_gw(GwName, update({?FUNCTION_NAME, bin(GwName), Conf})).
|
||||
|
||||
%% FIXME: delete cert files ??
|
||||
|
||||
|
@ -261,6 +259,22 @@ bin(B) when is_binary(B) ->
|
|||
ret_ok_err({ok, _}) -> ok;
|
||||
ret_ok_err(Err) -> Err.
|
||||
|
||||
ret_gw(GwName, {ok, #{raw_config := GwConf}}) ->
|
||||
GwConf1 = emqx_map_lib:deep_get([bin(GwName)], GwConf),
|
||||
LsConf = emqx_map_lib:deep_get(
|
||||
[bin(GwName), <<"listeners">>],
|
||||
GwConf, #{}),
|
||||
NLsConf =
|
||||
lists:foldl(fun({LType, SubConf}, Acc) ->
|
||||
NLConfs =
|
||||
lists:map(fun({LName, LConf}) ->
|
||||
do_convert_listener2(GwName, LType, LName, LConf)
|
||||
end, proplists:from_map(SubConf)),
|
||||
[NLConfs|Acc]
|
||||
end, [], proplists:from_map(LsConf)),
|
||||
{ok, maps:merge(GwConf1, #{<<"listeners">> => NLsConf})};
|
||||
ret_gw(_GwName, Err) -> Err.
|
||||
|
||||
ret_authn(GwName, {ok, #{raw_config := GwConf}}) ->
|
||||
Authn = emqx_map_lib:deep_get(
|
||||
[bin(GwName), <<"authentication">>],
|
||||
|
|
|
@ -221,7 +221,7 @@ fields(lwm2m) ->
|
|||
})}
|
||||
, {lifetime_min,
|
||||
sc(duration(),
|
||||
#{ default => "1s"
|
||||
#{ default => "15s"
|
||||
, desc => "Minimum value of lifetime allowed to be set by the LwM2M client"
|
||||
})}
|
||||
, {lifetime_max,
|
||||
|
|
|
@ -59,7 +59,7 @@ t_gateway(_) ->
|
|||
lists:foreach(fun assert_gw_unloaded/1, Gateways),
|
||||
{400, BadReq} = request(get, "/gateway/uname_gateway"),
|
||||
assert_bad_request(BadReq),
|
||||
{204, _} = request(post, "/gateway", #{name => <<"stomp">>}),
|
||||
{201, _} = request(post, "/gateway", #{name => <<"stomp">>}),
|
||||
{200, StompGw1} = request(get, "/gateway/stomp"),
|
||||
assert_feilds_apperence([name, status, enable, created_at, started_at],
|
||||
StompGw1),
|
||||
|
@ -81,12 +81,12 @@ t_gateway_stomp(_) ->
|
|||
#{name => <<"def">>, type => <<"tcp">>, bind => <<"61613">>}
|
||||
]
|
||||
},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/stomp"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
%% put
|
||||
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{frame => #{max_headers => 10}}),
|
||||
{204, _} = request(put, "/gateway/stomp", maps:without([name], GwConf2)),
|
||||
{200, _} = request(put, "/gateway/stomp", maps:without([name], GwConf2)),
|
||||
{200, ConfResp2} = request(get, "/gateway/stomp"),
|
||||
assert_confs(GwConf2, ConfResp2),
|
||||
{204, _} = request(delete, "/gateway/stomp").
|
||||
|
@ -104,12 +104,12 @@ t_gateway_mqttsn(_) ->
|
|||
#{name => <<"def">>, type => <<"udp">>, bind => <<"1884">>}
|
||||
]
|
||||
},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/mqttsn"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
%% put
|
||||
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{predefined => []}),
|
||||
{204, _} = request(put, "/gateway/mqttsn", maps:without([name], GwConf2)),
|
||||
{200, _} = request(put, "/gateway/mqttsn", maps:without([name], GwConf2)),
|
||||
{200, ConfResp2} = request(get, "/gateway/mqttsn"),
|
||||
assert_confs(GwConf2, ConfResp2),
|
||||
{204, _} = request(delete, "/gateway/mqttsn").
|
||||
|
@ -125,12 +125,12 @@ t_gateway_coap(_) ->
|
|||
#{name => <<"def">>, type => <<"udp">>, bind => <<"5683">>}
|
||||
]
|
||||
},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/coap"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
%% put
|
||||
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{heartbeat => <<"10s">>}),
|
||||
{204, _} = request(put, "/gateway/coap", maps:without([name], GwConf2)),
|
||||
{200, _} = request(put, "/gateway/coap", maps:without([name], GwConf2)),
|
||||
{200, ConfResp2} = request(get, "/gateway/coap"),
|
||||
assert_confs(GwConf2, ConfResp2),
|
||||
{204, _} = request(delete, "/gateway/coap").
|
||||
|
@ -156,12 +156,12 @@ t_gateway_lwm2m(_) ->
|
|||
#{name => <<"def">>, type => <<"udp">>, bind => <<"5783">>}
|
||||
]
|
||||
},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/lwm2m"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
%% put
|
||||
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{qmode_time_window => <<"10s">>}),
|
||||
{204, _} = request(put, "/gateway/lwm2m", maps:without([name], GwConf2)),
|
||||
{200, _} = request(put, "/gateway/lwm2m", maps:without([name], GwConf2)),
|
||||
{200, ConfResp2} = request(get, "/gateway/lwm2m"),
|
||||
assert_confs(GwConf2, ConfResp2),
|
||||
{204, _} = request(delete, "/gateway/lwm2m").
|
||||
|
@ -177,19 +177,19 @@ t_gateway_exproto(_) ->
|
|||
#{name => <<"def">>, type => <<"tcp">>, bind => <<"7993">>}
|
||||
]
|
||||
},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/exproto"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
%% put
|
||||
GwConf2 = emqx_map_lib:deep_merge(GwConf, #{server => #{bind => <<"9200">>}}),
|
||||
{204, _} = request(put, "/gateway/exproto", maps:without([name], GwConf2)),
|
||||
{200, _} = request(put, "/gateway/exproto", maps:without([name], GwConf2)),
|
||||
{200, ConfResp2} = request(get, "/gateway/exproto"),
|
||||
assert_confs(GwConf2, ConfResp2),
|
||||
{204, _} = request(delete, "/gateway/exproto").
|
||||
|
||||
t_authn(_) ->
|
||||
GwConf = #{name => <<"stomp">>},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{204, _} = request(get, "/gateway/stomp/authentication"),
|
||||
|
||||
AuthConf = #{mechanism => <<"password-based">>,
|
||||
|
@ -212,7 +212,7 @@ t_authn(_) ->
|
|||
|
||||
t_authn_data_mgmt(_) ->
|
||||
GwConf = #{name => <<"stomp">>},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{204, _} = request(get, "/gateway/stomp/authentication"),
|
||||
|
||||
AuthConf = #{mechanism => <<"password-based">>,
|
||||
|
@ -256,7 +256,7 @@ t_authn_data_mgmt(_) ->
|
|||
|
||||
t_listeners(_) ->
|
||||
GwConf = #{name => <<"stomp">>},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{404, _} = request(get, "/gateway/stomp/listeners"),
|
||||
LisConf = #{name => <<"def">>,
|
||||
type => <<"tcp">>,
|
||||
|
@ -289,7 +289,7 @@ t_listeners_authn(_) ->
|
|||
type => <<"tcp">>,
|
||||
bind => <<"61613">>
|
||||
}]},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/stomp"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
|
||||
|
@ -316,7 +316,7 @@ t_listeners_authn_data_mgmt(_) ->
|
|||
type => <<"tcp">>,
|
||||
bind => <<"61613">>
|
||||
}]},
|
||||
{204, _} = request(post, "/gateway", GwConf),
|
||||
{201, _} = request(post, "/gateway", GwConf),
|
||||
{200, ConfResp} = request(get, "/gateway/stomp"),
|
||||
assert_confs(GwConf, ConfResp),
|
||||
|
||||
|
|
|
@ -244,12 +244,12 @@ t_load_unload_gateway(_) ->
|
|||
StompConf2 = compose(?CONF_STOMP_BAISC_2,
|
||||
?CONF_STOMP_AUTHN_1,
|
||||
?CONF_STOMP_LISTENER_1),
|
||||
ok = emqx_gateway_conf:load_gateway(stomp, StompConf1),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(stomp, StompConf1),
|
||||
{error, already_exist} =
|
||||
emqx_gateway_conf:load_gateway(stomp, StompConf1),
|
||||
assert_confs(StompConf1, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
ok = emqx_gateway_conf:update_gateway(stomp, StompConf2),
|
||||
{ok, _} = emqx_gateway_conf:update_gateway(stomp, StompConf2),
|
||||
assert_confs(StompConf2, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
ok = emqx_gateway_conf:unload_gateway(stomp),
|
||||
|
@ -265,7 +265,7 @@ t_load_unload_gateway(_) ->
|
|||
t_load_remove_authn(_) ->
|
||||
StompConf = compose_listener(?CONF_STOMP_BAISC_1, ?CONF_STOMP_LISTENER_1),
|
||||
|
||||
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
{ok, _} = emqx_gateway_conf:add_authn(<<"stomp">>, ?CONF_STOMP_AUTHN_1),
|
||||
|
@ -292,7 +292,7 @@ t_load_remove_authn(_) ->
|
|||
t_load_remove_listeners(_) ->
|
||||
StompConf = compose_authn(?CONF_STOMP_BAISC_1, ?CONF_STOMP_AUTHN_1),
|
||||
|
||||
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
{ok, _} = emqx_gateway_conf:add_listener(
|
||||
|
@ -338,7 +338,7 @@ t_load_remove_listener_authn(_) ->
|
|||
?CONF_STOMP_AUTHN_2
|
||||
),
|
||||
|
||||
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
{ok, _} = emqx_gateway_conf:add_authn(
|
||||
|
@ -368,7 +368,7 @@ t_load_gateway_with_certs_content(_) ->
|
|||
?CONF_STOMP_BAISC_1,
|
||||
?CONF_STOMP_LISTENER_SSL
|
||||
),
|
||||
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
SslConf = emqx_map_lib:deep_get(
|
||||
[<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl">>],
|
||||
|
@ -388,7 +388,7 @@ t_load_gateway_with_certs_content(_) ->
|
|||
% ?CONF_STOMP_BAISC_1,
|
||||
% ?CONF_STOMP_LISTENER_SSL_PATH
|
||||
% ),
|
||||
% ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
% {ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
% assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
% SslConf = emqx_map_lib:deep_get(
|
||||
% [<<"listeners">>, <<"ssl">>, <<"default">>, <<"ssl">>],
|
||||
|
@ -402,7 +402,7 @@ t_load_gateway_with_certs_content(_) ->
|
|||
|
||||
t_add_listener_with_certs_content(_) ->
|
||||
StompConf = ?CONF_STOMP_BAISC_1,
|
||||
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
{ok, _} = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
|
||||
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
|
||||
|
||||
{ok, _} = emqx_gateway_conf:add_listener(
|
||||
|
|
Loading…
Reference in New Issue