From: Marcin Haba Date: Wed, 13 Sep 2023 07:25:19 +0000 (+0200) Subject: baculum: Add client name parameter to clients endpoint X-Git-Tag: Beta-15.0.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c96367ce3150cd89ca04a64e40c8ded9de69975f;p=thirdparty%2Fbacula.git baculum: Add client name parameter to clients endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/Clients.php b/gui/baculum/protected/API/Pages/API/Clients.php index 69bc1f5f3..98e5136bf 100644 --- a/gui/baculum/protected/API/Pages/API/Clients.php +++ b/gui/baculum/protected/API/Pages/API/Clients.php @@ -34,12 +34,40 @@ class Clients extends BaculumAPIServer { public function get() { $misc = $this->getModule('misc'); + $client = $this->Request->contains('name') && $misc->isValidName($this->Request['name']) ? $this->Request['name'] : ''; $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; $plugin = $this->Request->contains('plugin') && $misc->isValidAlphaNumeric($this->Request['plugin']) ? $this->Request['plugin'] : ''; $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client')); if ($result->exitcode === 0) { $params = []; + + $clients = []; + if (!empty($client)) { + if (in_array($client, $result->output)) { + $clients = [$client]; + } else { + // no client name provided but not found in the configuration + $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS; + return; + } + } else { + $clients = $result->output; + } + if (count($clients) == 0) { + // no $clients criteria means that user has no client resource assigned. + $this->output = []; + $this->error = ClientError::ERROR_NO_ERRORS; + return; + } + + $params['Client.Name'] = []; + $params['Client.Name'][] = [ + 'operator' => 'IN', + 'vals' => $clients + ]; + if (!empty($plugin)) { $params['Plugins'] = []; $params['Plugins'][] = [ diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 064a5b44b..baa61b546 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -456,7 +456,7 @@ "error": { "type": "integer", "description": "Error code", - "enum": [0, 1, 2, 3, 4, 5, 6, 7, 11, 1000] + "enum": [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 1000] } } } @@ -471,6 +471,16 @@ { "$ref": "#/components/parameters/Offset" }, + { + "name": "name", + "in": "query", + "required": false, + "description": "Client name", + "schema": { + "type": "string", + "pattern": "[a-zA-Z0-9:.-_ ]+" + } + }, { "name": "plugin", "in": "query",