chore(psk): improve configuration file

This commit is contained in:
zhouzb 2021-09-18 17:27:04 +08:00
parent 7c61bc18cf
commit 2f18f5e8b5
3 changed files with 21 additions and 9 deletions

View File

@ -1,7 +1,19 @@
##--------------------------------------------------------------------
## EMQ X PSK
##--------------------------------------------------------------------
psk { psk {
## Whether to enable the PSK feature.
enable = true enable = true
# boot_file = {{ platform_data_dir }}/boot.psk ## If boot file is specified, emqx will import PSKs from the file
## into the built-in database at startup for use by the runtime.
##
## The file has to be structured line-by-line, each line must be in
## the format: <PSKIdentity>:<SharedSecret>
## boot_file = {{ platform_data_dir }}/boot.psk
# delimiter = ":" ## Specifies the separator for PSKIdentity and SharedSecret in the boot file.
## The default is colon (:)
## separator = ":"
} }

View File

@ -148,15 +148,15 @@ is_enable() ->
boot_file() -> boot_file() ->
emqx_config:get([psk, boot_file], undefined). emqx_config:get([psk, boot_file], undefined).
delimiter() -> separator() ->
emqx_config:get([psk, delimiter], ?DEFAULT_DELIMITER). emqx_config:get([psk, separator], ?DEFAULT_DELIMITER).
import_psks(SrcFile) -> import_psks(SrcFile) ->
case file:open(SrcFile, [read, raw, binary, read_ahead]) of case file:open(SrcFile, [read, raw, binary, read_ahead]) of
{error, Reason} -> {error, Reason} ->
{error, Reason}; {error, Reason};
{ok, Io} -> {ok, Io} ->
case Result = import_psks(Io, delimiter()) of case Result = import_psks(Io, separator()) of
ok -> ignore; ok -> ignore;
{error, Reason} -> {error, Reason} ->
?LOG("Failed to import psk from ~s due to ~p", [SrcFile, Reason]) ?LOG("Failed to import psk from ~s due to ~p", [SrcFile, Reason])

View File

@ -29,7 +29,7 @@ roots() -> [].
fields("psk") -> fields("psk") ->
[ {enable, fun enable/1} [ {enable, fun enable/1}
, {boot_file, fun boot_file/1} , {boot_file, fun boot_file/1}
, {delimiter, fun delimiter/1} , {separator, fun separator/1}
]. ].
enable(type) -> boolean(); enable(type) -> boolean();
@ -40,6 +40,6 @@ boot_file(type) -> binary();
boot_file(nullable) -> true; boot_file(nullable) -> true;
boot_file(_) -> undefined. boot_file(_) -> undefined.
delimiter(type) -> binary(); separator(type) -> binary();
delimiter(default) -> <<":">>; separator(default) -> <<":">>;
delimiter(_) -> undefined. separator(_) -> undefined.