Mercurial > sci
diff sciworkerd/main.c @ 52:95bc6b4ec753
sciworkerd: add API key support
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 17 Aug 2022 09:38:19 +0200 |
parents | 081e1c258e64 |
children | 319979427566 |
line wrap: on
line diff
--- a/sciworkerd/main.c Wed Aug 17 09:37:45 2022 +0200 +++ b/sciworkerd/main.c Wed Aug 17 09:38:19 2022 +0200 @@ -20,17 +20,21 @@ #include <stdlib.h> #include <unistd.h> +#include "apic.h" #include "sciworkerd.h" +#include "util.h" static void env(void) { const char *env; - if ((env = getenv("SCI_URL"))) - snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg); + if ((env = getenv("SCI_API_URL"))) + util_strlcpy(apiconf.baseurl, env, sizeof (apiconf.baseurl)); + if ((env = getenv("SCI_API_KEY"))) + util_strlcpy(apiconf.key, env, sizeof (apiconf.key)); if ((env = getenv("SCI_WORKER"))) - snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg); + util_strlcpy(sciworkerd.name, env, sizeof (sciworkerd.name)); } int @@ -41,21 +45,24 @@ env(); opterr = 0; - while ((ch = getopt(argc, argv, "j:t:u:w:")) != -1) { + while ((ch = getopt(argc, argv, "k:j:t:u:w:")) != -1) { switch (ch) { case 'j': if ((val = atoi(optarg)) > 0) sciworkerd.maxjobs = val; break; + case 'k': + util_strlcpy(apiconf.key, optarg, sizeof (apiconf.key)); + break; case 't': if ((val = atoi(optarg)) > 0) sciworkerd.timeout = val; break; case 'u': - snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg); + util_strlcpy(apiconf.baseurl, optarg, sizeof (apiconf.baseurl)); break; case 'w': - snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg); + util_strlcpy(sciworkerd.name, optarg, sizeof (sciworkerd.name)); break; default: break;