]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add volume names endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Jun 2023 13:49:51 +0000 (15:49 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Jun 2023 13:50:42 +0000 (15:50 +0200)
gui/baculum/protected/API/Modules/VolumeManager.php
gui/baculum/protected/API/Pages/API/VolumeNames.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 0eb22e79072d1eb5bc9956d5552fbe4932a3ece3..bc4c29abf7ca28c0d8a663faa3c90b289f4a2280 100644 (file)
@@ -457,11 +457,34 @@ LEFT JOIN Storage USING (StorageId)
         */
        public function getVolumesKeys($criteria = array(), $limit_val = 0) {
                $volumes = [];
-               $vols = $this->getVolumes($criteria, $limit_val);
+               $vols = $this->getVolumes($criteria, [], $limit_val);
                for ($i = 0; $i < count($vols); $i++) {
                        $volumes[$vols[$i]->volumename] = $vols[$i];
                }
                return $volumes;
        }
+
+       /**
+        * Get volumes names.
+        *
+        * @param integer $limit_val limit results value
+        * @return array volume name list
+        */
+       public function getVolumeNames($limit_val = null) {
+               $limit = '';
+               if(is_int($limit_val) && $limit_val > 0) {
+                       $limit = sprintf(
+                               ' LIMIT %d',
+                               $limit_val
+                       );
+               }
+               $sql = 'SELECT VolumeName as volumename
+                       FROM Media
+                       ORDER BY VolumeName ' . $limit;
+               $statement = Database::runQuery($sql);
+               $result = $statement->fetchAll(\PDO::FETCH_GROUP);
+               $volumes = array_keys($result);
+               return $volumes;
+       }
 }
 ?>
diff --git a/gui/baculum/protected/API/Pages/API/VolumeNames.php b/gui/baculum/protected/API/Pages/API/VolumeNames.php
new file mode 100644 (file)
index 0000000..b2355d7
--- /dev/null
@@ -0,0 +1,42 @@
+<?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\VolumeError;
+
+/**
+ * Volume names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class VolumeNames extends BaculumAPIServer {
+
+       public function get() {
+               $misc = $this->getModule('misc');
+               $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
+               $volumes = $this->getModule('volume')->getVolumeNames($limit);
+               $this->output = $volumes;
+               $this->error = VolumeError::ERROR_NO_ERRORS;
+       }
+}
index 8ff16209d8fddddb847cbd0687d14b898bd86544..a1dabdde054535dc5316a176a51c1d831a355c9a 100644 (file)
@@ -61,6 +61,7 @@
        <url ServiceParameter="VolumeLabelBarcodes" pattern="api/v2/volumes/label/barcodes/" />
        <url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/" />
        <url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/{barcodes}/" parameters.barcodes="barcodes" />
+       <url ServiceParameter="VolumeNames" pattern="api/v2/volumes/names/" />
        <!-- pools endpoints -->
        <url ServiceParameter="Pools" pattern="api/v2/pools/" />
        <url ServiceParameter="Pool" pattern="api/v2/pools/{id}/" parameters.id="\d+" />
index 8632fa77583784e7e9000d7bb6321b413c549356..e1bf1f41a69a6e87e732b1e097526e301ad1e43c 100644 (file)
                                ]
                        }
                },
+               "/api/v2/volumes/names": {
+                       "get": {
+                               "tags": ["volumes"],
+                               "summary": "Volume names",
+                               "description": "Get volume names.",
+                               "responses": {
+                                       "200": {
+                                               "description": "Volume names.",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Volume name"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 6, 7, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/Limit"
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/filesets": {
                        "get": {
                                "tags": ["filesets"],