feat: add default csv file in authn-built-in-db
This commit is contained in:
parent
8e904099c7
commit
08596f886a
|
@ -0,0 +1 @@
|
|||
user_id,password,is_superuser
|
|
|
@ -181,6 +181,10 @@ import_users({PasswordType, Filename, FileData}, State, Opts) ->
|
|||
case do_import_users(Users, Opts#{filename => Filename}) of
|
||||
ok ->
|
||||
ok;
|
||||
%% Do not log empty user entries.
|
||||
%% The default etc/auth-built-in-db.csv file contains an empty user entry.
|
||||
{error, empty_users} ->
|
||||
{error, empty_users};
|
||||
{error, Reason} ->
|
||||
?SLOG(
|
||||
warning,
|
||||
|
@ -496,7 +500,7 @@ reader_fn(Filename0, Data) ->
|
|||
error(Reason)
|
||||
end;
|
||||
<<".csv">> ->
|
||||
%% Example: data/user-credentials.csv
|
||||
%% Example: etc/auth-built-in-db-bootstrap.csv
|
||||
emqx_utils_stream:csv(Data);
|
||||
<<>> ->
|
||||
error(unknown_file_format);
|
||||
|
@ -541,11 +545,11 @@ is_superuser(#{<<"is_superuser">> := true}) -> true;
|
|||
is_superuser(_) -> false.
|
||||
|
||||
boostrap_user_from_file(Config, State) ->
|
||||
case maps:get(boostrap_file, Config, <<>>) of
|
||||
case maps:get(bootstrap_file, Config, <<>>) of
|
||||
<<>> ->
|
||||
ok;
|
||||
FileName0 ->
|
||||
#{boostrap_type := Type} = Config,
|
||||
#{bootstrap_type := Type} = Config,
|
||||
FileName = emqx_schema:naive_env_interpolation(FileName0),
|
||||
case file:read_file(FileName) of
|
||||
{ok, FileData} ->
|
||||
|
|
|
@ -46,7 +46,7 @@ select_union_member(_Kind, _Value) ->
|
|||
fields(builtin_db) ->
|
||||
[
|
||||
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw/1}
|
||||
] ++ common_fields().
|
||||
] ++ common_fields();
|
||||
fields(builtin_db_api) ->
|
||||
[
|
||||
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw_api/1}
|
||||
|
@ -79,7 +79,7 @@ bootstrap_fields() ->
|
|||
#{
|
||||
desc => ?DESC(bootstrap_file),
|
||||
required => false,
|
||||
default => <<>>
|
||||
default => <<"${EMQX_ETC_DIR}/auth-built-in-db-bootstrap.csv">>
|
||||
}
|
||||
)},
|
||||
{bootstrap_type,
|
||||
|
|
|
@ -124,8 +124,8 @@ test_bootstrap_file(Config0, Type, File) ->
|
|||
test_bootstrap_file(Config0, Type, File, Opts) ->
|
||||
{Type, Filename, _FileData} = sample_filename_and_data(Type, File),
|
||||
Config2 = Config0#{
|
||||
boostrap_file => Filename,
|
||||
boostrap_type => Type
|
||||
bootstrap_file => Filename,
|
||||
bootstrap_type => Type
|
||||
},
|
||||
{ok, State0} = emqx_authn_mnesia:create(?AUTHN_ID, Config2),
|
||||
Result = ets:tab2list(emqx_authn_mnesia),
|
||||
|
|
|
@ -469,6 +469,8 @@ relx_overlay(ReleaseType, Edition) ->
|
|||
{copy, "bin/install_upgrade.escript", "bin/install_upgrade.escript-{{release_version}}"},
|
||||
{copy, "apps/emqx_gateway_lwm2m/lwm2m_xml", "etc/lwm2m_xml"},
|
||||
{copy, "apps/emqx_auth/etc/acl.conf", "etc/acl.conf"},
|
||||
{copy, "apps/emqx_auth/etc/auth-built-in-db-bootstrap.csv",
|
||||
"etc/auth-built-in-db-bootstrap.csv"},
|
||||
{template, "bin/emqx.cmd", "bin/emqx.cmd"},
|
||||
{template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"},
|
||||
{copy, "bin/nodetool", "bin/nodetool"},
|
||||
|
|
Loading…
Reference in New Issue