]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add type parameter to clients endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 9 Nov 2023 10:11:30 +0000 (11:11 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 9 Nov 2023 10:13:51 +0000 (11:13 +0100)
gui/baculum/protected/API/Modules/ClientManager.php
gui/baculum/protected/API/Pages/API/Clients.php
gui/baculum/protected/API/openapi_baculum.json

index bd5554527c7e194e34a2809026db51c9f8660ce2..be5e2d7eabe9e8a988c48b0908dc7ab6c049684f 100644 (file)
@@ -33,6 +33,13 @@ use Prado\Data\ActiveRecord\TActiveRecordCriteria;
  */
 class ClientManager extends APIModule {
 
+
+       /**
+        * Client types
+        */
+       const CLIENT_TYPE_REACHABLE = 'reachable';
+       const CLIENT_TYPE_UNREACHABLE = 'unreachable';
+
        /**
         * Result modes.
         */
index eaffe5734d9d5dd389c63a02cea2196f9c9867e2..829ff0863a55b54b4e90d15ca7d0a100b12f5e5e 100644 (file)
@@ -42,6 +42,7 @@ class Clients extends BaculumAPIServer {
                $plugin = $this->Request->contains('plugin') && $misc->isValidAlphaNumeric($this->Request['plugin']) ? $this->Request['plugin'] : '';
                $os = $this->Request->contains('os') && $misc->isValidNameExt($this->Request['os']) ? $this->Request['os'] : '';
                $version = $this->Request->contains('version') && $misc->isValidColumn($this->Request['version']) ? $this->Request['version'] : '';
+               $type = $this->Request->contains('type') && $misc->isValidName($this->Request['type']) ? $this->Request['type'] : null;
                $mode = $this->Request->contains('overview') && $misc->isValidBooleanTrue($this->Request['overview']) ? ClientManager::CLIENT_RESULT_MODE_OVERVIEW : ClientManager::CLIENT_RESULT_MODE_NORMAL;
                $order_by = $this->Request->contains('order_by') && $misc->isValidColumn($this->Request['order_by']) ? $this->Request['order_by']: null;
                $order_direction = $this->Request->contains('order_direction') && $misc->isValidOrderDirection($this->Request['order_direction']) ? $this->Request['order_direction']: null;
@@ -144,8 +145,8 @@ class Clients extends BaculumAPIServer {
                                        'vals' => ''
                                ];
                                $clients_reached = $this->getModule('client')->getClients(
-                                       $limit,
-                                       $offset,
+                                       (is_null($type) || $type === ClientManager::CLIENT_TYPE_REACHABLE ? $limit : 0),
+                                       (is_null($type) || $type === ClientManager::CLIENT_TYPE_REACHABLE ? $offset : 0),
                                        $sort,
                                        $params,
                                        $jobs,
@@ -159,8 +160,8 @@ class Clients extends BaculumAPIServer {
                                        'vals' => ''
                                ];
                                $clients_unreached = $this->getModule('client')->getClients(
-                                       $limit,
-                                       $offset,
+                                       (is_null($type) || $type === ClientManager::CLIENT_TYPE_UNREACHABLE ? $limit : 0),
+                                       (is_null($type) || $type === ClientManager::CLIENT_TYPE_UNREACHABLE ? $offset : 0),
                                        $sort,
                                        $params,
                                        $jobs,
index 9cf84a0980be459057013a46ce32320ac024d865..4a28b6c52c8be61c3fca32c37af4fa49e637c2f8 100644 (file)
                                        {
                                                "$ref": "#/components/parameters/Offset"
                                        },
+                                       {
+                                               "name": "type",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "Client type (reachable/unreachable). It determines for wich type will be applied offset and limit. This option has meaning only for overview mode (overview=1). For other modes it is ignored. Please note, providing one type does not cause that other types will not be listed, but only offset and limit criteria will be applied for selected type.",
+                                               "schema": {
+                                                       "type": "string",
+                                                       "enum": ["reachable", "unreachable"]
+                                               }
+                                       },
                                        {
                                                "name": "name",
                                                "in": "query",