Skip to content

Commit a4fdd96

Browse files
committed
🐛 [HDK-8201] Retainer: fixing emqx plugin.
- Fixing retainer functionality with redis.
1 parent ae20586 commit a4fdd96

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

rebar.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
, {emqx_durable_storage, {git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.1.4"}, "apps/emqx_durable_storage"}}
99
%% this is my plugin's dependency
1010
, {map_sets, "1.1.0"}
11+
, {eredis_cluster, {git, "https://github.com/emqx/eredis_cluster", {tag, "0.8.3"}}}
12+
, {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "v0.4.2"}}}
1113
]}.
1214

1315
{plugins, [
@@ -30,9 +32,9 @@
3032
, {builder,
3133
[ {name, "ubidots"}
3234
, {contact, "[email protected]"}
33-
, {website, "http://example.com"}
35+
, {website, "http://ubidots.com"}
3436
]}
35-
, {repo, "https://github.com/emqx/emqx-plugin-template"}
37+
, {repo, "https://github.com/jdavidagudelo/emqx-plugin-template-test.git"}
3638
, {functionality, ["Demo"]}
3739
, {compatibility,
3840
[ {emqx, "~> 5.0"}

src/ubidots_emqx_core_redis_cli.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ get_value_by_key(Pool, VariableKey, Type) ->
6262

6363
get_values_loop_redis(_Pool, _Type, []) ->
6464
[];
65+
get_values_loop_redis(Pool, Type, [_ValueKind, _Topic, undefined | RestData]) ->
66+
get_values_loop_redis(Pool, Type, RestData);
6567
get_values_loop_redis(Pool, Type, [ValueKind, Topic, VariableId | RestData]) ->
6668
VariableKey = string:concat(get_variable_key(ValueKind), binary_to_list(VariableId)),
6769
{ok, Value} = get_value_by_key(Pool, VariableKey, Type),

src/ubidots_emqx_plugin.app.src

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
{application, ubidots_emqx_plugin, [
2-
{description, "Another amazing EMQX plugin."},
3-
{vsn, "0.1.0"},
4-
{modules, []},
5-
{registered, [ubidots_emqx_plugin_sup]},
6-
{applications, [kernel, stdlib, map_sets]},
7-
{mod, {ubidots_emqx_plugin_app, []}},
8-
{env, []},
9-
{licenses, ["Apache-2.0"]},
10-
{maintainers, ["ubidots <devel@ubidots.com>"]}
11-
]}.
1+
{application, ubidots_emqx_plugin,
2+
[{description, "Another amazing EMQX plugin."},
3+
{vsn, "0.1.0"},
4+
{modules, []},
5+
{registered, [ubidots_emqx_plugin_sup]},
6+
{applications, [kernel, stdlib, map_sets]},
7+
{mod, {ubidots_emqx_plugin_app, []}},
8+
{env, []},
9+
{licenses, ["Apache-2.0"]},
10+
{maintainers, ["ubidots <ubidots@email.com>"]}
11+
]}.

src/ubidots_emqx_reactor_redis_cli.erl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,20 @@ binary_to_list_validated(undefined) ->
9494
binary_to_list_validated(Value) ->
9595
binary_to_list(Value).
9696

97+
can_view_value_device(_Pool, _Type, _PermissionType, _OwnerId, "*", _Token) ->
98+
"1";
9799
can_view_value_device(_Pool, _Type, "all", _OwnerId, _DeviceLabel, _Token) ->
98-
true;
99-
can_view_value_device(Pool, Type, _, OwnerId, DeviceLabel, Token) ->
100+
"1";
101+
can_view_value_device(Pool, Type, _PermissionType, OwnerId, DeviceLabel, Token) ->
100102
DeviceHashSetKey = "reactor_variables/" ++ OwnerId,
101103
DeviceLabelKey = "/" ++ DeviceLabel,
102104
TokenKey = "reactor_devices_with_permissions/view_value/" ++ Token,
103105
DeviceId = execute_redis_command(Pool, Type, ["HGET", DeviceHashSetKey, DeviceLabelKey]),
104106
CanViewValueDevice = execute_redis_command(Pool, Type, ["SISMEMBER", TokenKey, DeviceId]),
105107
binary_to_list_validated(CanViewValueDevice).
106108

109+
get_topics_mqtt_by_topic(none, _Topic, _VariableId) ->
110+
[];
107111
get_topics_mqtt_by_topic(last_value, Topic, VariableId) ->
108112
[atom_to_list(last_value), Topic ++ "/lv", VariableId];
109113
get_topics_mqtt_by_topic(value, Topic, VariableId) ->
@@ -151,11 +155,20 @@ get_device_labels(Pool, Type, Token) ->
151155
DeviceIds = execute_redis_command(Pool, Type, ["SMEMBERS", DeviceIdsKey]),
152156
get_device_labels_by_device_ids(Pool, Type, DeviceIds).
153157

158+
get_mqtt_topics_device_labels_and_variable_label(_Pool, _Type, _CanViewDevice, [], _VariableLabel, _OwnerId, _Token, _TopicKind, _Version) ->
159+
[];
160+
get_mqtt_topics_device_labels_and_variable_label(Pool, Type, CanViewDevice, [DeviceLabel | Rest], VariableLabel, OwnerId, Token, TopicKind, Version) ->
161+
get_mqtt_topics_by_label(Pool, Type, CanViewDevice, DeviceLabel, VariableLabel, OwnerId, Token, TopicKind, Version) ++
162+
get_mqtt_topics_device_labels_and_variable_label(Pool, Type, CanViewDevice, Rest, VariableLabel, OwnerId, Token, TopicKind, Version).
163+
154164
get_mqtt_topics_by_label(Pool, Type, "1", "*", "*", OwnerId, Token, TopicKind, Version) ->
155165
DeviceLabels = get_device_labels(Pool, Type, Token),
156166
get_mqtt_topics_by_device_labels(Pool, Type, DeviceLabels, OwnerId, TopicKind, Version);
157167
get_mqtt_topics_by_label(Pool, Type, "1", DeviceLabel, "*", OwnerId, _, TopicKind, Version) ->
158168
get_mqtt_topics_by_device_labels(Pool, Type, [DeviceLabel], OwnerId, TopicKind, Version);
169+
get_mqtt_topics_by_label(Pool, Type, "1", "*", VariableLabel, OwnerId, Token, TopicKind, Version) ->
170+
DeviceLabels = get_device_labels(Pool, Type, Token),
171+
get_mqtt_topics_device_labels_and_variable_label(Pool, Type, "1", DeviceLabels, VariableLabel, OwnerId, Token, TopicKind, Version);
159172
get_mqtt_topics_by_label(
160173
Pool, Type, "1", DeviceLabel, VariableLabel, OwnerId, _, TopicKind, Version
161174
) ->

0 commit comments

Comments
 (0)