|
@@ -24,7 +24,7 @@
|
|
|
-include_lib("emqx/include/logger.hrl").
|
|
-include_lib("emqx/include/logger.hrl").
|
|
|
-include_lib("emqx/include/emqx_authentication.hrl").
|
|
-include_lib("emqx/include/emqx_authentication.hrl").
|
|
|
|
|
|
|
|
--import(hoconsc, [mk/2, ref/1]).
|
|
|
|
|
|
|
+-import(hoconsc, [mk/2, ref/1, ref/2]).
|
|
|
-import(emqx_dashboard_swagger, [error_codes/2]).
|
|
-import(emqx_dashboard_swagger, [error_codes/2]).
|
|
|
|
|
|
|
|
-define(BAD_REQUEST, 'BAD_REQUEST').
|
|
-define(BAD_REQUEST, 'BAD_REQUEST').
|
|
@@ -128,31 +128,26 @@ roots() ->
|
|
|
|
|
|
|
|
fields(request_user_create) ->
|
|
fields(request_user_create) ->
|
|
|
[
|
|
[
|
|
|
- {user_id, binary()}
|
|
|
|
|
|
|
+ {user_id, mk(binary(), #{required => true})}
|
|
|
| fields(request_user_update)
|
|
| fields(request_user_update)
|
|
|
];
|
|
];
|
|
|
fields(request_user_update) ->
|
|
fields(request_user_update) ->
|
|
|
[
|
|
[
|
|
|
- {password, binary()},
|
|
|
|
|
|
|
+ {password, mk(binary(), #{required => true})},
|
|
|
{is_superuser, mk(boolean(), #{default => false, required => false})}
|
|
{is_superuser, mk(boolean(), #{default => false, required => false})}
|
|
|
];
|
|
];
|
|
|
fields(request_move) ->
|
|
fields(request_move) ->
|
|
|
- [{position, binary()}];
|
|
|
|
|
|
|
+ [{position, mk(binary(), #{required => true})}];
|
|
|
fields(request_import_users) ->
|
|
fields(request_import_users) ->
|
|
|
- [{filename, binary()}];
|
|
|
|
|
|
|
+ %% TODO: add file update
|
|
|
|
|
+ [{filename, mk(binary(), #{required => true})}];
|
|
|
fields(response_user) ->
|
|
fields(response_user) ->
|
|
|
[
|
|
[
|
|
|
- {user_id, binary()},
|
|
|
|
|
|
|
+ {user_id, mk(binary(), #{required => true})},
|
|
|
{is_superuser, mk(boolean(), #{default => false, required => false})}
|
|
{is_superuser, mk(boolean(), #{default => false, required => false})}
|
|
|
];
|
|
];
|
|
|
fields(response_users) ->
|
|
fields(response_users) ->
|
|
|
- paginated_list_type(ref(response_user));
|
|
|
|
|
-fields(pagination_meta) ->
|
|
|
|
|
- [
|
|
|
|
|
- {page, pos_integer()},
|
|
|
|
|
- {limit, pos_integer()},
|
|
|
|
|
- {count, non_neg_integer()}
|
|
|
|
|
- ].
|
|
|
|
|
|
|
+ paginated_list_type(ref(response_user)).
|
|
|
|
|
|
|
|
schema("/authentication") ->
|
|
schema("/authentication") ->
|
|
|
#{
|
|
#{
|
|
@@ -431,10 +426,8 @@ schema("/authentication/:id/users") ->
|
|
|
description => <<"List users in authenticator in global authentication chain">>,
|
|
description => <<"List users in authenticator in global authentication chain">>,
|
|
|
parameters => [
|
|
parameters => [
|
|
|
param_auth_id(),
|
|
param_auth_id(),
|
|
|
- {page,
|
|
|
|
|
- mk(pos_integer(), #{in => query, desc => <<"Page Index">>, required => false})},
|
|
|
|
|
- {limit,
|
|
|
|
|
- mk(pos_integer(), #{in => query, desc => <<"Page Limit">>, required => false})},
|
|
|
|
|
|
|
+ ref(emqx_dashboard_swagger, page),
|
|
|
|
|
+ ref(emqx_dashboard_swagger, limit),
|
|
|
{like_username,
|
|
{like_username,
|
|
|
mk(binary(), #{
|
|
mk(binary(), #{
|
|
|
in => query,
|
|
in => query,
|
|
@@ -483,10 +476,8 @@ schema("/listeners/:listener_id/authentication/:id/users") ->
|
|
|
parameters => [
|
|
parameters => [
|
|
|
param_listener_id(),
|
|
param_listener_id(),
|
|
|
param_auth_id(),
|
|
param_auth_id(),
|
|
|
- {page,
|
|
|
|
|
- mk(pos_integer(), #{in => query, desc => <<"Page Index">>, required => false})},
|
|
|
|
|
- {limit,
|
|
|
|
|
- mk(pos_integer(), #{in => query, desc => <<"Page Limit">>, required => false})}
|
|
|
|
|
|
|
+ ref(emqx_dashboard_swagger, page),
|
|
|
|
|
+ ref(emqx_dashboard_swagger, limit)
|
|
|
],
|
|
],
|
|
|
responses => #{
|
|
responses => #{
|
|
|
200 => emqx_dashboard_swagger:schema_with_example(
|
|
200 => emqx_dashboard_swagger:schema_with_example(
|
|
@@ -587,7 +578,8 @@ param_auth_id() ->
|
|
|
id,
|
|
id,
|
|
|
mk(binary(), #{
|
|
mk(binary(), #{
|
|
|
in => path,
|
|
in => path,
|
|
|
- desc => <<"Authenticator ID">>
|
|
|
|
|
|
|
+ desc => <<"Authenticator ID">>,
|
|
|
|
|
+ required => true
|
|
|
})
|
|
})
|
|
|
}.
|
|
}.
|
|
|
|
|
|
|
@@ -597,6 +589,7 @@ param_listener_id() ->
|
|
|
mk(binary(), #{
|
|
mk(binary(), #{
|
|
|
in => path,
|
|
in => path,
|
|
|
desc => <<"Listener ID">>,
|
|
desc => <<"Listener ID">>,
|
|
|
|
|
+ required => true,
|
|
|
example => emqx_listeners:id_example()
|
|
example => emqx_listeners:id_example()
|
|
|
})
|
|
})
|
|
|
}.
|
|
}.
|
|
@@ -1182,7 +1175,7 @@ update_config(Path, ConfigRequest) ->
|
|
|
|
|
|
|
|
get_raw_config_with_defaults(ConfKeyPath) ->
|
|
get_raw_config_with_defaults(ConfKeyPath) ->
|
|
|
NConfKeyPath = [atom_to_binary(Key, utf8) || Key <- ConfKeyPath],
|
|
NConfKeyPath = [atom_to_binary(Key, utf8) || Key <- ConfKeyPath],
|
|
|
- RawConfig = emqx_map_lib:deep_get(NConfKeyPath, emqx_config:get_raw([]), []),
|
|
|
|
|
|
|
+ RawConfig = emqx:get_raw_config(NConfKeyPath, []),
|
|
|
ensure_list(fill_defaults(RawConfig)).
|
|
ensure_list(fill_defaults(RawConfig)).
|
|
|
|
|
|
|
|
find_config(AuthenticatorID, AuthenticatorsConfig) ->
|
|
find_config(AuthenticatorID, AuthenticatorsConfig) ->
|
|
@@ -1200,7 +1193,24 @@ find_config(AuthenticatorID, AuthenticatorsConfig) ->
|
|
|
fill_defaults(Configs) when is_list(Configs) ->
|
|
fill_defaults(Configs) when is_list(Configs) ->
|
|
|
lists:map(fun fill_defaults/1, Configs);
|
|
lists:map(fun fill_defaults/1, Configs);
|
|
|
fill_defaults(Config) ->
|
|
fill_defaults(Config) ->
|
|
|
- emqx_authn:check_config(Config, #{only_fill_defaults => true}).
|
|
|
|
|
|
|
+ emqx_authn:check_config(merge_default_headers(Config), #{only_fill_defaults => true}).
|
|
|
|
|
+
|
|
|
|
|
+merge_default_headers(Config) ->
|
|
|
|
|
+ case maps:find(<<"headers">>, Config) of
|
|
|
|
|
+ {ok, Headers} ->
|
|
|
|
|
+ NewHeaders =
|
|
|
|
|
+ case Config of
|
|
|
|
|
+ #{<<"method">> := <<"get">>} ->
|
|
|
|
|
+ (emqx_authn_http:headers_no_content_type(converter))(Headers);
|
|
|
|
|
+ #{<<"method">> := <<"post">>} ->
|
|
|
|
|
+ (emqx_authn_http:headers(converter))(Headers);
|
|
|
|
|
+ _ ->
|
|
|
|
|
+ Headers
|
|
|
|
|
+ end,
|
|
|
|
|
+ Config#{<<"headers">> => NewHeaders};
|
|
|
|
|
+ error ->
|
|
|
|
|
+ Config
|
|
|
|
|
+ end.
|
|
|
|
|
|
|
|
convert_certs(#{ssl := SSL} = Config) when SSL =/= undefined ->
|
|
convert_certs(#{ssl := SSL} = Config) when SSL =/= undefined ->
|
|
|
Config#{ssl := emqx_tls_lib:drop_invalid_certs(SSL)};
|
|
Config#{ssl := emqx_tls_lib:drop_invalid_certs(SSL)};
|
|
@@ -1316,7 +1326,7 @@ binfmt(Fmt, Args) -> iolist_to_binary(io_lib:format(Fmt, Args)).
|
|
|
paginated_list_type(Type) ->
|
|
paginated_list_type(Type) ->
|
|
|
[
|
|
[
|
|
|
{data, hoconsc:array(Type)},
|
|
{data, hoconsc:array(Type)},
|
|
|
- {meta, ref(pagination_meta)}
|
|
|
|
|
|
|
+ {meta, ref(emqx_dashboard_swagger, meta)}
|
|
|
].
|
|
].
|
|
|
|
|
|
|
|
authenticator_array_example() ->
|
|
authenticator_array_example() ->
|