Просмотр исходного кода

chore(license): change `key` type to `binary()`

So that the `raw_default` field in the schema JSON renders properly.
Thales Macedo Garitezi 3 лет назад
Родитель
Сommit
a9d0143d5f
2 измененных файлов с 16 добавлено и 7 удалено
  1. 9 2
      bin/nodetool
  2. 7 5
      lib-ee/emqx_license/src/emqx_license_schema.erl

+ 9 - 2
bin/nodetool

@@ -24,12 +24,19 @@ main(Args) ->
         ["hocon" | Rest] ->
             %% forward the call to hocon_cli
             hocon_cli:main(Rest);
-        ["check_license_key", Key] ->
-            check_license(#{key => list_to_binary(Key)});
+        ["check_license_key", Key0] ->
+            Key = cleanup_key(Key0),
+            check_license(#{key => Key});
         _ ->
             do(Args)
     end.
 
+%% the key is a string (list) representation of a binary, so we need
+%% to remove the leading and trailing angle brackets.
+cleanup_key(Str0) ->
+    Str1 = iolist_to_binary(string:replace(Str0, "<<", "", leading)),
+    iolist_to_binary(string:replace(Str1, ">>", "", trailing)).
+
 do(Args) ->
     ok = do_with_halt(Args, "mnesia_dir", fun create_mnesia_dir/2),
     ok = do_with_halt(Args, "chkconfig", fun("-config", X) -> chkconfig(X) end),

+ 7 - 5
lib-ee/emqx_license/src/emqx_license_schema.erl

@@ -37,7 +37,7 @@ tags() ->
 fields(key_license) ->
     [
         {key, #{
-            type => string(),
+            type => binary(),
             default => default_license(),
             %% so it's not logged
             sensitive => true,
@@ -85,7 +85,9 @@ check_license_watermark(Conf) ->
 %% NOTE: when updating a new key, the schema doc in emqx_license_schema_i18n.conf
 %% should be updated accordingly
 default_license() ->
-    "MjIwMTExCjAKMTAKRXZhbHVhdGlvbgpjb250YWN0QGVtcXguaW8KZ"
-    "GVmYXVsdAoyMDIzMDEwOQoxODI1CjEwMAo=.MEUCIG62t8W15g05f"
-    "1cKx3tA3YgJoR0dmyHOPCdbUxBGxgKKAiEAhHKh8dUwhU+OxNEaOn"
-    "8mgRDtiT3R8RZooqy6dEsOmDI=".
+    <<
+        "MjIwMTExCjAKMTAKRXZhbHVhdGlvbgpjb250YWN0QGVtcXguaW8KZ"
+        "GVmYXVsdAoyMDIzMDEwOQoxODI1CjEwMAo=.MEUCIG62t8W15g05f"
+        "1cKx3tA3YgJoR0dmyHOPCdbUxBGxgKKAiEAhHKh8dUwhU+OxNEaOn"
+        "8mgRDtiT3R8RZooqy6dEsOmDI="
+    >>.