From 8c37aa368894a3062dfbb165711dfa14253783fe Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Fri, 30 Aug 2024 12:59:31 +0200 Subject: rest: adapt cache/fetch to support repository with multiple IP adddress take repository_id as json attributo, then infer repository IP from client. --- src/rest.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index 1a243e4..f4b5918 100644 --- a/src/rest.c +++ b/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); } -- cgit v1.2.3-18-g5258