Skip to content
Snippets Groups Projects
Commit 35fc3d01 authored by Michael Hinton's avatar Michael Hinton Committed by Alejandro Sanchez
Browse files

dbv0.0.38 - add with_deleted input parameter to GET /user[s]

Bug 13063
parent e0a95ad9
No related branches found
No related tags found
No related merge requests found
......@@ -230,6 +230,7 @@ documents those changes that are of interest to users and administrators.
-- CVE-2022-29501 - Prevent abuse of REQUEST_FORWARD_DATA.
-- CVE-2022-29502 - Correctly validate io keys.
-- openapi/dbv0.0.38 - set with_deleted to false by default for /user[s].
-- openapi/dbv0.0.38 - add with_deleted input parameter to GET /user[s].
 
* Changes in Slurm 21.08.9
==========================
......
......@@ -341,6 +341,19 @@
</tr>
</table>
<h4>Add with_deleted input parameter to GET /user, /users</h4>
<table class="tchange">
<tr class="trchange">
<td class="tdfield">New parameter</td>
<td class="tdchange" colspan=2>
<ul>
<li>.paths."/user/{user_name}".get.parameters[] | select(.name=="with_deleted")</li>
<li>.paths."/users/".get.parameters[] | select(.name=="with_deleted")</li>
</ul>
</td>
</tr>
</table>
<h3>openapi/dbv0.0.36 (src/plugins/openapi/dbv0.0.36/openapi.json)</h3>
<h4>Deprecation notice</h4>
......
......@@ -798,6 +798,17 @@
"schema": {
"type": "string"
}
},
{
"name": "with_deleted",
"in": "query",
"description": "Include deleted users. False by default.",
"required": false,
"style": "form",
"explode": false,
"schema": {
"type": "boolean"
}
}
]
}
......@@ -895,7 +906,20 @@
}
}
}
}
},
"parameters": [
{
"name": "with_deleted",
"in": "query",
"description": "Include deleted users. False by default.",
"required": false,
"style": "form",
"explode": false,
"schema": {
"type": "boolean"
}
}
]
}
},
"/cluster/{cluster_name}": {
......
......@@ -65,6 +65,11 @@ typedef struct {
List qos_list;
} foreach_user_t;
typedef struct {
data_t *errors;
slurmdb_user_cond_t *user_cond;
} foreach_query_search_t;
static int _foreach_user(void *x, void *arg)
{
slurmdb_user_rec_t *user = x;
......@@ -84,7 +89,35 @@ static int _foreach_user(void *x, void *arg)
return 0;
}
static int _dump_users(data_t *resp, data_t *errors, void *auth, char *user_name)
static data_for_each_cmd_t _foreach_query_search(const char *key,
data_t *data,
void *arg)
{
foreach_query_search_t *args = arg;
data_t *errors = args->errors;
if (!xstrcasecmp("with_deleted", key)) {
if (data_convert_type(data, DATA_TYPE_BOOL) != DATA_TYPE_BOOL) {
resp_error(errors, ESLURM_REST_INVALID_QUERY,
"must be a Boolean", NULL);
return DATA_FOR_EACH_FAIL;
}
if (data->data.bool_u)
args->user_cond->with_deleted = true;
else
args->user_cond->with_deleted = false;
return DATA_FOR_EACH_CONT;
}
resp_error(errors, ESLURM_REST_INVALID_QUERY, "Unknown query field",
NULL);
return DATA_FOR_EACH_FAIL;
}
static int _dump_users(data_t *resp, data_t *errors, void *auth, char *user_name,
slurmdb_user_cond_t *user_cond)
{
int rc = SLURM_SUCCESS;
List user_list = NULL;
......@@ -99,13 +132,12 @@ static int _dump_users(data_t *resp, data_t *errors, void *auth, char *user_name
.users = data_set_list(data_key_set(resp, "users")),
};
slurmdb_assoc_cond_t assoc_cond = { 0 };
slurmdb_user_cond_t user_cond = {
.assoc_cond = &assoc_cond,
.with_assocs = true,
.with_coords = true,
/* with_deleted defaults to false */
.with_wckeys = true,
};
user_cond->assoc_cond = &assoc_cond;
user_cond->with_assocs = true;
user_cond->with_coords = true;
/* with_deleted defaults to false */
user_cond->with_wckeys = true;
if (user_name) {
assoc_cond.user_list = list_create(NULL);
......@@ -113,7 +145,7 @@ static int _dump_users(data_t *resp, data_t *errors, void *auth, char *user_name
}
if (!(rc = db_query_list(errors, auth, &user_list, slurmdb_users_get,
&user_cond)) &&
user_cond)) &&
!(rc = db_query_list(errors, auth, &args.tres_list,
slurmdb_tres_get, &tres_cond)) &&
!(rc = db_query_list(errors, auth, &args.qos_list, slurmdb_qos_get,
......@@ -368,8 +400,20 @@ extern int op_handler_users(const char *context_id,
{
data_t *errors = populate_response_format(resp);
slurmdb_user_cond_t user_cond = {0};
if (query && data_get_dict_length(query)) {
/* Default to no deleted users */
foreach_query_search_t args = {
.errors = errors,
.user_cond = &user_cond,
};
if (data_dict_for_each(query, _foreach_query_search, &args) < 0)
return ESLURM_REST_INVALID_QUERY;
}
if (method == HTTP_REQUEST_GET)
return _dump_users(resp, errors, auth, NULL);
return _dump_users(resp, errors, auth, NULL, &user_cond);
else if (method == HTTP_REQUEST_POST)
return _update_users(query, resp, auth, (tag != CONFIG_OP_TAG));
else
......@@ -384,10 +428,22 @@ static int op_handler_user(const char *context_id, http_request_method_t method,
data_t *errors = populate_response_format(resp);
char *user_name = get_str_param("user_name", errors, parameters);
slurmdb_user_cond_t user_cond = {0};
if (query && data_get_dict_length(query)) {
/* Default to no deleted users */
foreach_query_search_t args = {
.errors = errors,
.user_cond = &user_cond,
};
if (data_dict_for_each(query, _foreach_query_search, &args) < 0)
return ESLURM_REST_INVALID_QUERY;
}
if (!user_name)
rc = ESLURM_REST_INVALID_QUERY;
else if (method == HTTP_REQUEST_GET)
rc = _dump_users(resp, errors, auth, user_name);
rc = _dump_users(resp, errors, auth, user_name, &user_cond);
else if (method == HTTP_REQUEST_DELETE)
rc = _delete_user(resp, auth, user_name, errors);
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment