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">>,
table => <<"mqtt">>,
pool_size => 8,
username => <<"root">>,
password => <<"******">>,
aws_access_key_id => <<"root">>,
aws_secret_access_key => <<"******">>,
template => ?DEFAULT_TEMPLATE,
local_topic => <<"local/topic/#">>,
resource_opts => #{

View File

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

View File

@ -52,32 +52,21 @@ roots() ->
fields(config) ->
[
{url, mk(binary(), #{required => true, desc => ?DESC("url")})},
{table, mk(binary(), #{required => true, desc => ?DESC("table")})}
| override_schemas(
emqx_connector_schema_lib:relational_db_fields()
)
{table, mk(binary(), #{required => true, desc => ?DESC("table")})},
{aws_access_key_id,
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
%%========================================================================================
@ -90,8 +79,8 @@ on_start(
InstanceId,
#{
url := Url,
username := Username,
password := Password,
aws_access_key_id := AccessKeyID,
aws_secret_access_key := SecretAccessKey,
table := Table,
pool_size := PoolSize
} = Config
@ -99,7 +88,7 @@ on_start(
?SLOG(info, #{
msg => "starting_dynamo_connector",
connector => InstanceId,
config => emqx_utils:redact(Config)
config => redact(Config)
}),
{Schema, Server} = get_host_schema(to_str(Url)),
@ -109,8 +98,8 @@ on_start(
{config, #{
host => Host,
port => Port,
username => to_str(Username),
password => to_str(Password),
aws_access_key_id => to_str(AccessKeyID),
aws_secret_access_key => to_str(SecretAccessKey),
schema => Schema
}},
{pool_size, PoolSize}
@ -251,13 +240,13 @@ execute([{put, _} | _] = Msgs, Table) ->
connect(Opts) ->
#{
username := Username,
password := Password,
aws_access_key_id := AccessKeyID,
aws_secret_access_key := SecretAccessKey,
host := Host,
port := Port,
schema := Schema
} = 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
%% 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]}) ->
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:
"""DynamoDB Table."""
table {
desc {
en: """DynamoDB Table."""
zh: """DynamoDB 的表。"""
}
label: {
en: "Table "
zh: "表"
}
}
table.label:
"""DynamoDB Table"""
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: "连接访问密钥"
}
}
}