diff options
author | PradeepKiruvale <PRADEEPKIRUVALE@gmail.com> | 2021-10-14 17:57:39 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-14 17:57:39 +0530 |
commit | 7020503aa9bfea97c07c58692e332e19884ecc1e (patch) | |
tree | 41d6d6e30427e863318e2624510ca38adbb35d4a /docs | |
parent | 1e530be1415a06de81385f3faec39e61b90c06b4 (diff) |
[CIT-619] update plugin list api (#494)
* [CIT-619] update list plugin apis
* [CIT-619] parse tab separated values
* use csv parser
* remove commented code
* remove debug statements
* revert the deleted files
* update document
* update specification
* update system tests
* address review comments
* remove unused module
* reword documents
* regular string instread of format!
Co-authored-by: Pradeep Kumar K J <pradeepkumar.kj@sofwareag.com>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/src/references/plugin-api.md | 13 | ||||
-rw-r--r-- | docs/src/tutorials/write-my-software-management-plugin.md | 36 |
2 files changed, 24 insertions, 25 deletions
diff --git a/docs/src/references/plugin-api.md b/docs/src/references/plugin-api.md index 07addba9..c007330f 100644 --- a/docs/src/references/plugin-api.md +++ b/docs/src/references/plugin-api.md @@ -60,23 +60,22 @@ On start-up and sighup, the sm-agent registers the plugins as follow: ### The `list` command -When called with the `list` command, a plugin returns the list of software modules that have been installed with this plugin. +When called with the `list` command, a plugin returns the list of software modules that have been installed with this plugin, +using tab separated values. ```shell $ debian-plugin list ... -{"name":"collectd-core","version":"5.8.1-1.3"} -{"name":"mosquitto","version":"1.5.7-1+deb10u1"} +collectd-core 5.8.1-1.3 +mosquitto 1.5.7-1+deb10u1 ... ``` Contract: * This command take no arguments. * If an error status is returned, the executable is removed from the list of plugins. -* The list is returned using the [jsonlines](https://jsonlines.org/) format. - * __`name`__: the name of the module. This name is the name that has been used to install it and that need to be used to remove it. - * __`version`__: the version currently installed. This is a string that can only been interpreted in the context of the plugin. - +* The list is returned using [CSV with tabulations as separators](https://en.wikipedia.org/wiki/Tab-separated_values). + Each line has two values separated by a tab: the name of the module then the version of that module. ### The `prepare` command The `prepare` command is invoked by the sm-agent before a sequence of install and remove commands diff --git a/docs/src/tutorials/write-my-software-management-plugin.md b/docs/src/tutorials/write-my-software-management-plugin.md index 176387bd..4d726d96 100644 --- a/docs/src/tutorials/write-my-software-management-plugin.md +++ b/docs/src/tutorials/write-my-software-management-plugin.md @@ -24,7 +24,7 @@ IMAGE_NAME="$2" case "$COMMAND" in list) - docker image list --format '{"name":"{{.Repository}}","version":"{{.Tag}}"}' || exit 2 + docker image list --format '{{.Repository}}\t{{.Tag}}' || exit 2 ;; install) docker pull $IMAGE_NAME || exit 2 @@ -48,23 +48,23 @@ exit 0 If you execute `./docker list`, you will see this kind of output. -```json -{"name":"alpine","version":"3.14"} -{"name":"eclipse-mosquitto","version":"2.0-openssl"} +```csv +alpine 3.14 +eclipse-mosquitto 2.0-openssl ... ``` The Software Management Agent runs executable plugins with a special argument, like `list`. Let's call the pre-defined argument such as `list`, `install`, and `remove` a **command** here. As you can see from this example, a plugin should be an executable file -that accepts the commands and outputs to stdout and stderr in the defined JSON Lines format. +that accepts the commands and outputs to stdout and stderr. Hence, you can implement a plugin in your preferred language. Here is the table of the commands that you can use in a plugin. |Command|Input arguments|Expected output|Description| |---|---|---|---| -|list| - | JSON Lines |Returns the list of software modules that have been installed with this plugin.| +|list| - | lines with tab separated values |Returns the list of software modules that have been installed with this plugin.| |prepare| - | - |Executes the provided actions before a sequence of install and remove commands.| |finalize| - | - |Executes the provided actions after a sequence of install and remove commands.| |install| NAME [--version VERSION] [--file FILE] | - |Executes the action of installation.| @@ -107,7 +107,8 @@ The `list` command is responsible to return the list of the installed software m Rules: - This command takes no arguments. -- The output must be in [the JSON Lines format](https://jsonlines.org/) including: +- The list is returned using [CSV with tabulations as separators](https://en.wikipedia.org/wiki/Tab-separated_values), + including: - **name**: the name of the software module, e.g. `mosquitto`. This name is the name that has been used to install it and that needs to be used to remove it. - **version**: the version currently installed. @@ -123,25 +124,24 @@ to report the list of software modules installed. > **Important**: the Software Management Agent executes a plugin using `sudo` and as `tedge-agent` user. -`docker` should output in the JSON lines format like +`docker` should output in the CSV with tabulations as separators like -```json -{"name":"alpine","version":"3.14"} -{"name":"eclipse-mosquitto","version":"2.0-openssl"} -{"name":"rust","version":"1.51-alpine"} +```csv +alpine 3.14 +eclipse-mosquitto 2.0-openssl +rust 1.51-alpine ``` with exit code `0` (successful). In most cases, the output of the `list` command is multi-lines. The line separator should be `\n`. -This requirement comes from the JSON Lines specifications. -A plugin must return this JSON structure per software module. -In the _docker_ file example, the following command outputs such JSON structures. +A plugin must return a CSV line per software module, using a tabulation `\t` as separator. +In the _docker_ file example, the following command outputs CSV structures with tabulations as separator. ```shell -docker image list --format '{"name":"{{.Repository}}","version":"{{.Tag}}"}' +docker image list --format '{{.Repository}}\t{{.Tag}}' ``` ## Prepare @@ -225,7 +225,7 @@ IMAGE_TAG="$4" case "$COMMAND" in list) - docker image list --format '{"name":"{{.Repository}}","version":"{{.Tag}}"}' || exit 2 + docker image list --format '{{.Repository}}\t{{.Tag}}' || exit 2 ;; install) if [ $# -eq 2 ]; then @@ -400,7 +400,7 @@ read_module() { case "$COMMAND" in list) - docker image list --format '{"name":"{{.Repository}}","version":"{{.Tag}}"}' || exit 2 + docker image list --format '{{.Repository}}\t{{.Tag}}' || exit 2 ;; install) # We use update-list instead |