From 40948f3c0bdb5fd026259ed4b6a635bd8003c347 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Mon, 16 Jan 2023 11:49:18 +0800 Subject: [PATCH] fix(influxdb): authentication is not required for influxdb v1 api --- changes/v5.0.15/fix-9680.en.md | 1 + changes/v5.0.15/fix-9680.zh.md | 1 + .../src/emqx_ee_connector_influxdb.erl | 27 ++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 changes/v5.0.15/fix-9680.en.md create mode 100644 changes/v5.0.15/fix-9680.zh.md diff --git a/changes/v5.0.15/fix-9680.en.md b/changes/v5.0.15/fix-9680.en.md new file mode 100644 index 000000000..2ee3caaa5 --- /dev/null +++ b/changes/v5.0.15/fix-9680.en.md @@ -0,0 +1 @@ +Fix the problem that username and password authentication is mandatory in Influxdb v1 write API. diff --git a/changes/v5.0.15/fix-9680.zh.md b/changes/v5.0.15/fix-9680.zh.md new file mode 100644 index 000000000..bd1ace306 --- /dev/null +++ b/changes/v5.0.15/fix-9680.zh.md @@ -0,0 +1 @@ +修复 InfluxDB v1 桥接写入 API 配置中强制需要用户名密码认证的问题。 diff --git a/lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl b/lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl index db99c4475..553e5369f 100644 --- a/lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl +++ b/lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl @@ -278,19 +278,18 @@ client_config( ] ++ protocol_config(Config). %% api v1 config -protocol_config(#{ - username := Username, - password := Password, - database := DB, - ssl := SSL -}) -> +protocol_config( + #{ + database := DB, + ssl := SSL + } = Config +) -> [ {protocol, http}, {version, v1}, - {username, str(Username)}, - {password, str(Password)}, {database, str(DB)} - ] ++ ssl_config(SSL); + ] ++ username(Config) ++ + password(Config) ++ ssl_config(SSL); %% api v2 config protocol_config(#{ bucket := Bucket, @@ -321,6 +320,16 @@ ssl_config(SSL = #{enable := true}) -> {transport, ssl} ] ++ maps:to_list(maps:remove(enable, SSL)). +username(#{username := Username}) -> + [{username, str(Username)}]; +username(_) -> + []. + +password(#{password := Password}) -> + [{password, str(Password)}]; +password(_) -> + []. + %% ------------------------------------------------------------------------------------------------- %% Query do_query(InstId, Client, Points) ->