]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add object names endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 31 May 2023 12:47:32 +0000 (14:47 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 1 Jun 2023 11:20:55 +0000 (13:20 +0200)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/ObjectNames.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 6c0e3f662bfab0d8d0d6daf5810d8165b319c946..c99a3fe7794d295944460671d2558ad8386d4e9f 100644 (file)
@@ -674,4 +674,28 @@ JOIN Job USING (JobId) '
                sort($values);
                return $values;
        }
+
+       /**
+        * Get existing object names.
+        *
+        * @param integer $limit_val maximum number of elements to return
+        * @return array object names
+        */
+       public function getObjectNames($limit_val = null) {
+               $limit = '';
+               if(is_int($limit_val) && $limit_val > 0) {
+                       $limit = sprintf(
+                               ' LIMIT %d',
+                               $limit_val
+                       );
+               }
+               $sql = 'SELECT DISTINCT ObjectName as objectname
+                       FROM Object
+                       ' . $limit;
+               $statement = Database::runQuery($sql);
+               $result = $statement->fetchAll(\PDO::FETCH_GROUP);
+               $values = array_keys($result);
+               sort($values);
+               return $values;
+       }
 }
diff --git a/gui/baculum/protected/API/Pages/API/ObjectNames.php b/gui/baculum/protected/API/Pages/API/ObjectNames.php
new file mode 100644 (file)
index 0000000..eb81e20
--- /dev/null
@@ -0,0 +1,41 @@
+<?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\ObjectError;
+
+/**
+ * Available object names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectNames extends BaculumAPIServer {
+
+       public function get() {
+               $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null;
+
+               $this->output = $this->getModule('object')->getObjectNames($limit);
+               $this->error = ObjectError::ERROR_NO_ERRORS;
+       }
+}
index 8c2679ca7d664dd0dd8ffef51c8687d688ab1bb3..8ff16209d8fddddb847cbd0687d14b898bd86544 100644 (file)
        <url ServiceParameter="ObjectsOverview" pattern="api/v2/objects/overview/" />
        <url ServiceParameter="ObjectVersions" pattern="api/v2/objects/versions/{uuid}" parameters.uuid="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="ObjectTypes" pattern="api/v2/objects/types/" />
+       <url ServiceParameter="ObjectNames" pattern="api/v2/objects/names/" />
        <url ServiceParameter="ObjectStatsCategorySum" pattern="api/v2/objects/stats/category-sum/" />
        <url ServiceParameter="ObjectStatsCategoryStatus" pattern="api/v2/objects/stats/category-status/" />
        <url ServiceParameter="ObjectStatsSizeSum" pattern="api/v2/objects/stats/size-sum/" />
index a1379c03300c5e5ed0cc649b030eb55d631db219..8632fa77583784e7e9000d7bb6321b413c549356 100644 (file)
                                }
                        }
                },
+               "/api/v2/objects/names": {
+                       "get": {
+                               "tags": ["objects"],
+                               "summary": "Object names",
+                               "description": "Get object names.",
+                               "responses": {
+                                       "200": {
+                                               "description": "Object names.",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Object name"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 6, 7, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/Limit"
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/objects/overview": {
                        "get": {
                                "tags": ["objects"],