Commit c665a3b1 authored by Marcin Haba's avatar Marcin Haba
Browse files

baculum: Add offset parameter to messages endpoint

parent d653b80b
......@@ -35,12 +35,17 @@ class Messages extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$cmd = ['messages'];
$result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, null, true);
$output = $result->output;
if ($result->exitcode == 0) {
$output = $limit > 0 ? array_slice($output, -$limit) : $output;
if ($limit > 0 && $offset <= 0) {
$output = array_slice($output, -$limit);
} elseif ($limit > 0 && $offset > 0) {
$output = array_slice($output, -$offset, $limit);
}
}
$this->output = $output;
$this->error = $result->exitcode > 0 ? GenericError::ERROR_WRONG_EXITCODE : GenericError::ERROR_NO_ERRORS;
......
......@@ -5558,16 +5558,28 @@
}
}
},
"parameters": [{
"name": "limit",
"in": "query",
"description": "Set messages log Limit.",
"required": false,
"default": 0,
"schema": {
"type": "integer"
"parameters": [
{
"name": "limit",
"in": "query",
"description": "Set messages log Limit. It is applyed from the end, not from the beginning. Ex. for msg1, msg2, msg3, msg4 and limit=2 it displays msg3 and msg4.",
"required": false,
"default": 0,
"schema": {
"type": "integer"
}
},
{
"name": "offset",
"in": "query",
"description": "Messages' offset must be used together with limit. It is applyed from the end, not from the beginning. Ex. for msg1, msg2, msg3, msg4 and offset=3 limit=2 it displays msg2 and msg3.",
"required": false,
"default": 0,
"schema": {
"type": "integer"
}
}
}]
]
}
},
"/api/v2/directors/{director_name}/status": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment