fix: generate ggateway api response code
This commit is contained in:
parent
74e6fa5a94
commit
15b8203ac1
|
@ -87,19 +87,19 @@ request_parameters() ->
|
||||||
[{clientid, mk(binary(), #{in => path, required => true})}].
|
[{clientid, mk(binary(), #{in => path, required => true})}].
|
||||||
|
|
||||||
request_body() ->
|
request_body() ->
|
||||||
[ {token, mk(binary(), #{desc => "message token, can be empty"})}
|
[ {token, mk(binary(), #{description => "message token, can be empty"})}
|
||||||
, {method, mk(enum([get, put, post, delete]), #{desc => "request method type"})}
|
, {method, mk(enum([get, put, post, delete]), #{description => "request method type"})}
|
||||||
, {timeout, mk(emqx_schema:duration_ms(), #{desc => "timespan for response"})}
|
, {timeout, mk(emqx_schema:duration_ms(), #{description => "timespan for response"})}
|
||||||
, {content_type, mk(enum(['text/plain', 'application/json', 'application/octet-stream']),
|
, {content_type, mk(enum(['text/plain', 'application/json', 'application/octet-stream']),
|
||||||
#{desc => "payload type"})}
|
#{description => "payload type"})}
|
||||||
, {payload, mk(binary(), #{desc => "the content of the payload"})}
|
, {payload, mk(binary(), #{description => "the content of the payload"})}
|
||||||
].
|
].
|
||||||
|
|
||||||
coap_message() ->
|
coap_message() ->
|
||||||
[ {id, mk(integer(), #{desc => "message id"})}
|
[ {id, mk(integer(), #{description => "message id"})}
|
||||||
, {token, mk(string(), #{desc => "message token, can be empty"})}
|
, {token, mk(string(), #{description => "message token, can be empty"})}
|
||||||
, {method, mk(string(), #{desc => "response code"})}
|
, {method, mk(string(), #{description => "response code"})}
|
||||||
, {payload, mk(string(), #{desc => "payload"})}
|
, {payload, mk(string(), #{description => "payload"})}
|
||||||
].
|
].
|
||||||
|
|
||||||
format_to_response(ContentType, #coap_message{id = Id,
|
format_to_response(ContentType, #coap_message{id = Id,
|
||||||
|
|
|
@ -141,7 +141,7 @@ gateway_insta(put, #{body := GwConf0,
|
||||||
end).
|
end).
|
||||||
|
|
||||||
gateway_insta_stats(get, _Req) ->
|
gateway_insta_stats(get, _Req) ->
|
||||||
return_http_error(401, "Implement it later (maybe 5.1)").
|
return_http_error(409, "Implement it later (maybe 5.1)").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Swagger defines
|
%% Swagger defines
|
||||||
|
@ -197,7 +197,9 @@ schema("/gateway/:name/stats") ->
|
||||||
?STANDARD_RESP(
|
?STANDARD_RESP(
|
||||||
#{200 => emqx_dashboard_swagger:schema_with_examples(
|
#{200 => emqx_dashboard_swagger:schema_with_examples(
|
||||||
ref(gateway_stats),
|
ref(gateway_stats),
|
||||||
examples_gateway_stats())
|
examples_gateway_stats()),
|
||||||
|
409 => emqx_dashboard_swagger:error_codes(
|
||||||
|
['NOT_SUPPORT'], <<"Resource not support">>)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}.
|
}.
|
||||||
|
@ -209,7 +211,7 @@ params_gateway_name_in_path() ->
|
||||||
[{name,
|
[{name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Gateway Name">>
|
, description => <<"Gateway Name">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -220,7 +222,7 @@ params_gateway_status_in_qs() ->
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Gateway Status">>
|
, description => <<"Gateway Status">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -236,50 +238,50 @@ roots() ->
|
||||||
fields(gateway_overview) ->
|
fields(gateway_overview) ->
|
||||||
[ {name,
|
[ {name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Gateway Name">>})}
|
#{ description => <<"Gateway Name">>})}
|
||||||
, {status,
|
, {status,
|
||||||
mk(hoconsc:enum([running, stopped, unloaded]),
|
mk(hoconsc:enum([running, stopped, unloaded]),
|
||||||
#{ desc => <<"The Gateway status">>})}
|
#{ description => <<"The Gateway status">>})}
|
||||||
, {created_at,
|
, {created_at,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{desc => <<"The Gateway created datetime">>})}
|
#{description => <<"The Gateway created datetime">>})}
|
||||||
, {started_at,
|
, {started_at,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"The Gateway started datetime">>})}
|
, description => <<"The Gateway started datetime">>})}
|
||||||
, {stopped_at,
|
, {stopped_at,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"The Gateway stopped datetime">>})}
|
, description => <<"The Gateway stopped datetime">>})}
|
||||||
, {max_connections,
|
, {max_connections,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"The Gateway allowed maximum connections/clients">>})}
|
#{ description => <<"The Gateway allowed maximum connections/clients">>})}
|
||||||
, {current_connections,
|
, {current_connections,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"The Gateway current connected connections/clients">>
|
#{ description => <<"The Gateway current connected connections/clients">>
|
||||||
})}
|
})}
|
||||||
, {listeners,
|
, {listeners,
|
||||||
mk(hoconsc:array(ref(gateway_listener_overview)),
|
mk(hoconsc:array(ref(gateway_listener_overview)),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The Gateway listeners overview">>})}
|
, description => <<"The Gateway listeners overview">>})}
|
||||||
];
|
];
|
||||||
fields(gateway_listener_overview) ->
|
fields(gateway_listener_overview) ->
|
||||||
[ {id,
|
[ {id,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Listener ID">>})}
|
#{ description => <<"Listener ID">>})}
|
||||||
, {running,
|
, {running,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ desc => <<"Listener Running status">>})}
|
#{ description => <<"Listener Running status">>})}
|
||||||
, {type,
|
, {type,
|
||||||
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
|
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
|
||||||
#{ desc => <<"Listener Type">>})}
|
#{ description => <<"Listener Type">>})}
|
||||||
];
|
];
|
||||||
|
|
||||||
fields(Gw) when Gw == stomp; Gw == mqttsn;
|
fields(Gw) when Gw == stomp; Gw == mqttsn;
|
||||||
Gw == coap; Gw == lwm2m;
|
Gw == coap; Gw == lwm2m;
|
||||||
Gw == exproto ->
|
Gw == exproto ->
|
||||||
[{name,
|
[{name,
|
||||||
mk(hoconsc:union([Gw]), #{ desc => <<"Gateway Name">>})}
|
mk(hoconsc:union([Gw]), #{ description => <<"Gateway Name">>})}
|
||||||
] ++ convert_listener_struct(emqx_gateway_schema:fields(Gw));
|
] ++ convert_listener_struct(emqx_gateway_schema:fields(Gw));
|
||||||
|
|
||||||
fields(Gw) when Gw == update_stomp; Gw == update_mqttsn;
|
fields(Gw) when Gw == update_stomp; Gw == update_mqttsn;
|
||||||
|
@ -296,17 +298,17 @@ fields(Listener) when Listener == tcp_listener;
|
||||||
[ {id,
|
[ {id,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener ID">>})}
|
, description => <<"Listener ID">>})}
|
||||||
, {type,
|
, {type,
|
||||||
mk(hoconsc:union([tcp, ssl, udp, dtls]),
|
mk(hoconsc:union([tcp, ssl, udp, dtls]),
|
||||||
#{ desc => <<"Listener type">>})}
|
#{ description => <<"Listener type">>})}
|
||||||
, {name,
|
, {name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Listener Name">>})}
|
#{ description => <<"Listener Name">>})}
|
||||||
, {running,
|
, {running,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener running status">>})}
|
, description => <<"Listener running status">>})}
|
||||||
] ++ emqx_gateway_schema:fields(Listener);
|
] ++ emqx_gateway_schema:fields(Listener);
|
||||||
|
|
||||||
fields(gateway_stats) ->
|
fields(gateway_stats) ->
|
||||||
|
@ -335,7 +337,7 @@ convert_listener_struct(Schema) ->
|
||||||
#{type := Type}}, Schema1} = lists:keytake(listeners, 1, Schema),
|
#{type := Type}}, Schema1} = lists:keytake(listeners, 1, Schema),
|
||||||
ListenerSchema = hoconsc:mk(listeners_schema(Type),
|
ListenerSchema = hoconsc:mk(listeners_schema(Type),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The gateway listeners">>
|
, description => <<"The gateway listeners">>
|
||||||
}),
|
}),
|
||||||
lists:keystore(listeners, 1, Schema1, {listeners, ListenerSchema}).
|
lists:keystore(listeners, 1, Schema1, {listeners, ListenerSchema}).
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ params_gateway_name_in_path() ->
|
||||||
[{name,
|
[{name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Gateway Name">>
|
, description => <<"Gateway Name">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -283,7 +283,7 @@ params_gateway_name_in_path() ->
|
||||||
params_userid_in_path() ->
|
params_userid_in_path() ->
|
||||||
[{uid, mk(binary(),
|
[{uid, mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"User ID">>
|
, description => <<"User ID">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -292,13 +292,13 @@ params_paging_in_qs() ->
|
||||||
[{page, mk(integer(),
|
[{page, mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Page Index">>
|
, description => <<"Page Index">>
|
||||||
, example => 1
|
, example => 1
|
||||||
})},
|
})},
|
||||||
{limit, mk(integer(),
|
{limit, mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Page Limit">>
|
, description => <<"Page Limit">>
|
||||||
, example => 100
|
, example => 100
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -308,14 +308,14 @@ params_fuzzy_in_qs() ->
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Fuzzy search by username">>
|
, description => <<"Fuzzy search by username">>
|
||||||
, example => <<"username">>
|
, example => <<"username">>
|
||||||
})},
|
})},
|
||||||
{like_clientid,
|
{like_clientid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Fuzzy search by clientid">>
|
, description => <<"Fuzzy search by clientid">>
|
||||||
, example => <<"clientid">>
|
, example => <<"clientid">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
|
@ -471,60 +471,60 @@ params_client_searching_in_qs() ->
|
||||||
M = #{in => query, required => false, example => <<"">>},
|
M = #{in => query, required => false, example => <<"">>},
|
||||||
[ {node,
|
[ {node,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's node name">>})}
|
M#{description => <<"Match the client's node name">>})}
|
||||||
, {clientid,
|
, {clientid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's ID">>})}
|
M#{description => <<"Match the client's ID">>})}
|
||||||
, {username,
|
, {username,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's Username">>})}
|
M#{description => <<"Match the client's Username">>})}
|
||||||
, {ip_address,
|
, {ip_address,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's ip address">>})}
|
M#{description => <<"Match the client's ip address">>})}
|
||||||
, {conn_state,
|
, {conn_state,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's connection state">>})}
|
M#{description => <<"Match the client's connection state">>})}
|
||||||
, {proto_ver,
|
, {proto_ver,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the client's protocol version">>})}
|
M#{description => <<"Match the client's protocol version">>})}
|
||||||
, {clean_start,
|
, {clean_start,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
M#{desc => <<"Match the client's clean start flag">>})}
|
M#{description => <<"Match the client's clean start flag">>})}
|
||||||
, {like_clientid,
|
, {like_clientid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Use sub-string to match client's ID">>})}
|
M#{description => <<"Use sub-string to match client's ID">>})}
|
||||||
, {like_username,
|
, {like_username,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Use sub-string to match client's username">>})}
|
M#{description => <<"Use sub-string to match client's username">>})}
|
||||||
, {gte_created_at,
|
, {gte_created_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
M#{desc => <<"Match the session created datetime greater than "
|
M#{description => <<"Match the session created datetime greater than "
|
||||||
"a certain value">>})}
|
"a certain value">>})}
|
||||||
, {lte_created_at,
|
, {lte_created_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
M#{desc => <<"Match the session created datetime less than "
|
M#{description => <<"Match the session created datetime less than "
|
||||||
"a certain value">>})}
|
"a certain value">>})}
|
||||||
, {gte_connected_at,
|
, {gte_connected_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
M#{desc => <<"Match the client socket connected datetime greater "
|
M#{description => <<"Match the client socket connected datetime greater "
|
||||||
"than a certain value">>})}
|
"than a certain value">>})}
|
||||||
, {lte_connected_at,
|
, {lte_connected_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
M#{desc => <<"Match the client socket connected datatime less than "
|
M#{description => <<"Match the client socket connected datatime less than "
|
||||||
"a certain value">>})}
|
"a certain value">>})}
|
||||||
, {endpoint_name,
|
, {endpoint_name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the lwm2m client's endpoint name">>})}
|
M#{description => <<"Match the lwm2m client's endpoint name">>})}
|
||||||
, {like_endpoint_name,
|
, {like_endpoint_name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Use sub-string to match lwm2m client's endpoint name">>})}
|
M#{description => <<"Use sub-string to match lwm2m client's endpoint name">>})}
|
||||||
, {gte_lifetime,
|
, {gte_lifetime,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the lwm2m client registered lifetime greater "
|
M#{description => <<"Match the lwm2m client registered lifetime greater "
|
||||||
"than a certain value">>})}
|
"than a certain value">>})}
|
||||||
, {lte_lifetime,
|
, {lte_lifetime,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
M#{desc => <<"Match the lwm2m client registered lifetime less than "
|
M#{description => <<"Match the lwm2m client registered lifetime less than "
|
||||||
"a certain value">>})}
|
"a certain value">>})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -533,13 +533,13 @@ params_paging() ->
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Page Index">>
|
, description => <<"Page Index">>
|
||||||
, example => 1
|
, example => 1
|
||||||
})}
|
})}
|
||||||
, {limit,
|
, {limit,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, desc => <<"Page Limit">>
|
, description => <<"Page Limit">>
|
||||||
, required => false
|
, required => false
|
||||||
, example => 100
|
, example => 100
|
||||||
})}
|
})}
|
||||||
|
@ -549,7 +549,7 @@ params_gateway_name_in_path() ->
|
||||||
[{name,
|
[{name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Gateway Name">>
|
, description => <<"Gateway Name">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -557,7 +557,7 @@ params_clientid_in_path() ->
|
||||||
[{clientid,
|
[{clientid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Client ID">>
|
, description => <<"Client ID">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ params_topic_name_in_path() ->
|
||||||
[{topic,
|
[{topic,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Topic Filter/Name">>
|
, description => <<"Topic Filter/Name">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -612,10 +612,10 @@ fields(coap_client) ->
|
||||||
fields(lwm2m_client) ->
|
fields(lwm2m_client) ->
|
||||||
[ {endpoint_name,
|
[ {endpoint_name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"The LwM2M client endpoint name">>})}
|
#{ description => <<"The LwM2M client endpoint name">>})}
|
||||||
, {lifetime,
|
, {lifetime,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Life time">>})}
|
#{ description => <<"Life time">>})}
|
||||||
] ++ common_client_props();
|
] ++ common_client_props();
|
||||||
fields(exproto_client) ->
|
fields(exproto_client) ->
|
||||||
common_client_props();
|
common_client_props();
|
||||||
|
@ -623,153 +623,153 @@ fields(exproto_client) ->
|
||||||
fields(subscription) ->
|
fields(subscription) ->
|
||||||
[ {topic,
|
[ {topic,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Topic Fillter">>})}
|
#{ description => <<"Topic Fillter">>})}
|
||||||
, {qos,
|
, {qos,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"QoS level, enum: 0, 1, 2">>})}
|
#{ description => <<"QoS level, enum: 0, 1, 2">>})}
|
||||||
, {nl,
|
, {nl,
|
||||||
mk(integer(), %% FIXME: why not boolean?
|
mk(integer(), %% FIXME: why not boolean?
|
||||||
#{ desc => <<"No Local option, enum: 0, 1">>})}
|
#{ description => <<"No Local option, enum: 0, 1">>})}
|
||||||
, {rap,
|
, {rap,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Retain as Published option, enum: 0, 1">>})}
|
#{ description => <<"Retain as Published option, enum: 0, 1">>})}
|
||||||
, {rh,
|
, {rh,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Retain Handling option, enum: 0, 1, 2">>})}
|
#{ description => <<"Retain Handling option, enum: 0, 1, 2">>})}
|
||||||
, {sub_props,
|
, {sub_props,
|
||||||
mk(ref(extra_sub_props),
|
mk(ref(extra_sub_props),
|
||||||
#{desc => <<"Subscription properties">>})}
|
#{description => <<"Subscription properties">>})}
|
||||||
];
|
];
|
||||||
fields(extra_sub_props) ->
|
fields(extra_sub_props) ->
|
||||||
[ {subid,
|
[ {subid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Only stomp protocol, a unique identity for "
|
#{ description => <<"Only stomp protocol, a unique identity for "
|
||||||
"the subscription. range: 1-65535.">>})}
|
"the subscription. range: 1-65535.">>})}
|
||||||
].
|
].
|
||||||
|
|
||||||
common_client_props() ->
|
common_client_props() ->
|
||||||
[ {node,
|
[ {node,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Name of the node to which the client is "
|
#{ description => <<"Name of the node to which the client is "
|
||||||
"connected">>})}
|
"connected">>})}
|
||||||
, {clientid,
|
, {clientid,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Client identifier">>})}
|
#{ description => <<"Client identifier">>})}
|
||||||
, {username,
|
, {username,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Username of client when connecting">>})}
|
#{ description => <<"Username of client when connecting">>})}
|
||||||
, {proto_name,
|
, {proto_name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Client protocol name">>})}
|
#{ description => <<"Client protocol name">>})}
|
||||||
, {proto_ver,
|
, {proto_ver,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Protocol version used by the client">>})}
|
#{ description => <<"Protocol version used by the client">>})}
|
||||||
, {ip_address,
|
, {ip_address,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ desc => <<"Client's IP address">>})}
|
#{ description => <<"Client's IP address">>})}
|
||||||
, {port,
|
, {port,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Client's port">>})}
|
#{ description => <<"Client's port">>})}
|
||||||
, {is_bridge,
|
, {is_bridge,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ desc => <<"Indicates whether the client is connected via "
|
#{ description => <<"Indicates whether the client is connected via "
|
||||||
"bridge">>})}
|
"bridge">>})}
|
||||||
, {connected_at,
|
, {connected_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
#{ desc => <<"Client connection time">>})}
|
#{ description => <<"Client connection time">>})}
|
||||||
, {disconnected_at,
|
, {disconnected_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
#{ desc => <<"Client offline time, This field is only valid and "
|
#{ description => <<"Client offline time, This field is only valid and "
|
||||||
"returned when connected is false">>})}
|
"returned when connected is false">>})}
|
||||||
, {connected,
|
, {connected,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ desc => <<"Whether the client is connected">>})}
|
#{ description => <<"Whether the client is connected">>})}
|
||||||
%% FIXME: the will_msg attribute is not a general attribute
|
%% FIXME: the will_msg attribute is not a general attribute
|
||||||
%% for every protocol. But it should be returned to frontend if someone
|
%% for every protocol. But it should be returned to frontend if someone
|
||||||
%% want it
|
%% want it
|
||||||
%%
|
%%
|
||||||
%, {will_msg,
|
%, {will_msg,
|
||||||
% mk(binary(),
|
% mk(binary(),
|
||||||
% #{ desc => <<"Client will message">>})}
|
% #{ description => <<"Client will message">>})}
|
||||||
, {keepalive,
|
, {keepalive,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"keepalive time, with the unit of second">>})}
|
#{ description => <<"keepalive time, with the unit of second">>})}
|
||||||
, {clean_start,
|
, {clean_start,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ desc => <<"Indicate whether the client is using a brand "
|
#{ description => <<"Indicate whether the client is using a brand "
|
||||||
"new session">>})}
|
"new session">>})}
|
||||||
, {expiry_interval,
|
, {expiry_interval,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Session expiration interval, with the unit of "
|
#{ description => <<"Session expiration interval, with the unit of "
|
||||||
"second">>})}
|
"second">>})}
|
||||||
, {created_at,
|
, {created_at,
|
||||||
mk(emqx_datetime:epoch_millisecond(),
|
mk(emqx_datetime:epoch_millisecond(),
|
||||||
#{ desc => <<"Session creation time">>})}
|
#{ description => <<"Session creation time">>})}
|
||||||
, {subscriptions_cnt,
|
, {subscriptions_cnt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of subscriptions established by this "
|
#{ description => <<"Number of subscriptions established by this "
|
||||||
"client">>})}
|
"client">>})}
|
||||||
, {subscriptions_max,
|
, {subscriptions_max,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Maximum number of subscriptions allowed by this "
|
#{ description => <<"Maximum number of subscriptions allowed by this "
|
||||||
"client">>})}
|
"client">>})}
|
||||||
, {inflight_cnt,
|
, {inflight_cnt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Current length of inflight">>})}
|
#{ description => <<"Current length of inflight">>})}
|
||||||
, {inflight_max,
|
, {inflight_max,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Maximum length of inflight">>})}
|
#{ description => <<"Maximum length of inflight">>})}
|
||||||
, {mqueue_len,
|
, {mqueue_len,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Current length of message queue">>})}
|
#{ description => <<"Current length of message queue">>})}
|
||||||
, {mqueue_max,
|
, {mqueue_max,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Maximum length of message queue">>})}
|
#{ description => <<"Maximum length of message queue">>})}
|
||||||
, {mqueue_dropped,
|
, {mqueue_dropped,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of messages dropped by the message queue "
|
#{ description => <<"Number of messages dropped by the message queue "
|
||||||
"due to exceeding the length">>})}
|
"due to exceeding the length">>})}
|
||||||
, {awaiting_rel_cnt,
|
, {awaiting_rel_cnt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
%% FIXME: PUBREC ??
|
%% FIXME: PUBREC ??
|
||||||
#{ desc => <<"Number of awaiting acknowledge packet">>})}
|
#{ description => <<"Number of awaiting acknowledge packet">>})}
|
||||||
, {awaiting_rel_max,
|
, {awaiting_rel_max,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Maximum allowed number of awaiting PUBREC "
|
#{ description => <<"Maximum allowed number of awaiting PUBREC "
|
||||||
"packet">>})}
|
"packet">>})}
|
||||||
, {recv_oct,
|
, {recv_oct,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of bytes received">>})}
|
#{ description => <<"Number of bytes received">>})}
|
||||||
, {recv_cnt,
|
, {recv_cnt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of socket packets received">>})}
|
#{ description => <<"Number of socket packets received">>})}
|
||||||
, {recv_pkt,
|
, {recv_pkt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of protocol packets received">>})}
|
#{ description => <<"Number of protocol packets received">>})}
|
||||||
, {recv_msg,
|
, {recv_msg,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of message packets received">>})}
|
#{ description => <<"Number of message packets received">>})}
|
||||||
, {send_oct,
|
, {send_oct,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of bytes sent">>})}
|
#{ description => <<"Number of bytes sent">>})}
|
||||||
, {send_cnt,
|
, {send_cnt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of socket packets sent">>})}
|
#{ description => <<"Number of socket packets sent">>})}
|
||||||
, {send_pkt,
|
, {send_pkt,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of protocol packets sent">>})}
|
#{ description => <<"Number of protocol packets sent">>})}
|
||||||
, {send_msg,
|
, {send_msg,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Number of message packets sent">>})}
|
#{ description => <<"Number of message packets sent">>})}
|
||||||
, {mailbox_len,
|
, {mailbox_len,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Process mailbox size">>})}
|
#{ description => <<"Process mailbox size">>})}
|
||||||
, {heap_size,
|
, {heap_size,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Process heap size with the unit of byte">>})}
|
#{ description => <<"Process heap size with the unit of byte">>})}
|
||||||
, {reductions,
|
, {reductions,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ desc => <<"Erlang reduction">>})}
|
#{ description => <<"Erlang reduction">>})}
|
||||||
].
|
].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -409,7 +409,7 @@ params_gateway_name_in_path() ->
|
||||||
[{name,
|
[{name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Gateway Name">>
|
, description => <<"Gateway Name">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -418,7 +418,7 @@ params_listener_id_in_path() ->
|
||||||
[{id,
|
[{id,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"Listener ID">>
|
, description => <<"Listener ID">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -426,7 +426,7 @@ params_listener_id_in_path() ->
|
||||||
params_userid_in_path() ->
|
params_userid_in_path() ->
|
||||||
[{uid, mk(binary(),
|
[{uid, mk(binary(),
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, desc => <<"User ID">>
|
, description => <<"User ID">>
|
||||||
, example => <<"">>
|
, example => <<"">>
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -435,13 +435,13 @@ params_paging_in_qs() ->
|
||||||
[{page, mk(integer(),
|
[{page, mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Page Index">>
|
, description => <<"Page Index">>
|
||||||
, example => 1
|
, example => 1
|
||||||
})},
|
})},
|
||||||
{limit, mk(integer(),
|
{limit, mk(integer(),
|
||||||
#{ in => query
|
#{ in => query
|
||||||
, required => false
|
, required => false
|
||||||
, desc => <<"Page Limit">>
|
, description => <<"Page Limit">>
|
||||||
, example => 100
|
, example => 100
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -458,22 +458,22 @@ fields(listener) ->
|
||||||
[ {tcp,
|
[ {tcp,
|
||||||
mk(ref(tcp_listener_opts),
|
mk(ref(tcp_listener_opts),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The tcp socket options for tcp or ssl listener">>
|
, description => <<"The tcp socket options for tcp or ssl listener">>
|
||||||
})}
|
})}
|
||||||
, {ssl,
|
, {ssl,
|
||||||
mk(ref(ssl_listener_opts),
|
mk(ref(ssl_listener_opts),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The ssl socket options for ssl listener">>
|
, description => <<"The ssl socket options for ssl listener">>
|
||||||
})}
|
})}
|
||||||
, {udp,
|
, {udp,
|
||||||
mk(ref(udp_listener_opts),
|
mk(ref(udp_listener_opts),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The udp socket options for udp or dtls listener">>
|
, description => <<"The udp socket options for udp or dtls listener">>
|
||||||
})}
|
})}
|
||||||
, {dtls,
|
, {dtls,
|
||||||
mk(ref(dtls_listener_opts),
|
mk(ref(dtls_listener_opts),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The dtls socket options for dtls listener">>
|
, description => <<"The dtls socket options for dtls listener">>
|
||||||
})}
|
})}
|
||||||
];
|
];
|
||||||
fields(tcp_listener_opts) ->
|
fields(tcp_listener_opts) ->
|
||||||
|
@ -530,47 +530,47 @@ common_listener_opts() ->
|
||||||
[ {enable,
|
[ {enable,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Whether to enable this listener">>})}
|
, description => <<"Whether to enable this listener">>})}
|
||||||
, {id,
|
, {id,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener Id">>})}
|
, description => <<"Listener Id">>})}
|
||||||
, {name,
|
, {name,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener name">>})}
|
, description => <<"Listener name">>})}
|
||||||
, {type,
|
, {type,
|
||||||
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
|
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener type. Enum: tcp, udp, ssl, dtls">>})}
|
, description => <<"Listener type. Enum: tcp, udp, ssl, dtls">>})}
|
||||||
, {running,
|
, {running,
|
||||||
mk(boolean(),
|
mk(boolean(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener running status">>})}
|
, description => <<"Listener running status">>})}
|
||||||
, {bind,
|
, {bind,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener bind address or port">>})}
|
, description => <<"Listener bind address or port">>})}
|
||||||
, {acceptors,
|
, {acceptors,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener acceptors number">>})}
|
, description => <<"Listener acceptors number">>})}
|
||||||
, {access_rules,
|
, {access_rules,
|
||||||
mk(hoconsc:array(binary()),
|
mk(hoconsc:array(binary()),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Listener Access rules for client">>})}
|
, description => <<"Listener Access rules for client">>})}
|
||||||
, {max_conn_rate,
|
, {max_conn_rate,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Max connection rate for the listener">>})}
|
, description => <<"Max connection rate for the listener">>})}
|
||||||
, {max_connections,
|
, {max_connections,
|
||||||
mk(integer(),
|
mk(integer(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc => <<"Max connections for the listener">>})}
|
, description => <<"Max connections for the listener">>})}
|
||||||
, {mountpoint,
|
, {mountpoint,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{ required => false
|
#{ required => false
|
||||||
, desc =>
|
, description =>
|
||||||
<<"The Mounpoint for clients of the listener. "
|
<<"The Mounpoint for clients of the listener. "
|
||||||
"The gateway-level mountpoint configuration can be overloaded "
|
"The gateway-level mountpoint configuration can be overloaded "
|
||||||
"when it is not null or empty string">>})}
|
"when it is not null or empty string">>})}
|
||||||
|
@ -578,7 +578,7 @@ common_listener_opts() ->
|
||||||
, {authentication,
|
, {authentication,
|
||||||
mk(emqx_authn_schema:authenticator_type(),
|
mk(emqx_authn_schema:authenticator_type(),
|
||||||
#{ required => {false, recursively}
|
#{ required => {false, recursively}
|
||||||
, desc => <<"The authenticatior for this listener">>
|
, description => <<"The authenticatior for this listener">>
|
||||||
})}
|
})}
|
||||||
] ++ emqx_gateway_schema:proxy_protocol_opts().
|
] ++ emqx_gateway_schema:proxy_protocol_opts().
|
||||||
|
|
||||||
|
|
|
@ -307,11 +307,7 @@ reason2resp(R) ->
|
||||||
|
|
||||||
-spec return_http_error(integer(), any()) -> {integer(), binary()}.
|
-spec return_http_error(integer(), any()) -> {integer(), binary()}.
|
||||||
return_http_error(Code, Msg) ->
|
return_http_error(Code, Msg) ->
|
||||||
{Code, emqx_json:encode(
|
{Code, codestr(Code), emqx_gateway_utils:stringfy(Msg)}.
|
||||||
#{code => codestr(Code),
|
|
||||||
message => emqx_gateway_utils:stringfy(Msg)
|
|
||||||
})
|
|
||||||
}.
|
|
||||||
|
|
||||||
-spec reason2msg({atom(), map()} | any()) -> error | string().
|
-spec reason2msg({atom(), map()} | any()) -> error | string().
|
||||||
reason2msg({badconf, #{key := Key, value := Value, reason := Reason}}) ->
|
reason2msg({badconf, #{key := Key, value := Value, reason := Reason}}) ->
|
||||||
|
@ -362,9 +358,9 @@ reason2msg(_) ->
|
||||||
error.
|
error.
|
||||||
|
|
||||||
codestr(400) -> 'BAD_REQUEST';
|
codestr(400) -> 'BAD_REQUEST';
|
||||||
codestr(401) -> 'NOT_SUPPORTED_NOW';
|
|
||||||
codestr(404) -> 'RESOURCE_NOT_FOUND';
|
codestr(404) -> 'RESOURCE_NOT_FOUND';
|
||||||
codestr(405) -> 'METHOD_NOT_ALLOWED';
|
codestr(405) -> 'METHOD_NOT_ALLOWED';
|
||||||
|
codestr(409) -> 'NOT_SUPPORT';
|
||||||
codestr(500) -> 'UNKNOW_ERROR';
|
codestr(500) -> 'UNKNOW_ERROR';
|
||||||
codestr(501) -> 'NOT_IMPLEMENTED'.
|
codestr(501) -> 'NOT_IMPLEMENTED'.
|
||||||
|
|
||||||
|
|
|
@ -117,11 +117,11 @@ schema(?PATH("/write")) ->
|
||||||
|
|
||||||
fields(resource) ->
|
fields(resource) ->
|
||||||
[
|
[
|
||||||
{operations, mk(binary(), #{desc => <<"Resource Operations">>, example => "E"})},
|
{operations, mk(binary(), #{description => <<"Resource Operations">>, example => "E"})},
|
||||||
{'dataType', mk(hoconsc:enum(?DATA_TYPE), #{desc => <<"Data Type">>,
|
{'dataType', mk(hoconsc:enum(?DATA_TYPE), #{description => <<"Data Type">>,
|
||||||
example => 'Integer'})},
|
example => 'Integer'})},
|
||||||
{path, mk(binary(), #{desc => <<"Resource Path">>, example => "urn:oma:lwm2m:oma:2"})},
|
{path, mk(binary(), #{description => <<"Resource Path">>, example => "urn:oma:lwm2m:oma:2"})},
|
||||||
{name, mk(binary(), #{desc => <<"Resource Name">>, example => "lwm2m-test"})}
|
{name, mk(binary(), #{description => <<"Resource Name">>, example => "lwm2m-test"})}
|
||||||
].
|
].
|
||||||
|
|
||||||
lookup_cmd(get, #{bindings := Bindings, query_string := QS}) ->
|
lookup_cmd(get, #{bindings := Bindings, query_string := QS}) ->
|
||||||
|
|
Loading…
Reference in New Issue