diff mbox series

[v2] Extend Suricatta CMD_CONFIG with ability to insert and modify device attributes

Message ID 20210406161445.337381-1-sava.jakovljev@teufel.de
State Accepted
Headers show
Series [v2] Extend Suricatta CMD_CONFIG with ability to insert and modify device attributes | expand

Commit Message

Sava Jakovljev April 6, 2021, 4:14 p.m. UTC
* Introduce additional configuration option for Hawkbit Suricatta
  implementation, which allows users to modify or insert new device
  attributes at run-time using command IPC.
* Document new feature.

Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de>
---
 doc/source/swupdate-ipc.rst | 22 +++++++++++++++++++++-
 suricatta/server_hawkbit.c  | 21 +++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

--
2.26.3

Comments

Stefano Babic April 6, 2021, 4:40 p.m. UTC | #1
Hi Sava,

On 06.04.21 18:14, Sava Jakovljev wrote:
> * Introduce additional configuration option for Hawkbit Suricatta
>    implementation, which allows users to modify or insert new device
>    attributes at run-time using command IPC.
> * Document new feature.
> 
> Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de>
> ---
>   doc/source/swupdate-ipc.rst | 22 +++++++++++++++++++++-
>   suricatta/server_hawkbit.c  | 21 +++++++++++++++++++++
>   2 files changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/source/swupdate-ipc.rst b/doc/source/swupdate-ipc.rst
> index f506215..9953b1e 100644
> --- a/doc/source/swupdate-ipc.rst
> +++ b/doc/source/swupdate-ipc.rst
> @@ -192,6 +192,26 @@ Enable / disable Suricatta daemon
>           { "enable" : true }
>           { "enable" : false }
> 
> +Set custom device attributes for Suricatta (for Hawkbit implementation)
> +.......................................................................
> +
> +::
> +
> +        { "identify" : [
> +            {
> +                "name"  : "customizableAttributeOne",
> +                "value" : "valueOne"
> +            },
> +            {
> +                "name"  : "customizableAttributeTwo",
> +                "value" : "valueTwo"
> +            }
> +        ]}
> +
> +New attributes can be added at runtime, and existing attributes can be modified in the same
> +way. Changes will be reflected on the server in the next poll iteration.
> +
> +
>   Trigger a check on the server
>   .............................
> 
> @@ -393,5 +413,5 @@ Example:
>   		"name": "rootfs.ext4.gz",
>   		"percent": "18"
>   	}
> -
> +
> 
> diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
> index b1372a8..aafcd4c 100644
> --- a/suricatta/server_hawkbit.c
> +++ b/suricatta/server_hawkbit.c
> @@ -1961,6 +1961,19 @@ cleanup:
>   	return result;
>   }
> 
> +static void server_set_additional_device_attributes_ipc(json_object* json_data)
> +{
> +	for (int i = 0; i < json_object_array_length(json_data); ++i) {
> +		json_object* attr_obj = json_object_array_get_idx(json_data, i);
> +		json_object* attr_key_data = json_get_path_key(attr_obj, (const char *[]){"name", NULL});
> +		json_object* attr_value_data = json_get_path_key(attr_obj, (const char *[]){"value", NULL});
> +
> +		const char* key = json_object_get_string(attr_key_data);
> +		const char* value = json_object_get_string(attr_value_data);
> +		dict_set_value(&server_hawkbit.configdata, key, value);
> +	}
> +}
> +
>   static server_op_res_t server_configuration_ipc(ipc_message *msg)
>   {
>   	struct json_object *json_root;
> @@ -1983,6 +1996,14 @@ static server_op_res_t server_configuration_ipc(ipc_message *msg)
>   			server_hawkbit.polling_interval_from_server = true;
>   	}
> 
> +	json_data = json_get_path_key(
> +		json_root, (const char*[]){"identify", NULL});
> +
> +	if (json_data) {
> +		server_set_additional_device_attributes_ipc(json_data);
> +		server_hawkbit.has_to_send_configData = true;
> +	}
> +
>   	return SERVER_OK;
>   }
> 
> --
> 2.26.3
> 

It looks great to me.

Reviewed-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/doc/source/swupdate-ipc.rst b/doc/source/swupdate-ipc.rst
index f506215..9953b1e 100644
--- a/doc/source/swupdate-ipc.rst
+++ b/doc/source/swupdate-ipc.rst
@@ -192,6 +192,26 @@  Enable / disable Suricatta daemon
         { "enable" : true }
         { "enable" : false }

+Set custom device attributes for Suricatta (for Hawkbit implementation)
+.......................................................................
+
+::
+
+        { "identify" : [
+            {
+                "name"  : "customizableAttributeOne",
+                "value" : "valueOne"
+            },
+            {
+                "name"  : "customizableAttributeTwo",
+                "value" : "valueTwo"
+            }
+        ]}
+
+New attributes can be added at runtime, and existing attributes can be modified in the same
+way. Changes will be reflected on the server in the next poll iteration.
+
+
 Trigger a check on the server
 .............................

@@ -393,5 +413,5 @@  Example:
 		"name": "rootfs.ext4.gz",
 		"percent": "18"
 	}
-
+

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index b1372a8..aafcd4c 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -1961,6 +1961,19 @@  cleanup:
 	return result;
 }

+static void server_set_additional_device_attributes_ipc(json_object* json_data)
+{
+	for (int i = 0; i < json_object_array_length(json_data); ++i) {
+		json_object* attr_obj = json_object_array_get_idx(json_data, i);
+		json_object* attr_key_data = json_get_path_key(attr_obj, (const char *[]){"name", NULL});
+		json_object* attr_value_data = json_get_path_key(attr_obj, (const char *[]){"value", NULL});
+
+		const char* key = json_object_get_string(attr_key_data);
+		const char* value = json_object_get_string(attr_value_data);
+		dict_set_value(&server_hawkbit.configdata, key, value);
+	}
+}
+
 static server_op_res_t server_configuration_ipc(ipc_message *msg)
 {
 	struct json_object *json_root;
@@ -1983,6 +1996,14 @@  static server_op_res_t server_configuration_ipc(ipc_message *msg)
 			server_hawkbit.polling_interval_from_server = true;
 	}

+	json_data = json_get_path_key(
+		json_root, (const char*[]){"identify", NULL});
+
+	if (json_data) {
+		server_set_additional_device_attributes_ipc(json_data);
+		server_hawkbit.has_to_send_configData = true;
+	}
+
 	return SERVER_OK;
 }