chore(authn): remove implied schema
This commit is contained in:
parent
b7bc8b8cac
commit
3f2ca5282c
|
@ -1336,29 +1336,35 @@ move(post, Request) ->
|
||||||
import_users(post, Request) ->
|
import_users(post, Request) ->
|
||||||
AuthenticatorID = cowboy_req:binding(id, Request),
|
AuthenticatorID = cowboy_req:binding(id, Request),
|
||||||
{ok, Body, _} = cowboy_req:read_body(Request),
|
{ok, Body, _} = cowboy_req:read_body(Request),
|
||||||
NBody = emqx_json:decode(Body, [return_maps]),
|
case emqx_json:decode(Body, [return_maps]) of
|
||||||
Config = hocon_schema:check_plain(emqx_authn_implied_schema, #{<<"filename">> => NBody},
|
#{<<"filename">> := Filename} ->
|
||||||
#{nullable => true}, ["filename"]),
|
case emqx_authn:import_users(?CHAIN, AuthenticatorID, Filename) of
|
||||||
#{filename := #{filename := Filename}} = emqx_map_lib:unsafe_atom_key_map(Config),
|
ok ->
|
||||||
case emqx_authn:import_users(?CHAIN, AuthenticatorID, Filename) of
|
{204};
|
||||||
ok ->
|
{error, Reason} ->
|
||||||
{204};
|
serialize_error(Reason)
|
||||||
{error, Reason} ->
|
end;
|
||||||
serialize_error(Reason)
|
_ ->
|
||||||
|
serialize_error({missing_parameter, filename})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
users(post, Request) ->
|
users(post, Request) ->
|
||||||
AuthenticatorID = cowboy_req:binding(id, Request),
|
AuthenticatorID = cowboy_req:binding(id, Request),
|
||||||
{ok, Body, _} = cowboy_req:read_body(Request),
|
{ok, Body, _} = cowboy_req:read_body(Request),
|
||||||
NBody = emqx_json:decode(Body, [return_maps]),
|
case emqx_json:decode(Body, [return_maps]) of
|
||||||
Config = hocon_schema:check_plain(emqx_authn_implied_schema, #{<<"user_info">> => NBody},
|
#{ <<"user_id">> := UserID
|
||||||
#{nullable => true}, ["user_info"]),
|
, <<"password">> := Password} ->
|
||||||
#{user_info := UserInfo} = emqx_map_lib:unsafe_atom_key_map(Config),
|
case emqx_authn:add_user(?CHAIN, AuthenticatorID, #{ user_id => UserID
|
||||||
case emqx_authn:add_user(?CHAIN, AuthenticatorID, UserInfo) of
|
, password => Password}) of
|
||||||
{ok, User} ->
|
{ok, User} ->
|
||||||
{201, User};
|
{201, User};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
serialize_error(Reason)
|
serialize_error(Reason)
|
||||||
|
end;
|
||||||
|
#{<<"user_id">> := _} ->
|
||||||
|
serialize_error({missing_parameter, password});
|
||||||
|
_ ->
|
||||||
|
serialize_error({missing_parameter, user_id})
|
||||||
end;
|
end;
|
||||||
users(get, Request) ->
|
users(get, Request) ->
|
||||||
AuthenticatorID = cowboy_req:binding(id, Request),
|
AuthenticatorID = cowboy_req:binding(id, Request),
|
||||||
|
@ -1373,15 +1379,16 @@ users2(patch, Request) ->
|
||||||
AuthenticatorID = cowboy_req:binding(id, Request),
|
AuthenticatorID = cowboy_req:binding(id, Request),
|
||||||
UserID = cowboy_req:binding(user_id, Request),
|
UserID = cowboy_req:binding(user_id, Request),
|
||||||
{ok, Body, _} = cowboy_req:read_body(Request),
|
{ok, Body, _} = cowboy_req:read_body(Request),
|
||||||
NBody = emqx_json:decode(Body, [return_maps]),
|
case emqx_json:decode(Body, [return_maps]) of
|
||||||
Config = hocon_schema:check_plain(emqx_authn_implied_schema, #{<<"new_user_info">> => NBody},
|
#{<<"password">> := Password} ->
|
||||||
#{nullable => true}, ["new_user_info"]),
|
case emqx_authn:update_user(?CHAIN, AuthenticatorID, UserID, #{password => Password}) of
|
||||||
#{new_user_info := NewUserInfo} = emqx_map_lib:unsafe_atom_key_map(Config),
|
{ok, User} ->
|
||||||
case emqx_authn:update_user(?CHAIN, AuthenticatorID, UserID, NewUserInfo) of
|
{200, User};
|
||||||
{ok, User} ->
|
{error, Reason} ->
|
||||||
{200, User};
|
serialize_error(Reason)
|
||||||
{error, Reason} ->
|
end;
|
||||||
serialize_error(Reason)
|
_ ->
|
||||||
|
serialize_error({missing_parameter, password})
|
||||||
end;
|
end;
|
||||||
users2(get, Request) ->
|
users2(get, Request) ->
|
||||||
AuthenticatorID = cowboy_req:binding(id, Request),
|
AuthenticatorID = cowboy_req:binding(id, Request),
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
||||||
%%
|
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
%% you may not use this file except in compliance with the License.
|
|
||||||
%% You may obtain a copy of the License at
|
|
||||||
%%
|
|
||||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
%%
|
|
||||||
%% Unless required by applicable law or agreed to in writing, software
|
|
||||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
%% See the License for the specific language governing permissions and
|
|
||||||
%% limitations under the License.
|
|
||||||
%%--------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqx_authn_implied_schema).
|
|
||||||
|
|
||||||
-include("emqx_authn.hrl").
|
|
||||||
-include_lib("typerefl/include/types.hrl").
|
|
||||||
|
|
||||||
-behaviour(hocon_schema).
|
|
||||||
|
|
||||||
-export([ structs/0
|
|
||||||
, fields/1
|
|
||||||
]).
|
|
||||||
|
|
||||||
structs() -> [ "filename", "user_info", "new_user_info"].
|
|
||||||
|
|
||||||
fields("filename") ->
|
|
||||||
[ {filename, fun filename/1} ];
|
|
||||||
fields("user_info") ->
|
|
||||||
[ {user_id, fun user_id/1}
|
|
||||||
, {password, fun password/1}
|
|
||||||
];
|
|
||||||
fields("new_user_info") ->
|
|
||||||
[ {password, fun password/1}
|
|
||||||
].
|
|
||||||
|
|
||||||
filename(type) -> string();
|
|
||||||
filename(nullable) -> false;
|
|
||||||
filename(_) -> undefined.
|
|
||||||
|
|
||||||
user_id(type) -> binary();
|
|
||||||
user_id(nullable) -> false;
|
|
||||||
user_id(_) -> undefined.
|
|
||||||
|
|
||||||
password(type) -> binary();
|
|
||||||
password(nullable) -> false;
|
|
||||||
password(_) -> undefined.
|
|
||||||
|
|
Loading…
Reference in New Issue