]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add object versions endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 12 Aug 2022 07:24:06 +0000 (09:24 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 17 Nov 2022 09:05:10 +0000 (10:05 +0100)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/ObjectVersions.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 637ed4dc3cf4f7027369cffccc47a33d217b1069..6ffa219c1b06f75d1b756146ee0b2373c503b616 100644 (file)
@@ -187,4 +187,45 @@ LEFT JOIN Job USING (JobId) '
                $sth->execute();
                return $sth->fetchAll(\PDO::FETCH_ASSOC);
        }
+
+       /**
+        * Get all object versions by objectuuid.
+        *
+        * @param string $objectuuid object UUID
+        * @return array object versions
+        */
+       public function getObjectVersions($objectuuid) {
+               $sql = 'SELECT
+                               obj.ObjectUUID     AS objectuuid,
+                               obj.ObjectId       AS objectid,
+                               obj.ObjectType     AS objecttype,
+                               obj.ObjectName     AS objectname,
+                               obj.ObjectCategory AS objectcategory,
+                               Job.JobId          AS jobid,
+                               Job.Name           AS jobname,
+                               Job.Level          AS level,
+                               Job.JobStatus      AS jobstatus,
+                               Job.JobBytes       AS jobbytes,
+                               Job.JobFiles       AS jobfiles,
+                               Job.StartTime      AS starttime,
+                               Job.EndTime        AS endtime,
+                               Job.JobErrors      AS joberrors,
+                               Client.Name        AS client,
+                               FileSet.FileSet    AS fileset
+                               FROM
+                                       Object AS obj
+                                       LEFT JOIN Job USING(JobId)
+                                       LEFT JOIN Client USING(ClientId)
+                                       LEFT JOIN FileSet USING(FileSetId)
+                               WHERE
+                                       obj.ObjectUUID=:objectuuid
+                               ORDER BY Job.StartTime DESC';
+               $connection = ObjectRecord::finder()->getDbConnection();
+               $connection->setActive(true);
+               $pdo = $connection->getPdoInstance();
+               $sth = $pdo->prepare($sql);
+               $sth->bindParam(':objectuuid', $objectuuid, \PDO::PARAM_STR, 400);
+               $sth->execute();
+               return $sth->fetchAll(\PDO::FETCH_ASSOC);
+       }
 }
diff --git a/gui/baculum/protected/API/Pages/API/ObjectVersions.php b/gui/baculum/protected/API/Pages/API/ObjectVersions.php
new file mode 100644 (file)
index 0000000..0093c7f
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2022 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\Common\Modules\Errors\ObjectError;
+
+/**
+ * Object versions endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectVersions extends BaculumAPIServer {
+
+       public function get() {
+               $misc = $this->getModule('misc');
+               $objectuuid = null;
+               if ($this->Request->contains('uuid') && $misc->isValidName($this->Request['uuid'])) {
+                       $objectuuid = $this->Request['uuid'];
+               }
+
+               $versions = $this->getModule('object')->getObjectVersions(
+                       $objectuuid
+               );
+               $this->output = $versions;
+               $this->error = ObjectError::ERROR_NO_ERRORS;
+       }
+}
index 28d98cf844d40a640288f7cc21c30d83d71298ac..04f93a251207a7f1dbff1697ce062e6516b721b4 100644 (file)
@@ -90,6 +90,7 @@
        <!-- event endpoints -->
        <url ServiceParameter="Objects" pattern="api/v2/objects/" />
        <url ServiceParameter="ObjectClass" pattern="api/v2/objects/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="ObjectVersions" pattern="api/v2/objects/versions/{uuid}" parameters.uuid="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="ObjectStatsCategorySum" pattern="api/v2/objects/stats/category-sum/" />
        <url ServiceParameter="ObjectStatsSizeSum" pattern="api/v2/objects/stats/size-sum/" />
        <!-- @TODO: Separate this endpoint outside 'joblog' -->
index 2ec19573648efbc1c59f818a1a955a9662179c39..92add7e25960378bb8f4eae88d2d135eb14b98cc 100644 (file)
                                ]
                        }
                },
+               "/api/v2/objects/versions/{objectuuid}": {
+                       "get": {
+                               "tags": ["objects"],
+                               "summary": "Object versions by objectuuid",
+                               "description": "Get object versions.",
+                               "responses": {
+                                       "200": {
+                                               "description": "Object versions by objectuuid",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "$ref": "#/components/schemas/Objects"
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 6, 7, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "name": "objectuuid",
+                                               "in": "path",
+                                               "required": true,
+                                               "description": "Object UUID",
+                                               "schema": {
+                                                       "type": "string"
+                                               }
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/objects/stats/category-sum": {
                        "get": {
                                "tags": ["objects"],