summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-20 11:27:56 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-10-20 13:44:44 +0200
commit2958d23db2e7938905ce351d2737aec6be9ac158 (patch)
treeb9a499ab185f166f0228b92dc76c205c20add0e5
parent25c1c16e99a2fbc19002b2ca06d0266f5276d3a8 (diff)
#942 Use client's IP as filter in GET /hardware
This patch uses client's IP instead of scope ID as a filter for the request. Request: GET /hardware { "client": ["192.168.56.11"] } Response: 200 OK { "hardware": [ { "description": "BIOS", "type": "Tipo de proceso de arranque" }, { "description": "QEMU Standard PC (i440FX + PIIX, 1996) v.pc-i440fx-5.1", "type": "Marca y modelo del equipo" }, { "description": "Intel Corp. Intel Core Processor (Haswell, no TSX, IBRS) 2GHz v.pc-i440fx-5.1", "type": "Microprocesadores" }, { "description": "QEMU 2049MiB (DIMM 0)", "type": "Memorias" }, { "description": "Red Hat, Inc. Virtio network device v.00", "type": "Tarjetas de Red" } ] }
-rw-r--r--src/rest.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/rest.c b/src/rest.c
index a9edd2f..6b35a8a 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1452,8 +1452,6 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
{
const char *key, *msglog, *hw_item, *hw_type;
json_t *value, *root, *array, *item;
- struct og_scope scope = {};
- uint64_t flags = 0;
struct og_dbi *dbi;
dbi_result result;
int err = 0;
@@ -1463,27 +1461,18 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
};
json_object_foreach(element, key, value) {
- if (!strcmp(key, "scope")) {
- err = og_json_parse_scope(value, &scope,
- OG_PARAM_SCOPE_ID |
- OG_PARAM_SCOPE_TYPE);
- flags |= OG_REST_PARAM_SCOPE;
- } else {
+ if (!strcmp(key, "client"))
+ err = og_json_parse_clients(value, params);
+ else
err = -1;
- }
if (err < 0)
return err;
}
- if (!og_flags_validate(flags, OG_REST_PARAM_SCOPE))
+ if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR))
return -1;
- if (strcmp(scope.type, "computer")) {
- syslog(LOG_ERR, "incorrect scope type\n");
- return -1;
- }
-
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
@@ -1501,8 +1490,8 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
" ON perfileshard_hardwares.idperfilhard = ordenadores.idperfilhard "
"INNER JOIN tipohardwares "
" ON hardwares.idtipohardware = tipohardwares.idtipohardware "
- "WHERE ordenadores.idordenador = %u",
- scope.id);
+ "WHERE ordenadores.ip = '%s'",
+ params->ips_array[0]);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",