fix(dynamo): fix terminology erros

- Changed `username` to `aws_access_key_id`
- Changed `password` to `aws_secret_access_key`
This commit is contained in:
firest 2023-04-19 15:56:46 +08:00
parent b112f544a9
commit e89f4d4565
5 changed files with 68 additions and 48 deletions

View File

@ -1,3 +1,5 @@
Fix a configuration item name error in the DynamoDB data bridge. Fix some configuration item terminology errors in the DynamoDB data bridge:
Changed `database` to `table`, because there is no term like `database` in DynamoDB, the correct concept should be `table` - Changed `database` to `table`
- Changed `username` to `aws_access_key_id`
- Changed `password` to `aws_secret_access_key`

View File

@ -45,8 +45,8 @@ values(_Method) ->
url => <<"http://127.0.0.1:8000">>, url => <<"http://127.0.0.1:8000">>,
table => <<"mqtt">>, table => <<"mqtt">>,
pool_size => 8, pool_size => 8,
username => <<"root">>, aws_access_key_id => <<"root">>,
password => <<"******">>, aws_secret_access_key => <<"******">>,
template => ?DEFAULT_TEMPLATE, template => ?DEFAULT_TEMPLATE,
local_topic => <<"local/topic/#">>, local_topic => <<"local/topic/#">>,
resource_opts => #{ resource_opts => #{

View File

@ -14,8 +14,8 @@
% DB defaults % DB defaults
-define(TABLE, "mqtt"). -define(TABLE, "mqtt").
-define(TABLE_BIN, to_bin(?TABLE)). -define(TABLE_BIN, to_bin(?TABLE)).
-define(USERNAME, "root"). -define(ACCESS_KEY_ID, "root").
-define(PASSWORD, "public"). -define(SECRET_ACCESS_KEY, "public").
-define(HOST, "dynamo"). -define(HOST, "dynamo").
-define(PORT, 8000). -define(PORT, 8000).
-define(SCHEMA, "http://"). -define(SCHEMA, "http://").
@ -159,8 +159,8 @@ dynamo_config(BridgeType, Config) ->
" enable = true\n" " enable = true\n"
" url = ~p\n" " url = ~p\n"
" table = ~p\n" " table = ~p\n"
" username = ~p\n" " aws_access_key_id = ~p\n"
" password = ~p\n" " aws_secret_access_key = ~p\n"
" resource_opts = {\n" " resource_opts = {\n"
" request_timeout = 500ms\n" " request_timeout = 500ms\n"
" batch_size = ~b\n" " batch_size = ~b\n"
@ -172,8 +172,8 @@ dynamo_config(BridgeType, Config) ->
Name, Name,
Url, Url,
?TABLE, ?TABLE,
?USERNAME, ?ACCESS_KEY_ID,
?PASSWORD, ?SECRET_ACCESS_KEY,
BatchSize, BatchSize,
QueryMode QueryMode
] ]
@ -244,10 +244,10 @@ delete_table(_Config) ->
setup_dynamo(Config) -> setup_dynamo(Config) ->
Host = ?GET_CONFIG(host, Config), Host = ?GET_CONFIG(host, Config),
Port = ?GET_CONFIG(port, Config), Port = ?GET_CONFIG(port, Config),
erlcloud_ddb2:configure(?USERNAME, ?PASSWORD, Host, Port, ?SCHEMA). erlcloud_ddb2:configure(?ACCESS_KEY_ID, ?SECRET_ACCESS_KEY, Host, Port, ?SCHEMA).
directly_setup_dynamo() -> directly_setup_dynamo() ->
erlcloud_ddb2:configure(?USERNAME, ?PASSWORD, ?HOST, ?PORT, ?SCHEMA). erlcloud_ddb2:configure(?ACCESS_KEY_ID, ?SECRET_ACCESS_KEY, ?HOST, ?PORT, ?SCHEMA).
directly_query(Query) -> directly_query(Query) ->
directly_setup_dynamo(), directly_setup_dynamo(),

View File

@ -52,32 +52,21 @@ roots() ->
fields(config) -> fields(config) ->
[ [
{url, mk(binary(), #{required => true, desc => ?DESC("url")})}, {url, mk(binary(), #{required => true, desc => ?DESC("url")})},
{table, mk(binary(), #{required => true, desc => ?DESC("table")})} {table, mk(binary(), #{required => true, desc => ?DESC("table")})},
| override_schemas( {aws_access_key_id,
emqx_connector_schema_lib:relational_db_fields() mk(
) binary(),
#{required => true, desc => ?DESC("aws_access_key_id")}
)},
{aws_secret_access_key,
mk(
binary(),
#{required => true, desc => ?DESC("aws_secret_access_key")}
)},
{pool_size, fun emqx_connector_schema_lib:pool_size/1},
{auto_reconnect, fun emqx_connector_schema_lib:auto_reconnect/1}
]. ].
override_schemas(Fields) ->
lists:foldr(
fun
({username, OrigUsernameFn}, Acc) ->
[{username, add_default_fn(OrigUsernameFn, <<"root">>)} | Acc];
({database, _}, Acc) ->
Acc;
(Field, Acc) ->
[Field | Acc]
end,
[],
Fields
).
add_default_fn(OrigFn, Default) ->
fun
(default) -> Default;
(Field) -> OrigFn(Field)
end.
%%======================================================================================== %%========================================================================================
%% `emqx_resource' API %% `emqx_resource' API
%%======================================================================================== %%========================================================================================
@ -90,8 +79,8 @@ on_start(
InstanceId, InstanceId,
#{ #{
url := Url, url := Url,
username := Username, aws_access_key_id := AccessKeyID,
password := Password, aws_secret_access_key := SecretAccessKey,
table := Table, table := Table,
pool_size := PoolSize pool_size := PoolSize
} = Config } = Config
@ -99,7 +88,7 @@ on_start(
?SLOG(info, #{ ?SLOG(info, #{
msg => "starting_dynamo_connector", msg => "starting_dynamo_connector",
connector => InstanceId, connector => InstanceId,
config => emqx_utils:redact(Config) config => redact(Config)
}), }),
{Schema, Server} = get_host_schema(to_str(Url)), {Schema, Server} = get_host_schema(to_str(Url)),
@ -109,8 +98,8 @@ on_start(
{config, #{ {config, #{
host => Host, host => Host,
port => Port, port => Port,
username => to_str(Username), aws_access_key_id => to_str(AccessKeyID),
password => to_str(Password), aws_secret_access_key => to_str(SecretAccessKey),
schema => Schema schema => Schema
}}, }},
{pool_size, PoolSize} {pool_size, PoolSize}
@ -251,13 +240,13 @@ execute([{put, _} | _] = Msgs, Table) ->
connect(Opts) -> connect(Opts) ->
#{ #{
username := Username, aws_access_key_id := AccessKeyID,
password := Password, aws_secret_access_key := SecretAccessKey,
host := Host, host := Host,
port := Port, port := Port,
schema := Schema schema := Schema
} = proplists:get_value(config, Opts), } = proplists:get_value(config, Opts),
erlcloud_ddb2:configure(Username, Password, Host, Port, Schema), erlcloud_ddb2:configure(AccessKeyID, SecretAccessKey, Host, Port, Schema),
%% The dynamodb driver uses caller process as its connection process %% The dynamodb driver uses caller process as its connection process
%% so at here, the connection process is the ecpool worker self %% so at here, the connection process is the ecpool worker self
@ -342,3 +331,6 @@ convert2binary(Value) when is_map(Value) ->
do_async_reply(Result, {ReplyFun, [Context]}) -> do_async_reply(Result, {ReplyFun, [Context]}) ->
ReplyFun(Context, Result). ReplyFun(Context, Result).
redact(Data) ->
emqx_utils:redact(Data, fun(Any) -> Any =:= aws_secret_access_key end).

View File

@ -11,10 +11,36 @@ emqx_ee_connector_dynamo {
} }
} }
table.desc: table {
"""DynamoDB Table.""" desc {
en: """DynamoDB Table."""
table.label: zh: """DynamoDB 的表。"""
"""DynamoDB Table""" }
label: {
en: "Table "
zh: "表"
}
}
aws_access_key_id {
desc {
en: """Access Key ID for connecting to DynamoDB."""
zh: """DynamoDB 的访问 ID。"""
}
label: {
en: "AWS Access Key ID"
zh: "连接访问 ID"
}
}
aws_secret_access_key {
desc {
en: """AWS Secret Access Key for connecting to DynamoDB."""
zh: """DynamoDB 的访问密钥。"""
}
label: {
en: "AWS Secret Access Key"
zh: "连接访问密钥"
}
}
} }