annotate scictl/scictl.c @ 61:8be8188d61a5

scictl: resurrect project-update command
author David Demelier <markand@malikania.fr>
date Thu, 18 Aug 2022 10:42:42 +0200
parents 319979427566
children 67470b67e460
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
1 /*
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
2 * scictl.c -- main scictl(8) utility file
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
3 *
32
081e1c258e64 misc: update copyright years
David Demelier <markand@malikania.fr>
parents: 31
diff changeset
4 * Copyright (c) 2021-2022 David Demelier <markand@malikania.fr>
16
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
5 *
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
8 * copyright notice and this permission notice appear in all copies.
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
9 *
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
17 */
3051ef92173a misc: add license headers
David Demelier <markand@malikania.fr>
parents: 13
diff changeset
18
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
19 #include <errno.h>
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
20 #include <limits.h>
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
21 #include <stdint.h>
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 #include <stdio.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
23 #include <stdlib.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
24 #include <string.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
25 #include <unistd.h>
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
26
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
27 #include <utlist.h>
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
28
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
29 #include "apic.h"
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
30 #include "util.h"
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
31
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
32 static void
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
33 usage(void)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
34 {
52
95bc6b4ec753 sciworkerd: add API key support
David Demelier <markand@malikania.fr>
parents: 50
diff changeset
35 fprintf(stderr, "usage: scictl [-k key] [-u baseurl] command [args...]\n");
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
36 exit(1);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
37 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
38
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
39 static void
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 help(void)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
42 fprintf(stderr, "usage: scictl job-add project tag\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
43 fprintf(stderr, " scictl job-todo worker\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
44 fprintf(stderr, " scictl project-add name desc url script\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
45 fprintf(stderr, " scictl project-info name\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
46 fprintf(stderr, " scictl project-list\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
47 fprintf(stderr, " scictl project-update name key value\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
48 fprintf(stderr, " scictl worker-add name desc\n");
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
49 fprintf(stderr, " scictl worker-list\n");
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
50 exit(0);
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
52
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
53 long long
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
54 toint(const char *s)
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
55 {
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
56 long long v;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
57 const char *err;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
58
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
59 v = util_strtonum(s, 0, LLONG_MAX, &err);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
60
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
61 if (err)
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
62 util_die("abort: %s\n", err);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
63
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
64 return v;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
65 }
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
66
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
67 static char *
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
68 readfile(const char *path)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
69 {
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
70 FILE *fp, *str;
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
71 char buf[BUFSIZ], *console = NULL;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
72 size_t nr, consolesz = 0;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
73
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
74 if (strcmp(path, "-") == 0)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
75 fp = stdin;
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
76 else if (!(fp = fopen(path, "r")))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
77 util_die("abort: %s: %s\n", path, strerror(errno));
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
78
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
79 if (!(str = open_memstream(&console, &consolesz)))
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
80 util_die("abort: open_memstream: %s\n", strerror(errno));
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
81
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
82 while ((nr = fread(buf, 1, sizeof (buf), fp)) > 0)
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
83 fwrite(buf, 1, nr, str);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
84
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
85 if ((ferror(fp) && !feof(fp)) || (ferror(str) && !feof(str)))
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
86 util_die("abort: %s\n", strerror(errno));
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
87
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
88 fclose(str);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
89 fclose(fp);
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
90
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
91 return console;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
92 }
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
93
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
94 static inline intmax_t
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
95 get_int(json_t *obj, const char *key)
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
96 {
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
97 json_t *val;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
98
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
99 if ((val = json_object_get(obj, key)) && json_is_integer(val))
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
100 return json_integer_value(val);
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
101
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
102 return 0;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
103 }
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
104
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
105 static inline const char *
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
106 get_string(json_t *obj, const char *key)
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
107 {
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
108 json_t *val;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
109
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
110 if ((val = json_object_get(obj, key)) && json_is_string(val))
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
111 return json_string_value(val);
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
112
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
113 return "";
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
114 }
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
115
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
116 static void
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
117 cmd_job_add(int argc, char **argv)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
118 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
119 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
120 json_t *obj;
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
121
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
122 if (argc < 3)
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
123 usage();
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
124
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
125 obj = json_pack("{ss ss}",
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
126 "project_name", argv[1],
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
127 "tag", argv[2]
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
128 );
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
129
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
130 if (apic_job_add(&req, obj) < 0)
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
131 util_die("abort: %s\n", req.error);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
132
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
133 json_decref(obj);
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
134 }
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
135
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
136 static void
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
137 cmd_job_todo(int argc, char **argv)
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
138 {
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
139 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
140 json_t *array, *obj;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
141 size_t i;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
142
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
143 if (argc < 2)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
144 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
145
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
146 if ((array = apic_job_todo(&req, argv[1])))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
147 util_die("abort: %s\n", req.error);
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
148
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
149 json_array_foreach(array, i, obj) {
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
150 printf("%-16s%jd\n", "id:", get_int(obj, "id"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
151 printf("%-16s%s\n", "tag:", get_string(obj, "tag"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
152 printf("%-16s%s\n", "project:", get_string(obj, "project_name"));
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
153
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
154 if (i + 1 < json_array_size(array))
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
155 printf("\n");
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
156 }
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
157
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
158 json_decref(array);
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
159 }
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
160
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
161 static void
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
162 cmd_project_add(int argc, char **argv)
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
163 {
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
164 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
165 char *script;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
166 json_t *obj;
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
167
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
168 if (argc < 5)
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
169 usage();
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
170
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
171 script = readfile(argv[4]);
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
172 obj = json_pack("{ss ss ss ss}",
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
173 "name", argv[1],
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
174 "desc", argv[2],
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
175 "url", argv[3],
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
176 "script", script
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
177 );
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
178
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
179 if (apic_project_save(&req, obj) < 0)
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
180 util_die("abort: unable to create project: %s\n", req.error);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
181
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
182 json_decref(obj);
1
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
183 }
5afdb14df924 sci: add support for storing results
David Demelier <markand@malikania.fr>
parents: 0
diff changeset
184
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
185 static void
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
186 cmd_project_update(int argc, char **argv)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
187 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
188 struct apic req;
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
189 json_t *obj;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
190
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
191 if (argc < 4)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
192 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
193
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
194 if (!(obj = apic_project_find(&req, argv[1])))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
195 util_die("abort: unable to find project: %s\n", req.error);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
196
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
197 /* Those fields are treated from argument. */
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
198 if (strcmp(argv[2], "name") == 0 ||
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
199 strcmp(argv[2], "desc") == 0 ||
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
200 strcmp(argv[2], "url") == 0)
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
201 json_object_set_new(obj, argv[2], json_string(argv[3]));
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
202 /* The script, however, is read from the file. */
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
203 else if (strcmp(argv[2], "script") == 0)
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
204 json_object_set_new(obj, "script", json_string(readfile(argv[3])));
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
205
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
206 if (apic_project_save(&req, obj) < 0)
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
207 util_die("abort: unable to save project: %s\n", req.error);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
208
61
8be8188d61a5 scictl: resurrect project-update command
David Demelier <markand@malikania.fr>
parents: 53
diff changeset
209 json_decref(obj);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
210 }
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
211
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
212 static void
13
67348ec46425 man: add manual pages
David Demelier <markand@malikania.fr>
parents: 12
diff changeset
213 cmd_project_info(int argc, char **argv)
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
214 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
215 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
216 json_t *obj;
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
217
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
218 if (argc < 2)
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
219 usage();
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
220 if (!(obj = apic_project_find(&req, argv[1])))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
221 util_die("abort: unable to find project: %s\n", req.error);
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
222
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
223 printf("%-16s%s\n", "name:", get_string(obj, "name"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
224 printf("%-16s%s\n", "desc:", get_string(obj, "desc"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
225 printf("%-16s%s\n", "url:", get_string(obj, "url"));
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
226 printf("\n");
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
227 printf("%s", get_string(obj, "script"));
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
228
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
229 json_decref(obj);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
230 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
231
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
232 static void
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
233 cmd_project_list(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
234 {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
235 (void)argc;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
236 (void)argv;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
237
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
238 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
239 json_t *array, *obj;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
240 size_t i;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
241
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
242 if (!(array = apic_project_list(&req)))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
243 util_die("abort: unable to list projects: %s\n", req.error);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
244
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
245 json_array_foreach(array, i, obj) {
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
246 printf("%-16s%s\n", "name:", get_string(obj, "name"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
247 printf("%-16s%s\n", "desc:", get_string(obj, "desc"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
248 printf("%-16s%s\n", "url:", get_string(obj, "url"));
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
249
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
250 if (i + 1 < json_array_size(array))
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
251 printf("\n");
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
252 }
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
253
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
254 json_decref(array);
2
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
255 }
5fa3d2f479b2 sci: initial upload support
David Demelier <markand@malikania.fr>
parents: 1
diff changeset
256
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
257 static void
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
258 cmd_worker_add(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
259 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
260 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
261 json_t *obj;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
262
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
263 if (argc < 3)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
264 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
265
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
266 obj = json_pack("{ss ss}",
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
267 "name", argv[1],
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
268 "desc", argv[2]
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
269 );
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
270
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
271 if (apic_worker_save(&req, obj) < 0)
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
272 util_die("abort: unable to save worker: %s\n", req.error);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
273
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
274 json_decref(obj);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
275 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
276
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
277 static void
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
278 cmd_worker_list(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
279 {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
280 (void)argc;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
281 (void)argv;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
282
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
283 struct apic req;
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
284 json_t *array, *obj;
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
285 size_t i;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
286
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
287 if (!(array = apic_worker_list(&req)))
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
288 util_die("abort: unable to list worker: %s\n", req.error);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
289
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
290 json_array_foreach(array, i, obj) {
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
291 printf("%-16s%s\n", "name:", get_string(obj, "name"));
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
292 printf("%-16s%s\n", "desc:", get_string(obj, "desc"));
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
293
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
294 if (i + 1 < json_array_size(array))
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
295 printf("\n");
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
296 }
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
297
27
dae2de19ca5d misc: switch to JSON everywhere
David Demelier <markand@malikania.fr>
parents: 24
diff changeset
298 json_decref(array);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
299 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
300
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
301 static struct {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
302 const char *name;
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
303 void (*exec)(int, char **);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
304 } commands[] = {
3
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
305 { "job-add", cmd_job_add },
215c0c3b3609 misc: use JSON everywhere (scictl/sciwebd)
David Demelier <markand@malikania.fr>
parents: 2
diff changeset
306 { "job-todo", cmd_job_todo },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
307 { "project-add", cmd_project_add },
13
67348ec46425 man: add manual pages
David Demelier <markand@malikania.fr>
parents: 12
diff changeset
308 { "project-info", cmd_project_info },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
309 { "project-list", cmd_project_list },
9
3ef8128e244f sci: add project-update command
David Demelier <markand@malikania.fr>
parents: 4
diff changeset
310 { "project-update", cmd_project_update },
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
311 { "worker-add", cmd_worker_add },
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
312 { "worker-list", cmd_worker_list },
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
313 { NULL, NULL }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
314 };
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
315
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
316 int
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
317 main(int argc, char **argv)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
318 {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
319 int ch;
50
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
320 const char *env;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
321
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
322 opterr = 0;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
323 setenv("POSIXLY_CORRECT", "1", 1);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
324
50
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
325 /* Environment first, options after. */
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
326 if ((env = getenv("SCI_API_URL")))
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
327 util_strlcpy(apiconf.baseurl, env, sizeof (apiconf.baseurl));
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
328 if ((env = getenv("SCI_API_KEY")))
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
329 util_strlcpy(apiconf.key, env, sizeof (apiconf.key));
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
330
53
319979427566 misc: refactor using util_getopt
David Demelier <markand@malikania.fr>
parents: 52
diff changeset
331 while ((ch = util_getopt(argc, argv, "k:u:")) != -1) {
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
332 switch (ch) {
50
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
333 case 'k':
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
334 util_strlcpy(apiconf.key, optarg, sizeof (apiconf.key));
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
335 break;
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
336 case 'u':
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
337 util_strlcpy(apiconf.baseurl, optarg, sizeof (apiconf.baseurl));
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
338 break;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
339 default:
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
340 break;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
341 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
342 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
343
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
344 argc -= optind;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
345 argv += optind;
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
346
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
347 optind = 1;
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
348
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
349 if (argc < 1)
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
350 usage();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
351 if (strcmp(argv[0], "help") == 0)
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
352 help();
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
353
50
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
354 /* At this step, every command requires an API key. */
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
355 if (strlen(apiconf.key) == 0)
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
356 util_die("abort: no API key defined\n");
b474f0985e39 scictl: add API key support
David Demelier <markand@malikania.fr>
parents: 32
diff changeset
357
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
358 for (size_t i = 0; commands[i].name; ++i) {
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
359 if (strcmp(commands[i].name, argv[0]) == 0) {
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
360 commands[i].exec(argc, argv);
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
361 return 0;
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
362 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
363 }
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
364
22
dd078aea5d02 misc: use project/worker name as primary key
David Demelier <markand@malikania.fr>
parents: 19
diff changeset
365 util_die("abort: invalid command: %s\n", argv[0]);
0
f1de39079243 misc: initial import
David Demelier <markand@malikania.fr>
parents:
diff changeset
366 }