]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add object types endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 31 May 2023 11:21:23 +0000 (13:21 +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/ObjectTypes.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 2b8ab6f30999a0479edd2bd882b74b0f8d01c031..6c0e3f662bfab0d8d0d6daf5810d8165b319c946 100644 (file)
@@ -659,4 +659,19 @@ JOIN Job USING (JobId) '
                $statement = Database::runQuery($sql, $where['params']);
                return $statement->fetchAll(\PDO::FETCH_ASSOC);
        }
+
+       /**
+        * Get existing object types.
+        *
+        * @return array object types
+        */
+       public function getObjectTypes() {
+               $sql = 'SELECT DISTINCT ObjectType as objecttype
+                       FROM Object';
+               $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/ObjectTypes.php b/gui/baculum/protected/API/Pages/API/ObjectTypes.php
new file mode 100644 (file)
index 0000000..b22363a
--- /dev/null
@@ -0,0 +1,39 @@
+<?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 types endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectTypes extends BaculumAPIServer {
+
+       public function get() {
+               $this->output = $this->getModule('object')->getObjectTypes();
+               $this->error = ObjectError::ERROR_NO_ERRORS;
+       }
+}
index 400bfbeb55c182481cae7977bcf200f6f888d57c..8c2679ca7d664dd0dd8ffef51c8687d688ab1bb3 100644 (file)
        <url ServiceParameter="ObjectClass" pattern="api/v2/objects/{id}/" parameters.id="\d+" />
        <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="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 e5d2afe8fd2a02088124bb2ecca39b88af0d7936..a1379c03300c5e5ed0cc649b030eb55d631db219 100644 (file)
                                ]
                        }
                },
+               "/api/v2/objects/types": {
+                       "get": {
+                               "tags": ["objects"],
+                               "summary": "Object types",
+                               "description": "Get object types.",
+                               "responses": {
+                                       "200": {
+                                               "description": "Object types.",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Object type"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 6, 7, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
                "/api/v2/objects/overview": {
                        "get": {
                                "tags": ["objects"],