]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add client name parameter to clients endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 13 Sep 2023 07:25:19 +0000 (09:25 +0200)
committerEric Bollengier <eric@baculasystems.com>
Tue, 31 Oct 2023 15:00:30 +0000 (16:00 +0100)
gui/baculum/protected/API/Pages/API/Clients.php
gui/baculum/protected/API/openapi_baculum.json

index 69bc1f5f3610479b410065ca50652d7baf3eac61..98e5136bf56089a536d5ee660c2685c359982885 100644 (file)
@@ -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'][] = [
index 064a5b44b63cbcea7bd95c27b7c375d17b6170db..baa61b546628ef6c87081d1528521b46c108628b 100644 (file)
                                                                                "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]
                                                                                }
                                                                        }
                                                                }
                                        {
                                                "$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",