fix(elvis): elvis warning
This commit is contained in:
parent
cf11f3f8ee
commit
0614c157ec
|
@ -126,7 +126,8 @@ EMQ X can be configured with:
|
||||||
<br>
|
<br>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>[]</code>: The default value, it allows *ALL* logins</li>
|
<li><code>[]</code>: The default value, it allows *ALL* logins</li>
|
||||||
<li>one: For example <code>{enable:true,backend:\"built-in-database\",mechanism=\"password-based\"}</code></li>
|
<li>one: For example <code>{enable:true,backend:\"built-in-database\",mechanism=\"password-based\"}
|
||||||
|
</code></li>
|
||||||
<li>chain: An array of structs.</li>
|
<li>chain: An array of structs.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
@ -1479,7 +1480,8 @@ authentication(Desc) ->
|
||||||
%% the type checks are done in emqx_auth application when it boots.
|
%% the type checks are done in emqx_auth application when it boots.
|
||||||
%% and in emqx_authentication_config module for rutime changes.
|
%% and in emqx_authentication_config module for rutime changes.
|
||||||
Default = hoconsc:lazy(hoconsc:union([typerefl:map(), hoconsc:array(typerefl:map())])),
|
Default = hoconsc:lazy(hoconsc:union([typerefl:map(), hoconsc:array(typerefl:map())])),
|
||||||
%% as the type is lazy, the runtime module injection from EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY
|
%% as the type is lazy, the runtime module injection
|
||||||
|
%% from EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY
|
||||||
%% is for now only affecting document generation.
|
%% is for now only affecting document generation.
|
||||||
%% maybe in the future, we can find a more straightforward way to support
|
%% maybe in the future, we can find a more straightforward way to support
|
||||||
%% * document generation (at compile time)
|
%% * document generation (at compile time)
|
||||||
|
|
|
@ -45,8 +45,8 @@ start_listeners() ->
|
||||||
components => #{
|
components => #{
|
||||||
schemas => #{},
|
schemas => #{},
|
||||||
'securitySchemes' => #{
|
'securitySchemes' => #{
|
||||||
basicAuth => #{type => http, scheme => basic},
|
'basicAuth' => #{type => http, scheme => basic},
|
||||||
bearerAuth => #{type => http, scheme => bearer}
|
'bearerAuth' => #{type => http, scheme => bearer}
|
||||||
}}},
|
}}},
|
||||||
Dispatch =
|
Dispatch =
|
||||||
case os:getenv("_EMQX_ENABLE_DASHBOARD") of
|
case os:getenv("_EMQX_ENABLE_DASHBOARD") of
|
||||||
|
@ -62,7 +62,7 @@ start_listeners() ->
|
||||||
base_path => ?BASE_PATH,
|
base_path => ?BASE_PATH,
|
||||||
modules => minirest_api:find_api_modules(apps()),
|
modules => minirest_api:find_api_modules(apps()),
|
||||||
authorization => Authorization,
|
authorization => Authorization,
|
||||||
security => [#{basicAuth => []}, #{bearerAuth => []}],
|
security => [#{'basicAuth' => []}, #{'bearerAuth' => []}],
|
||||||
swagger_global_spec => GlobalSpec,
|
swagger_global_spec => GlobalSpec,
|
||||||
dispatch => Dispatch,
|
dispatch => Dispatch,
|
||||||
middlewares => [cowboy_router, ?EMQX_MIDDLE, cowboy_handler]
|
middlewares => [cowboy_router, ?EMQX_MIDDLE, cowboy_handler]
|
||||||
|
|
|
@ -115,11 +115,11 @@ hash(Password) ->
|
||||||
|
|
||||||
verify_hash(Origin, SaltHash) ->
|
verify_hash(Origin, SaltHash) ->
|
||||||
case SaltHash of
|
case SaltHash of
|
||||||
<<Salt:4/binary, Hash/binary>> ->
|
<<Salt:4/binary, Hash/binary>> ->
|
||||||
case Hash =:= sha256(Salt, Origin) of
|
case Hash =:= sha256(Salt, Origin) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> error
|
false -> error
|
||||||
end;
|
end;
|
||||||
_ -> error
|
_ -> error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,8 @@ schema("/users/:username") ->
|
||||||
#{in => path, example => <<"admin">>})}],
|
#{in => path, example => <<"admin">>})}],
|
||||||
'requestBody' => [
|
'requestBody' => [
|
||||||
{ description
|
{ description
|
||||||
, mk(emqx_schema:unicode_binary(), #{desc => <<"User description">>, example => <<"administrator">>})}
|
, mk(emqx_schema:unicode_binary(),
|
||||||
|
#{desc => <<"User description">>, example => <<"administrator">>})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => mk( ref(?MODULE, user)
|
200 => mk( ref(?MODULE, user)
|
||||||
|
|
|
@ -95,7 +95,7 @@ fields(app) ->
|
||||||
#{desc => "No longer valid datetime",
|
#{desc => "No longer valid datetime",
|
||||||
example => <<"2021-12-05T02:01:34.186Z">>,
|
example => <<"2021-12-05T02:01:34.186Z">>,
|
||||||
nullable => true
|
nullable => true
|
||||||
})},
|
})},
|
||||||
{created_at, hoconsc:mk(emqx_schema:rfc3339_system_time(),
|
{created_at, hoconsc:mk(emqx_schema:rfc3339_system_time(),
|
||||||
#{desc => "ApiKey create datetime",
|
#{desc => "ApiKey create datetime",
|
||||||
example => <<"2021-12-01T00:00:00.000Z">>
|
example => <<"2021-12-01T00:00:00.000Z">>
|
||||||
|
@ -105,20 +105,20 @@ fields(app) ->
|
||||||
{enable, hoconsc:mk(boolean(), #{desc => "Enable/Disable", nullable => true})}
|
{enable, hoconsc:mk(boolean(), #{desc => "Enable/Disable", nullable => true})}
|
||||||
];
|
];
|
||||||
fields(name) ->
|
fields(name) ->
|
||||||
[{name, hoconsc:mk(binary(),
|
[{name, hoconsc:mk(binary(),
|
||||||
#{
|
#{
|
||||||
desc => <<"[a-zA-Z0-9-_]">>,
|
desc => <<"[a-zA-Z0-9-_]">>,
|
||||||
example => <<"EMQX-API-KEY-1">>,
|
example => <<"EMQX-API-KEY-1">>,
|
||||||
in => path,
|
in => path,
|
||||||
validator => fun ?MODULE:validate_name/1
|
validator => fun ?MODULE:validate_name/1
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
-define(NAME_RE, "^[A-Za-z]+[A-Za-z0-9-_]*$").
|
-define(NAME_RE, "^[A-Za-z]+[A-Za-z0-9-_]*$").
|
||||||
|
|
||||||
validate_name(Name) ->
|
validate_name(Name) ->
|
||||||
NameLen = byte_size(Name),
|
NameLen = byte_size(Name),
|
||||||
case NameLen > 0 andalso NameLen =< 256 of
|
case NameLen > 0 andalso NameLen =< 256 of
|
||||||
true ->
|
true ->
|
||||||
case re:run(Name, ?NAME_RE) of
|
case re:run(Name, ?NAME_RE) of
|
||||||
nomatch -> {error, "Name should be " ?NAME_RE};
|
nomatch -> {error, "Name should be " ?NAME_RE};
|
||||||
|
@ -131,7 +131,7 @@ delete(Keys, Fields) ->
|
||||||
lists:foldl(fun(Key, Acc) -> lists:keydelete(Key, 1, Acc) end, Fields, Keys).
|
lists:foldl(fun(Key, Acc) -> lists:keydelete(Key, 1, Acc) end, Fields, Keys).
|
||||||
|
|
||||||
api_key(get, _) ->
|
api_key(get, _) ->
|
||||||
{200, [format(App) ||App <- emqx_mgmt_auth:list()]};
|
{200, [format(App) || App <- emqx_mgmt_auth:list()]};
|
||||||
api_key(post, #{body := App}) ->
|
api_key(post, #{body := App}) ->
|
||||||
#{
|
#{
|
||||||
<<"name">> := Name,
|
<<"name">> := Name,
|
||||||
|
|
Loading…
Reference in New Issue