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
|
case do_import_users(Users, Opts#{filename => Filename}) of
|
||||||
ok ->
|
ok ->
|
||||||
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} ->
|
{error, Reason} ->
|
||||||
?SLOG(
|
?SLOG(
|
||||||
warning,
|
warning,
|
||||||
|
@ -496,7 +500,7 @@ reader_fn(Filename0, Data) ->
|
||||||
error(Reason)
|
error(Reason)
|
||||||
end;
|
end;
|
||||||
<<".csv">> ->
|
<<".csv">> ->
|
||||||
%% Example: data/user-credentials.csv
|
%% Example: etc/auth-built-in-db-bootstrap.csv
|
||||||
emqx_utils_stream:csv(Data);
|
emqx_utils_stream:csv(Data);
|
||||||
<<>> ->
|
<<>> ->
|
||||||
error(unknown_file_format);
|
error(unknown_file_format);
|
||||||
|
@ -541,11 +545,11 @@ is_superuser(#{<<"is_superuser">> := true}) -> true;
|
||||||
is_superuser(_) -> false.
|
is_superuser(_) -> false.
|
||||||
|
|
||||||
boostrap_user_from_file(Config, State) ->
|
boostrap_user_from_file(Config, State) ->
|
||||||
case maps:get(boostrap_file, Config, <<>>) of
|
case maps:get(bootstrap_file, Config, <<>>) of
|
||||||
<<>> ->
|
<<>> ->
|
||||||
ok;
|
ok;
|
||||||
FileName0 ->
|
FileName0 ->
|
||||||
#{boostrap_type := Type} = Config,
|
#{bootstrap_type := Type} = Config,
|
||||||
FileName = emqx_schema:naive_env_interpolation(FileName0),
|
FileName = emqx_schema:naive_env_interpolation(FileName0),
|
||||||
case file:read_file(FileName) of
|
case file:read_file(FileName) of
|
||||||
{ok, FileData} ->
|
{ok, FileData} ->
|
||||||
|
|
|
@ -46,7 +46,7 @@ select_union_member(_Kind, _Value) ->
|
||||||
fields(builtin_db) ->
|
fields(builtin_db) ->
|
||||||
[
|
[
|
||||||
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw/1}
|
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw/1}
|
||||||
] ++ common_fields().
|
] ++ common_fields();
|
||||||
fields(builtin_db_api) ->
|
fields(builtin_db_api) ->
|
||||||
[
|
[
|
||||||
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw_api/1}
|
{password_hash_algorithm, fun emqx_authn_password_hashing:type_rw_api/1}
|
||||||
|
@ -79,7 +79,7 @@ bootstrap_fields() ->
|
||||||
#{
|
#{
|
||||||
desc => ?DESC(bootstrap_file),
|
desc => ?DESC(bootstrap_file),
|
||||||
required => false,
|
required => false,
|
||||||
default => <<>>
|
default => <<"${EMQX_ETC_DIR}/auth-built-in-db-bootstrap.csv">>
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
{bootstrap_type,
|
{bootstrap_type,
|
||||||
|
|
|
@ -124,8 +124,8 @@ test_bootstrap_file(Config0, Type, File) ->
|
||||||
test_bootstrap_file(Config0, Type, File, Opts) ->
|
test_bootstrap_file(Config0, Type, File, Opts) ->
|
||||||
{Type, Filename, _FileData} = sample_filename_and_data(Type, File),
|
{Type, Filename, _FileData} = sample_filename_and_data(Type, File),
|
||||||
Config2 = Config0#{
|
Config2 = Config0#{
|
||||||
boostrap_file => Filename,
|
bootstrap_file => Filename,
|
||||||
boostrap_type => Type
|
bootstrap_type => Type
|
||||||
},
|
},
|
||||||
{ok, State0} = emqx_authn_mnesia:create(?AUTHN_ID, Config2),
|
{ok, State0} = emqx_authn_mnesia:create(?AUTHN_ID, Config2),
|
||||||
Result = ets:tab2list(emqx_authn_mnesia),
|
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, "bin/install_upgrade.escript", "bin/install_upgrade.escript-{{release_version}}"},
|
||||||
{copy, "apps/emqx_gateway_lwm2m/lwm2m_xml", "etc/lwm2m_xml"},
|
{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/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.cmd", "bin/emqx.cmd"},
|
||||||
{template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"},
|
{template, "bin/emqx_ctl.cmd", "bin/emqx_ctl.cmd"},
|
||||||
{copy, "bin/nodetool", "bin/nodetool"},
|
{copy, "bin/nodetool", "bin/nodetool"},
|
||||||
|
|
Loading…
Reference in New Issue