]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add single object record endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 10 Aug 2022 12:52:00 +0000 (14:52 +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/ObjectClass.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml

index 26154e4f6e083d8a27db8337a5caa7b0454fcece..5a6cd22b0c565eb873ea200e746ccf29628d9163 100644 (file)
@@ -53,4 +53,18 @@ LEFT JOIN Job USING (JobId) '
 
                return ObjectRecord::finder()->findAllBySql($sql, $where['params']);
        }
+
+       public function getObjectById($objectid) {
+               $params = [
+                       'Object.ObjectId' => [
+                               'vals' => $objectid,
+                               'operator' => ''
+                       ]
+               ];
+               $obj = $this->getObjects($params, 1);
+               if (is_array($obj) && count($obj) > 0) {
+                       $obj = array_shift($obj);
+               }
+               return $obj;
+       }
 }
diff --git a/gui/baculum/protected/API/Pages/API/ObjectClass.php b/gui/baculum/protected/API/Pages/API/ObjectClass.php
new file mode 100644 (file)
index 0000000..d198e65
--- /dev/null
@@ -0,0 +1,46 @@
+<?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;
+
+/**
+ * Objects endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectClass extends BaculumAPIServer {
+
+       public function get() {
+               $objectid = $this->Request->contains('id') ? (int)$this->Request['id'] : 0;
+
+               $object = $this->getModule('object')->getObjectById($objectid);
+               if (is_object($object)) {
+                       $this->output = $object;
+                       $this->error = ObjectError::ERROR_NO_ERRORS;
+               } else {
+                       $this->output = ObjectError::MSG_ERROR_OBJECT_DOES_NOT_EXISTS;
+                       $this->error = ObjectError::ERROR_OBJECT_DOES_NOT_EXISTS;
+               }
+       }
+}
index d60165b90949a4f70419953de4be2d8437a30610..a64b3a91261af918ec8b9f166ad5b15ae14ecafb 100644 (file)
@@ -89,6 +89,7 @@
        <url ServiceParameter="JobLog" pattern="api/v2/joblog/{id}/" parameters.id="\d+" />
        <!-- event endpoints -->
        <url ServiceParameter="Objects" pattern="api/v2/objects/" />
+       <url ServiceParameter="ObjectClass" pattern="api/v2/objects/{id}/" parameters.id="\d+" />
        <!-- @TODO: Separate this endpoint outside 'joblog' -->
        <url ServiceParameter="Messages" pattern="api/v2/joblog/messages" />
        <!-- fileset endpoints -->