Jelajahi Sumber

fix(mgmt): avoid using base64:decode/2 and encode/2

they are not available in otp 25
zmstone 2 tahun lalu
induk
melakukan
2cc1c563df

+ 3 - 0
apps/emqx_management/include/emqx_mgmt.hrl

@@ -15,3 +15,6 @@
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 
 
 -define(DEFAULT_ROW_LIMIT, 100).
 -define(DEFAULT_ROW_LIMIT, 100).
+
+-define(URL_PARAM_INTEGER, url_param_integer).
+-define(URL_PARAM_BINARY, url_param_binary).

+ 11 - 12
apps/emqx_management/src/emqx_mgmt_api.erl

@@ -17,13 +17,12 @@
 -module(emqx_mgmt_api).
 -module(emqx_mgmt_api).
 
 
 -include_lib("stdlib/include/qlc.hrl").
 -include_lib("stdlib/include/qlc.hrl").
+-include("emqx_mgmt.hrl").
 
 
 -elvis([{elvis_style, dont_repeat_yourself, #{min_complexity => 100}}]).
 -elvis([{elvis_style, dont_repeat_yourself, #{min_complexity => 100}}]).
 
 
 -define(LONG_QUERY_TIMEOUT, 50000).
 -define(LONG_QUERY_TIMEOUT, 50000).
 
 
--define(CONT_BASE64_OPTS, #{mode => urlsafe, padding => false}).
-
 -export([
 -export([
     paginate/3
     paginate/3
 ]).
 ]).
@@ -151,19 +150,19 @@ decode_continuation(none, _Encoding) ->
 decode_continuation(end_of_data, _Encoding) ->
 decode_continuation(end_of_data, _Encoding) ->
     %% Clients should not send "after=end_of_data" back to the server
     %% Clients should not send "after=end_of_data" back to the server
     error;
     error;
-decode_continuation(Cont, none) ->
-    Cont;
-decode_continuation(Cont, base64) ->
-    base64:decode(Cont, ?CONT_BASE64_OPTS).
+decode_continuation(Cont, ?URL_PARAM_INTEGER) ->
+    binary_to_integer(Cont);
+decode_continuation(Cont, ?URL_PARAM_BINARY) ->
+    emqx_utils:hexstr_to_bin(Cont).
 
 
 encode_continuation(none, _Encoding) ->
 encode_continuation(none, _Encoding) ->
     none;
     none;
 encode_continuation(end_of_data, _Encoding) ->
 encode_continuation(end_of_data, _Encoding) ->
     end_of_data;
     end_of_data;
-encode_continuation(Cont, none) ->
-    emqx_utils_conv:bin(Cont);
-encode_continuation(Cont, base64) ->
-    base64:encode(emqx_utils_conv:bin(Cont), ?CONT_BASE64_OPTS).
+encode_continuation(Cont, ?URL_PARAM_INTEGER) ->
+    integer_to_binary(Cont);
+encode_continuation(Cont, ?URL_PARAM_BINARY) ->
+    emqx_utils:bin_to_hexstr(Cont).
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% Node Query
 %% Node Query
@@ -663,7 +662,7 @@ parse_pager_params(Params) ->
             false
             false
     end.
     end.
 
 
--spec parse_cont_pager_params(map(), none | base64) ->
+-spec parse_cont_pager_params(map(), ?URL_PARAM_INTEGER | ?URL_PARAM_BINARY) ->
     #{limit := pos_integer(), continuation := none | end_of_table | binary()} | false.
     #{limit := pos_integer(), continuation := none | end_of_table | binary()} | false.
 parse_cont_pager_params(Params, Encoding) ->
 parse_cont_pager_params(Params, Encoding) ->
     Cont = continuation(Params, Encoding),
     Cont = continuation(Params, Encoding),
@@ -675,7 +674,7 @@ parse_cont_pager_params(Params, Encoding) ->
             false
             false
     end.
     end.
 
 
--spec encode_cont_pager_params(map(), none | base64) -> map().
+-spec encode_cont_pager_params(map(), ?URL_PARAM_INTEGER | ?URL_PARAM_BINARY) -> map().
 encode_cont_pager_params(#{continuation := Cont} = Meta, ContEncoding) ->
 encode_cont_pager_params(#{continuation := Cont} = Meta, ContEncoding) ->
     Meta1 = maps:remove(continuation, Meta),
     Meta1 = maps:remove(continuation, Meta),
     Meta1#{last => encode_continuation(Cont, ContEncoding)};
     Meta1#{last => encode_continuation(Cont, ContEncoding)};

+ 2 - 2
apps/emqx_management/src/emqx_mgmt_api_clients.erl

@@ -1166,9 +1166,9 @@ maybe_cast_cont(_, PagerParams) ->
     PagerParams.
     PagerParams.
 
 
 %% integer packet id
 %% integer packet id
-cont_encoding(inflight_msgs) -> none;
+cont_encoding(inflight_msgs) -> ?URL_PARAM_INTEGER;
 %% binary message id
 %% binary message id
-cont_encoding(mqueue_msgs) -> base64.
+cont_encoding(mqueue_msgs) -> ?URL_PARAM_BINARY.
 
 
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 %% QueryString to Match Spec
 %% QueryString to Match Spec