From: Marcin Haba Date: Fri, 21 Apr 2023 14:05:49 +0000 (+0200) Subject: baculum: Add client resnames endpoint X-Git-Tag: Release-13.0.3~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8e62e7f5ed04bbaff83c1b95c21b0bc5b1f1ecd;p=thirdparty%2Fbacula.git baculum: Add client resnames endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/ClientResNames.php b/gui/baculum/protected/API/Pages/API/ClientResNames.php new file mode 100644 index 000000000..638e571d9 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/ClientResNames.php @@ -0,0 +1,81 @@ + + * @category API + * @package Baculum API + */ +class ClientResNames extends BaculumAPIServer { + public function get() { + $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : 0; + $clients_cmd = ['.client']; + + $directors = $this->getModule('bconsole')->getDirectors(); + if ($directors->exitcode != 0) { + $this->output = $directors->output; + $this->error = $directors->exitcode; + return; + } + $clients = []; + $error = false; + $error_obj = null; + for ($i = 0; $i < count($directors->output); $i++) { + $client_list = $this->getModule('bconsole')->bconsoleCommand( + $directors->output[$i], + $clients_cmd, + null, + true + ); + if ($client_list->exitcode != 0) { + $error_obj = $client_list; + $error = true; + break; + } + $clients[$directors->output[$i]] = []; + for ($j = 0; $j < count($client_list->output); $j++) { + if (empty($client_list->output[$j])) { + continue; + } + $clients[$directors->output[$i]][] = $client_list->output[$j]; + + // limit per director, not for entire elements + if ($limit > 0 && count($clients[$directors->output[$i]]) === $limit) { + break; + } + } + } + if ($error === true) { + $emsg = ' Output => ' . implode(PHP_EOL, $error_obj->output) . 'ExitCode => ' . $error_obj->exitcode; + $this->output = BconsoleError::MSG_ERROR_WRONG_EXITCODE . $emsg; + $this->error = BconsoleError::ERROR_WRONG_EXITCODE; + } else { + $this->output = $clients; + $this->error = BconsoleError::ERROR_NO_ERRORS; + } + } +} diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 2f12e9a18..d7648631f 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -20,6 +20,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 904a8a6d5..f5b782df0 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -778,6 +778,44 @@ ] } }, + "/api/v2/clients/resnames": { + "get": { + "tags": ["clients"], + "summary": "Client resource names", + "description": "Get client resource names", + "responses": { + "200": { + "description": "List of client resource names", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "description": "List client resource names per director", + "type": "string" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 4, 5, 6, 7, 11, 1000] + } + } + } + } + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/Limit" + } + ] + } + }, "/api/v2/clients/show": { "get": { "tags": ["clients"],