emqx_plugins_schema.erl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2021-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_plugins_schema).
  17. -behaviour(hocon_schema).
  18. -export([
  19. roots/0,
  20. fields/1,
  21. namespace/0
  22. ]).
  23. -include_lib("hocon/include/hoconsc.hrl").
  24. -include("emqx_plugins.hrl").
  25. namespace() -> "plugin".
  26. roots() -> [{?CONF_ROOT, ?HOCON(?R_REF(?CONF_ROOT), #{importance => ?IMPORTANCE_LOW})}].
  27. fields(?CONF_ROOT) ->
  28. #{
  29. fields => root_fields(),
  30. desc => ?DESC(?CONF_ROOT)
  31. };
  32. fields(state) ->
  33. #{
  34. fields => state_fields(),
  35. desc => ?DESC(state)
  36. }.
  37. state_fields() ->
  38. [
  39. {name_vsn,
  40. ?HOCON(
  41. string(),
  42. #{
  43. desc => ?DESC(name_vsn),
  44. required => true
  45. }
  46. )},
  47. {enable,
  48. ?HOCON(
  49. boolean(),
  50. #{
  51. desc => ?DESC(enable),
  52. required => true
  53. }
  54. )}
  55. ].
  56. root_fields() ->
  57. [
  58. {states, fun states/1},
  59. {install_dir, fun install_dir/1},
  60. {check_interval, fun check_interval/1}
  61. ].
  62. states(type) -> ?ARRAY(?R_REF(state));
  63. states(required) -> false;
  64. states(default) -> [];
  65. states(desc) -> ?DESC(states);
  66. states(importance) -> ?IMPORTANCE_HIGH;
  67. states(_) -> undefined.
  68. install_dir(type) -> string();
  69. install_dir(required) -> false;
  70. %% runner's root dir todo move to data dir in 5.1
  71. install_dir(default) -> <<"plugins">>;
  72. install_dir(desc) -> ?DESC(install_dir);
  73. install_dir(importance) -> ?IMPORTANCE_LOW;
  74. install_dir(_) -> undefined.
  75. check_interval(type) -> emqx_schema:duration();
  76. check_interval(default) -> <<"5s">>;
  77. check_interval(desc) -> ?DESC(check_interval);
  78. check_interval(deprecated) -> {since, "5.0.24"};
  79. check_interval(_) -> undefined.