diff mbox series

hawkbit: add ability to set configdata via command line

Message ID 20240227182614.3251210-1-james.hilliard1@gmail.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series hawkbit: add ability to set configdata via command line | expand

Commit Message

James Hilliard Feb. 27, 2024, 6:26 p.m. UTC
Currently we can only set the configdata via the identify section in
the config file.

Lets allow these to be set via the command line as well similar to how
we allow setting custom http headers.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 suricatta/server_hawkbit.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Stefano Babic Feb. 29, 2024, 8:20 a.m. UTC | #1
Hi James,

On 27.02.24 19:26, James Hilliard wrote:
> Currently we can only set the configdata via the identify section in
> the config file.
>
> Lets allow these to be set via the command line as well similar to how
> we allow setting custom http headers.
>
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>   suricatta/server_hawkbit.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
>
> diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
> index 3e5f3bc..1633c5c 100644
> --- a/suricatta/server_hawkbit.c
> +++ b/suricatta/server_hawkbit.c
> @@ -57,6 +57,7 @@ static struct option long_options[] = {
>       {"server", required_argument, NULL, 'S'},
>   	{"connection-timeout", required_argument, NULL, 's'},
>   	{"custom-http-header", required_argument, NULL, 'a'},
> +	{"identify", required_argument, NULL, '3'},
>   	{"max-download-speed", required_argument, NULL, 'l'},
>       {NULL, 0, NULL, 0}};
>
> @@ -1692,6 +1693,7 @@ static void server_print_help(void)
>   	    "\t  -s, --connection-timeout Set the server connection timeout (default: 300s).\n"
>   	    "\t  -a, --custom-http-header <name> <value> Set custom HTTP header, "
>   	    "appended to every HTTP request being sent.\n"
> +	    "\t  --identify <name> <value> Set custom device attributes for Suricatta.\n"
>   	    "\t  -n, --max-download-speed <limit>  Set download speed limit.\n"
>   	    "\t                                    Example: -n 100k; -n 1M; -n 100; -n 1G\n",
>   	    CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES,
> @@ -1891,6 +1893,15 @@ static server_op_res_t server_start(const char *fname, int argc, char *argv[])
>   						argv[optind++]) < 0)
>   				return SERVER_EINIT;
>   			break;
> +		case '3':
> +			if (optind >= argc)
> +				return SERVER_EINIT;
> +
> +			if (dict_insert_value(&server_hawkbit.configdata,
> +						optarg,
> +						argv[optind++]) < 0)
> +				return SERVER_EINIT;
> +			break;
>   		case 'n':
>   			channel_data_defaults.max_download_speed =
>   				(unsigned int)ustrtoull(optarg, NULL, 10);


Applied to -master, thanks !

Best regards,
Stefano Babic
James Hilliard Feb. 29, 2024, 4:26 p.m. UTC | #2
By the way, I noticed that there's currently no way to pass arguments
with spaces to suricata, seems this splitargs function is missing the
ability to handle quotes.

https://github.com/sbabic/swupdate/blob/2023.12.1/core/util.c#L196-L212

On Thu, Feb 29, 2024 at 1:20 AM Stefano Babic
<stefano.babic@swupdate.org> wrote:
>
> Hi James,
>
> On 27.02.24 19:26, James Hilliard wrote:
> > Currently we can only set the configdata via the identify section in
> > the config file.
> >
> > Lets allow these to be set via the command line as well similar to how
> > we allow setting custom http headers.
> >
> > Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> > ---
> >   suricatta/server_hawkbit.c | 11 +++++++++++
> >   1 file changed, 11 insertions(+)
> >
> > diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
> > index 3e5f3bc..1633c5c 100644
> > --- a/suricatta/server_hawkbit.c
> > +++ b/suricatta/server_hawkbit.c
> > @@ -57,6 +57,7 @@ static struct option long_options[] = {
> >       {"server", required_argument, NULL, 'S'},
> >       {"connection-timeout", required_argument, NULL, 's'},
> >       {"custom-http-header", required_argument, NULL, 'a'},
> > +     {"identify", required_argument, NULL, '3'},
> >       {"max-download-speed", required_argument, NULL, 'l'},
> >       {NULL, 0, NULL, 0}};
> >
> > @@ -1692,6 +1693,7 @@ static void server_print_help(void)
> >           "\t  -s, --connection-timeout Set the server connection timeout (default: 300s).\n"
> >           "\t  -a, --custom-http-header <name> <value> Set custom HTTP header, "
> >           "appended to every HTTP request being sent.\n"
> > +         "\t  --identify <name> <value> Set custom device attributes for Suricatta.\n"
> >           "\t  -n, --max-download-speed <limit>  Set download speed limit.\n"
> >           "\t                                    Example: -n 100k; -n 1M; -n 100; -n 1G\n",
> >           CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES,
> > @@ -1891,6 +1893,15 @@ static server_op_res_t server_start(const char *fname, int argc, char *argv[])
> >                                               argv[optind++]) < 0)
> >                               return SERVER_EINIT;
> >                       break;
> > +             case '3':
> > +                     if (optind >= argc)
> > +                             return SERVER_EINIT;
> > +
> > +                     if (dict_insert_value(&server_hawkbit.configdata,
> > +                                             optarg,
> > +                                             argv[optind++]) < 0)
> > +                             return SERVER_EINIT;
> > +                     break;
> >               case 'n':
> >                       channel_data_defaults.max_download_speed =
> >                               (unsigned int)ustrtoull(optarg, NULL, 10);
>
>
> Applied to -master, thanks !
>
> Best regards,
> Stefano Babic
diff mbox series

Patch

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 3e5f3bc..1633c5c 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -57,6 +57,7 @@  static struct option long_options[] = {
     {"server", required_argument, NULL, 'S'},
 	{"connection-timeout", required_argument, NULL, 's'},
 	{"custom-http-header", required_argument, NULL, 'a'},
+	{"identify", required_argument, NULL, '3'},
 	{"max-download-speed", required_argument, NULL, 'l'},
     {NULL, 0, NULL, 0}};
 
@@ -1692,6 +1693,7 @@  static void server_print_help(void)
 	    "\t  -s, --connection-timeout Set the server connection timeout (default: 300s).\n"
 	    "\t  -a, --custom-http-header <name> <value> Set custom HTTP header, "
 	    "appended to every HTTP request being sent.\n"
+	    "\t  --identify <name> <value> Set custom device attributes for Suricatta.\n"
 	    "\t  -n, --max-download-speed <limit>  Set download speed limit.\n"
 	    "\t                                    Example: -n 100k; -n 1M; -n 100; -n 1G\n",
 	    CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES,
@@ -1891,6 +1893,15 @@  static server_op_res_t server_start(const char *fname, int argc, char *argv[])
 						argv[optind++]) < 0)
 				return SERVER_EINIT;
 			break;
+		case '3':
+			if (optind >= argc)
+				return SERVER_EINIT;
+
+			if (dict_insert_value(&server_hawkbit.configdata,
+						optarg,
+						argv[optind++]) < 0)
+				return SERVER_EINIT;
+			break;
 		case 'n':
 			channel_data_defaults.max_download_speed =
 				(unsigned int)ustrtoull(optarg, NULL, 10);