emqx_plugins_schema.erl 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2021-2022 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([ roots/0
  19. , fields/1
  20. , namespace/0
  21. ]).
  22. -include_lib("typerefl/include/types.hrl").
  23. -include("emqx_plugins.hrl").
  24. namespace() -> "plugin".
  25. roots() -> [?CONF_ROOT].
  26. fields(?CONF_ROOT) ->
  27. #{fields => root_fields(),
  28. desc => """
  29. Manage EMQ X plugins.
  30. <br>
  31. Plugins can be pre-built as a part of EMQ X package,
  32. or installed as a standalone package in a location specified by
  33. <code>install_dir</code> config key
  34. <br>
  35. The standalone-installed plugins are referred to as 'external' plugins.
  36. """
  37. };
  38. fields(state) ->
  39. #{ fields => state_fields(),
  40. desc => "A per-plugin config to describe the desired state of the plugin."
  41. }.
  42. state_fields() ->
  43. [ {name_vsn,
  44. hoconsc:mk(string(),
  45. #{ desc => "The {name}-{version} of the plugin.<br>"
  46. "It should match the plugin application name-version as the "
  47. "for the plugin release package name<br>"
  48. "For example: my_plugin-0.1.0."
  49. , nullable => false
  50. })}
  51. , {enable,
  52. hoconsc:mk(boolean(),
  53. #{ desc => "Set to 'true' to enable this plugin"
  54. , nullable => false
  55. })}
  56. ].
  57. root_fields() ->
  58. [ {states, fun states/1}
  59. , {install_dir, fun install_dir/1}
  60. ].
  61. states(type) -> hoconsc:array(hoconsc:ref(state));
  62. states(nullable) -> true;
  63. states(default) -> [];
  64. states(desc) -> "An array of plugins in the desired states.<br>"
  65. "The plugins are started in the defined order";
  66. states(_) -> undefined.
  67. install_dir(type) -> string();
  68. install_dir(nullable) -> true;
  69. install_dir(default) -> "plugins"; %% runner's root dir
  70. install_dir(T) when T =/= desc -> undefined;
  71. install_dir(desc) -> """
  72. In which directory are the external plugins installed.
  73. The plugin beam files and configuration files should reside in
  74. the sub-directory named as <code>emqx_foo_bar-0.1.0</code>.
  75. <br>
  76. NOTE: For security reasons, this directory should **NOT** be writable
  77. by anyone expect for <code>emqx</code> (or any user which runs EMQ X)
  78. """.