]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add client resnames endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 21 Apr 2023 14:05:49 +0000 (16:05 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 1 May 2023 11:18:25 +0000 (13:18 +0200)
gui/baculum/protected/API/Pages/API/ClientResNames.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

diff --git a/gui/baculum/protected/API/Pages/API/ClientResNames.php b/gui/baculum/protected/API/Pages/API/ClientResNames.php
new file mode 100644 (file)
index 0000000..638e571
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\BconsoleError;
+
+/**
+ * Client resource names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @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;
+               }
+       }
+}
index 2f12e9a181644bac0cba02737ffa736a73253c82..d7648631f82317d3e9453852f1d6ad02579d10e6 100644 (file)
@@ -20,6 +20,7 @@
        <!-- clients (file daemons) endpoints -->
        <url ServiceParameter="Clients" pattern="api/v2/clients/" />
        <url ServiceParameter="Client" pattern="api/v2/clients/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="ClientResNames" pattern="api/v2/clients/resnames/" />
        <url ServiceParameter="ClientsShow" pattern="api/v2/clients/show/" />
        <url ServiceParameter="ClientShow" pattern="api/v2/clients/{id}/show/" parameters.id="\d+" />
        <url ServiceParameter="ClientStatus" pattern="api/v2/clients/{id}/status/" parameters.id="\d+" />
index 904a8a6d51f08e41d1195820d275b9df18c53477..f5b782df09f7d80cd473c56e8483f5de050585b6 100644 (file)
                                ]
                        }
                },
+               "/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"],