Mercurial > sci
comparison 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 |
comparison
equal
deleted
inserted
replaced
51:054cc00e23d2 | 52:95bc6b4ec753 |
---|---|
18 | 18 |
19 #include <stdio.h> | 19 #include <stdio.h> |
20 #include <stdlib.h> | 20 #include <stdlib.h> |
21 #include <unistd.h> | 21 #include <unistd.h> |
22 | 22 |
23 #include "apic.h" | |
23 #include "sciworkerd.h" | 24 #include "sciworkerd.h" |
25 #include "util.h" | |
24 | 26 |
25 static void | 27 static void |
26 env(void) | 28 env(void) |
27 { | 29 { |
28 const char *env; | 30 const char *env; |
29 | 31 |
30 if ((env = getenv("SCI_URL"))) | 32 if ((env = getenv("SCI_API_URL"))) |
31 snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg); | 33 util_strlcpy(apiconf.baseurl, env, sizeof (apiconf.baseurl)); |
34 if ((env = getenv("SCI_API_KEY"))) | |
35 util_strlcpy(apiconf.key, env, sizeof (apiconf.key)); | |
32 if ((env = getenv("SCI_WORKER"))) | 36 if ((env = getenv("SCI_WORKER"))) |
33 snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg); | 37 util_strlcpy(sciworkerd.name, env, sizeof (sciworkerd.name)); |
34 } | 38 } |
35 | 39 |
36 int | 40 int |
37 main(int argc, char **argv) | 41 main(int argc, char **argv) |
38 { | 42 { |
39 int ch, val; | 43 int ch, val; |
40 | 44 |
41 env(); | 45 env(); |
42 opterr = 0; | 46 opterr = 0; |
43 | 47 |
44 while ((ch = getopt(argc, argv, "j:t:u:w:")) != -1) { | 48 while ((ch = getopt(argc, argv, "k:j:t:u:w:")) != -1) { |
45 switch (ch) { | 49 switch (ch) { |
46 case 'j': | 50 case 'j': |
47 if ((val = atoi(optarg)) > 0) | 51 if ((val = atoi(optarg)) > 0) |
48 sciworkerd.maxjobs = val; | 52 sciworkerd.maxjobs = val; |
53 break; | |
54 case 'k': | |
55 util_strlcpy(apiconf.key, optarg, sizeof (apiconf.key)); | |
49 break; | 56 break; |
50 case 't': | 57 case 't': |
51 if ((val = atoi(optarg)) > 0) | 58 if ((val = atoi(optarg)) > 0) |
52 sciworkerd.timeout = val; | 59 sciworkerd.timeout = val; |
53 break; | 60 break; |
54 case 'u': | 61 case 'u': |
55 snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg); | 62 util_strlcpy(apiconf.baseurl, optarg, sizeof (apiconf.baseurl)); |
56 break; | 63 break; |
57 case 'w': | 64 case 'w': |
58 snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg); | 65 util_strlcpy(sciworkerd.name, optarg, sizeof (sciworkerd.name)); |
59 break; | 66 break; |
60 default: | 67 default: |
61 break; | 68 break; |
62 } | 69 } |
63 } | 70 } |