From 4333ab5af89cbf236c3f111c5fd11936d47aa517 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Mon, 6 May 2024 10:59:37 +0800 Subject: [PATCH] fix: config.hocon.enterprise.example for plugin and bump template file --- README.md | 5 +- README_template.md | 1 + emqx-plugin.template | 17 ++- priv/config.hocon | 4 - priv/config.hocon.example | 20 +++ priv/config_schema.avsc.enterprise.example | 141 +++++++++++++++++++++ priv/config_schema.avsc.example | 85 +------------ rebar_template.config | 2 +- 8 files changed, 186 insertions(+), 89 deletions(-) delete mode 100644 priv/config.hocon create mode 100644 priv/config.hocon.example create mode 100644 priv/config_schema.avsc.enterprise.example diff --git a/README.md b/README.md index 1cffcaef..61b67ef0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ A plugin template for Elixir (experimental) can be found at https://github.com/e ## Prerequisites + A working build environment (eg `build_essential`) including `make` - + Erlang OTP 25 or newer recommended + + ASDF tool-chains recommended to manage EMQX released Erlang/OTP. + + **MUST** use OTP 25 For docker image deployment. See also [./.tool-versions](./.tool-versions) and [EMQX Release v5.5.0](https://github.com/emqx/emqx/releases/tag/v5.5.0). + rebar3 ## Usage @@ -32,6 +33,8 @@ $ make -C my_emqx_plugin rel > [!NOTE] > In order to use the AVRO config schema feature, please make sure the plugin template tag version >= 5.7.0 +> Rename files in the `./priv` directory to ensure that EMQX can load them correctly after the plugin is installed. +> See also [EMQX Documents - Plugins](https://www.emqx.io/docs/en/latest/extensions/plugins.html) for more detail. > [!NOTE] > If the `REBAR_CACHE_DIR` environment variable has been set, the directory for templates should be `$REBAR_CACHE_DIR/.config/rebar3/templates`. diff --git a/README_template.md b/README_template.md index ad35d090..8c5a2562 100644 --- a/README_template.md +++ b/README_template.md @@ -9,6 +9,7 @@ An EMQX plugin release is a tar file including including a subdirectory of this 1. A JSON format metadata file describing the plugin 2. Versioned directories for all applications needed for this plugin (source and binaries). +3. Confirm the OTP version used by EMQX that the plugin will be installed on (See also [./.tool-versions](./.tool-versions)). In a shell from this plugin's working directory execute `make rel` to have the package created like: diff --git a/emqx-plugin.template b/emqx-plugin.template index 6ef47b41..5060e6ad 100644 --- a/emqx-plugin.template +++ b/emqx-plugin.template @@ -3,20 +3,29 @@ {description, "Another amazing EMQX plugin."}, {version, "1.0.0", "The release version of this plugin."}, {app_vsn, "0.1.0", "The erlang application vsn value."}, - {emqx_vsn, "v5.4.1", "EMQX version to use as a dependency."}, + {emqx_vsn, "v5.6.1", "EMQX version to use as a dependency."}, {license, "Apache-2.0", "Short identifier for license you want to distribute this plugin under."}, {author_website, "http://example.com", "A website with details about the author."}, {repo, "https://github.com/emqx/emqx-plugin-template", "Where to find the source code for this plugin."} ]}. {dir, "{{name}}/src"}. {dir, "{{name}}/priv"}. +{dir, "{{name}}/scripts"}. +{file, ".tool-versions", "{{name}}/.tool-versions"}. {file, "LICENSE", "{{name}}/LICENSE"}. {file, "Makefile", "{{name}}/Makefile"}. {file, "erlang_ls.config", "{{name}}/erlang_ls.config"}. -{file, "get-rebar3", "{{name}}/get-rebar3"}. -{file, "priv/config.hocon", "{{name}}/priv/config.hocon"}. + +{file, "priv/config.hocon.example", "{{name}}/priv/config.hocon.example"}. +{file, "priv/config_schema.avsc.enterprise.example", "{{name}}/priv/config_schema.avsc.enterprise.example"}. +{file, "priv/config_schema.avsc.example", "{{name}}/priv/config_schema.avsc.example"}. +{file, "priv/config_i18n.json.example", "{{name}}/priv/config_i18n.json.example"}. + +{file, "scripts/ensure-rebar3.sh", "{{name}}/scripts/ensure-rebar3.sh"}. +{file, "scripts/get-otp-vsn.sh", "{{name}}/scripts/get-otp-vsn.sh"}. {file, "gitignore_template", "{{name}}/.gitignore"}. -{chmod, "{{name}}/get-rebar3", 8#755}. +{chmod, "{{name}}/scripts/ensure-rebar3.sh", 8#755}. +{chmod, "{{name}}/scripts/get-otp-vsn.sh", 8#755}. {template, "README_template.md", "{{name}}/README.md"}. {template, "rebar_template.config", "{{name}}/rebar.config"}. {template, "src/emqx_plugin_template.app.src", "{{name}}/src/{{name}}.app.src"}. diff --git a/priv/config.hocon b/priv/config.hocon deleted file mode 100644 index 52328f74..00000000 --- a/priv/config.hocon +++ /dev/null @@ -1,4 +0,0 @@ -## This is a demo config in HOCON format -## The same format used by EMQX since 5.0 - -magic_n = 42 diff --git a/priv/config.hocon.example b/priv/config.hocon.example new file mode 100644 index 00000000..aac3d33c --- /dev/null +++ b/priv/config.hocon.example @@ -0,0 +1,20 @@ +## This is a demo config in HOCON format +## The same format used by EMQX since 5.0 + +hostname = "localhost" +port = 3306 + +connectionOptions = [ + { + optionName = "autoReconnect" + optionType = "string" + optionValue = "true" + } +] + +auth { + username = "admin" + password { + string = "Public123" + } +} diff --git a/priv/config_schema.avsc.enterprise.example b/priv/config_schema.avsc.enterprise.example new file mode 100644 index 00000000..851bea21 --- /dev/null +++ b/priv/config_schema.avsc.enterprise.example @@ -0,0 +1,141 @@ +{ + "type": "record", + "name": "ExtendedConfig", + "fields": [ + { + "name": "hostname", + "type": "string", + "default": "localhost", + "$ui": { + "component": "input", + "flex": 12, + "required": true, + "label": "$hostname_label", + "description": "$hostname_desc", + "rules": [ + { + "type": "pattern", + "pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$", + "message": "$hostname_validate" + } + ] + } + }, + { + "name": "port", + "type": "int", + "default": 3306, + "$ui": { + "component": "input-number", + "flex": 12, + "required": true, + "label": "$port_label", + "description": "$port_desc", + "rules": [ + { + "type": "range", + "min": 1, + "max": 65535, + "message": "$port_range_validate" + } + ] + } + }, + { + "name": "connectionOptions", + "type": { + "type": "array", + "items": { + "type": "record", + "name": "ConnectionOption", + "fields": [ + { + "name": "optionName", + "type": "string" + }, + { + "name": "optionValue", + "type": "string" + }, + { + "name": "optionType", + "type": "string" + } + ] + } + }, + "default": [ + { + "optionName": "autoReconnect", + "optionValue": "true", + "optionType": "boolean" + } + ], + "$ui": { + "component": "maps-editor", + "flex": 24, + "items": { + "optionName": { + "label": "$option_name_label", + "description": "$option_name_desc", + "type": "string" + }, + "optionValue": { + "label": "$option_value_label", + "description": "$option_value_desc", + "type": "string" + } + }, + "label": "$connection_options_label", + "description": "$connection_options_desc" + } + }, + { + "name": "auth", + "type": { + "type": "record", + "name": "authConfigs", + "fields": [ + { + "name": "username", + "type": "string", + "$ui": { + "component": "input", + "flex": 12, + "required": true, + "label": "$username_label", + "description": "$username_desc" + } + }, + { + "name": "password", + "type": [ + "null", + "string" + ], + "default": null, + "$ui": { + "component": "input-password", + "flex": 12, + "label": "$password_label", + "description": "$password_desc", + "rules": [ + { + "type": "length", + "minLength": 8, + "maxLength": 128, + "message": "$password_length_validate" + }, + { + "type": "pattern", + "pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]*$", + "message": "$password_validate" + } + ] + } + } + ] + } + } + ] +} diff --git a/priv/config_schema.avsc.example b/priv/config_schema.avsc.example index 73ac29b5..a349c065 100644 --- a/priv/config_schema.avsc.example +++ b/priv/config_schema.avsc.example @@ -5,41 +5,12 @@ { "name": "hostname", "type": "string", - "default": "localhost", - "$ui": { - "component": "input", - "flex": 12, - "required": true, - "label": "$hostname_label", - "description": "$hostname_desc", - "rules": [ - { - "type": "pattern", - "pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$", - "message": "$hostname_validate" - } - ] - } + "default": "localhost" }, { "name": "port", "type": "int", - "default": 3306, - "$ui": { - "component": "input-number", - "flex": 12, - "required": true, - "label": "$port_label", - "description": "$port_desc", - "rules": [ - { - "type": "range", - "min": 1, - "max": 65535, - "message": "$port_range_validate" - } - ] - } + "default": 3306 }, { "name": "connectionOptions", @@ -68,27 +39,9 @@ { "optionName": "autoReconnect", "optionValue": "true", - "optionType": "string" + "optionType": "boolean" } - ], - "$ui": { - "component": "maps-editor", - "flex": 24, - "items": { - "optionName": { - "label": "$option_name_label", - "description": "$option_name_desc", - "type": "string" - }, - "optionValue": { - "label": "$option_value_label", - "description": "$option_value_desc", - "type": "string" - } - }, - "label": "$connection_options_label", - "description": "$connection_options_desc" - } + ] }, { "name": "auth", @@ -98,14 +51,7 @@ "fields": [ { "name": "username", - "type": "string", - "$ui": { - "component": "input", - "flex": 12, - "required": true, - "label": "$username_label", - "description": "$username_desc" - } + "type": "string" }, { "name": "password", @@ -113,26 +59,7 @@ "null", "string" ], - "default": null, - "$ui": { - "component": "input-password", - "flex": 12, - "label": "$password_label", - "description": "$password_desc", - "rules": [ - { - "type": "length", - "minLength": 8, - "maxLength": 128, - "message": "$password_length_validate" - }, - { - "type": "pattern", - "pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]*$", - "message": "$password_validate" - } - ] - } + "default": null } ] } diff --git a/rebar_template.config b/rebar_template.config index dcf68e1a..16bbd0f3 100644 --- a/rebar_template.config +++ b/rebar_template.config @@ -37,7 +37,7 @@ , {repo, "@@repo@@"} , {functionality, ["Demo"]} , {compatibility, - [ {emqx, "~> 5.0"} + [ {emqx, "~> 5.7"} ]} , {description, "@@description@@"} ]