mirror of https://git.48k.eu/ogserver
rest: adapt cache/fetch to support repository with multiple IP adddress
take repository_id as json attributo, then infer repository IP from client.master
parent
d8af32cbcb
commit
8c37aa3688
37
src/rest.c
37
src/rest.c
|
@ -4377,7 +4377,10 @@ static int og_cmd_cache_delete(json_t *element, struct og_msg_params *params,
|
|||
static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params,
|
||||
char *buffer_reply)
|
||||
{
|
||||
json_t *value, *body, *image, *repository = NULL;
|
||||
char repository_ip[OG_DB_IP_MAXLEN + 1] = {};
|
||||
json_t *value, *body;
|
||||
struct og_dbi *dbi;
|
||||
|
||||
const char *key;
|
||||
int err = 0;
|
||||
|
||||
|
@ -4388,29 +4391,39 @@ static int og_cmd_cache_fetch(json_t *element, struct og_msg_params *params,
|
|||
if (!strcmp(key, "clients")) {
|
||||
err = og_json_parse_clients(value, params);
|
||||
} else if (!strcmp(key, "image")) {
|
||||
if (json_typeof(value) != JSON_STRING) {
|
||||
err = -1;
|
||||
}
|
||||
image = value;
|
||||
} else if (!strcmp(key, "repository")) {
|
||||
if (json_typeof(value) != JSON_STRING) {
|
||||
err = -1;
|
||||
}
|
||||
repository = value;
|
||||
err = og_json_parse_string(value, ¶ms->name);
|
||||
params->flags |= OG_REST_PARAM_NAME;
|
||||
} else if (!strcmp(key, "repository_id")) {
|
||||
err = og_json_parse_uint64(value, ¶ms->image.repo_id);
|
||||
params->flags |= OG_REST_PARAM_REPO;
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
|
||||
if (!og_msg_params_validate(params, OG_REST_PARAM_NAME |
|
||||
OG_REST_PARAM_ADDR |
|
||||
OG_REST_PARAM_REPO))
|
||||
return -1;
|
||||
|
||||
if (!image || !repository)
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR,
|
||||
"cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = og_dbi_get_repository_ip(dbi, params->image.repo_id,
|
||||
params->ips_array[0], repository_ip);
|
||||
og_dbi_close(dbi);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
body = json_copy(element);
|
||||
json_object_del(body, "clients");
|
||||
json_object_set_new(body, "repository", json_string(repository_ip));
|
||||
|
||||
return og_send_request(OG_METHOD_POST, OG_CMD_CACHE_FETCH, params, body);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue