diff mbox series

[v2,1/2] hawkbit: allow passing target token as command line parameter

Message ID 20180905102019.4912-1-diego.rondini@kynetics.com
State Accepted
Headers show
Series [v2,1/2] hawkbit: allow passing target token as command line parameter | expand

Commit Message

Diego Rondini Sept. 5, 2018, 10:20 a.m. UTC
From: Marta Todeschini <marta.todeschini@kynetics.com>

Allow passing target token as a command line parameter with the '-k' or
'--targettoken' options. Additionaly rename 'token' option to 'targettoken' to
allow implementation of gateway token support.

Signed-off-by: Marta Todeschini <marta.todeschini@kynetics.com>
Signed-off-by: Diego Rondini <diego.rondini@kynetics.com>
---
 examples/configuration/swupdate.cfg |  6 +++---
 suricatta/server_hawkbit.c          | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
index 8ce943d..e8f7dd0 100644
--- a/examples/configuration/swupdate.cfg
+++ b/examples/configuration/swupdate.cfg
@@ -105,8 +105,8 @@  identify : (
 #			  path of the file containing the key for ssl connection
 # sslcert		: string
 #			  path of the file containing the certificate for SSL connection
-# token			: string
-#			  Hawkbit security token
+# targettoken	: string
+#			  hawkBit target security token
 # proxy			: string
 #			  in case the server is reached via a proxy
 # ciphers		: string in the format used by CURL to set the allowed ciphers suite
@@ -131,7 +131,7 @@  suricatta :
 	cafile		= "/etc/ssl/cafile";
 	sslkey		= "/etc/ssl/sslkey";
 	sslcert		= "/etc/ssl/sslcert";
-	token           = "3bc13b476cb3962a0c63a5c92beacfh7";
+	targettoken 	= "3bc13b476cb3962a0c63a5c92beacfh7";
 */
 };
 
diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 083c2ef..eabb9dd 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -61,6 +61,7 @@  static struct option long_options[] = {
     {"retry", required_argument, NULL, 'r'},
     {"retrywait", required_argument, NULL, 'w'},
     {"proxy", optional_argument, NULL, 'y'},
+    {"targettoken", required_argument, NULL, 'k'},
     {NULL, 0, NULL, 0}};
 
 static unsigned short mandatory_argument_count = 0;
@@ -1474,7 +1475,8 @@  void suricatta_print_help(void)
 	    "\t  -w, --retrywait     Time to wait prior to retry and "
 	    "resume a download (default: %ds).\n"
 	    "\t  -y, --proxy         Use proxy. Either give proxy URL, else "
-	    "{http,all}_proxy env is tried.\n",
+	    "{http,all}_proxy env is tried.\n"
+	    "\t  -k, --targettoken   Set target token.\n",
 	    DEFAULT_POLLING_INTERVAL, DEFAULT_RESUME_TRIES,
 	    DEFAULT_RESUME_DELAY);
 }
@@ -1524,7 +1526,7 @@  static int suricatta_settings(void *elem, void  __attribute__ ((__unused__)) *da
 	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "proxy", tmp);
 	if (strlen(tmp))
 		SETSTRING(channel_data_defaults.proxy, tmp);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "token", tmp);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "targettoken", tmp);
 	if (strlen(tmp)) {
 		char *token_header;
 		if (asprintf(&token_header, "Authorization: TargetToken %s", tmp))
@@ -1589,7 +1591,7 @@  server_op_res_t server_start(char *fname, int argc, char *argv[])
 
 	/* reset to optind=1 to parse suricatta's argument vector */
 	optind = 1;
-	while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:",
+	while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:",
 				     long_options, NULL)) != -1) {
 		switch (choice) {
 		case 't':
@@ -1600,6 +1602,13 @@  server_op_res_t server_start(char *fname, int argc, char *argv[])
 			SETSTRING(server_hawkbit.device_id, optarg);
 			mandatory_argument_count |= ID_BIT;
 			break;
+		case 'k':
+			{
+				char *token_header;
+				if (asprintf(&token_header, "Authorization: TargetToken %s", optarg))
+					SETSTRING(channel_data_defaults.header, token_header);
+				break;
+			}
 		case 'c':
 			/* When no persistent update state storage is available,
 			 * use command line switch to instruct what to report.