feat(sqlserver): accept wrapped secrets as passwords

This commit is contained in:
Andrew Mayorov 2023-11-08 21:52:49 +07:00
parent 06861e377f
commit 7250059c60
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
3 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_sqlserver, [
{description, "EMQX Enterprise SQL Server Bridge"},
{vsn, "0.1.4"},
{vsn, "0.1.5"},
{registered, []},
{applications, [kernel, stdlib, emqx_resource, odbc]},
{env, []},

View File

@ -199,7 +199,7 @@ on_start(
Options = [
{server, to_bin(Server)},
{username, Username},
{password, emqx_secret:wrap(maps:get(password, Config, ""))},
{password, maps:get(password, Config, "")},
{driver, Driver},
{database, Database},
{pool_size, PoolSize}

View File

@ -130,7 +130,9 @@ end_per_group(_Group, _Config) ->
ok.
init_per_suite(Config) ->
Config.
Passfile = filename:join(?config(priv_dir, Config), "passfile"),
ok = file:write_file(Passfile, <<?SQL_SERVER_PASSWORD>>),
[{sqlserver_passfile, Passfile} | Config].
end_per_suite(_Config) ->
emqx_mgmt_api_test_util:end_suite(),
@ -193,7 +195,9 @@ t_setup_via_http_api_and_publish(Config) ->
SQLServerConfig0 = ?config(sqlserver_config, Config),
SQLServerConfig = SQLServerConfig0#{
<<"name">> => Name,
<<"type">> => BridgeType
<<"type">> => BridgeType,
%% NOTE: using literal password with HTTP API requests.
<<"password">> => <<?SQL_SERVER_PASSWORD>>
},
?assertMatch(
{ok, _},
@ -449,6 +453,7 @@ sqlserver_config(BridgeType, Config) ->
Name = atom_to_binary(?MODULE),
BatchSize = batch_size(Config),
QueryMode = ?config(query_mode, Config),
Passfile = ?config(sqlserver_passfile, Config),
ConfigString =
io_lib:format(
"bridges.~s.~s {\n"
@ -472,7 +477,7 @@ sqlserver_config(BridgeType, Config) ->
Server,
?SQL_SERVER_DATABASE,
?SQL_SERVER_USERNAME,
?SQL_SERVER_PASSWORD,
"file://" ++ Passfile,
?SQL_BRIDGE,
?SQL_SERVER_DRIVER,
BatchSize,