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;
+ }
}
--- /dev/null
+<?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;
+ }
+}
<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/" />
}
}
},
+ "/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"],