From: Marcin Haba Date: Wed, 31 May 2023 12:47:32 +0000 (+0200) Subject: baculum: Add object names endpoint X-Git-Tag: Release-13.0.4~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4a54d6f2a123f28bb7bde8b5715206786f0fada;p=thirdparty%2Fbacula.git baculum: Add object names endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index 6c0e3f662..c99a3fe77 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -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 index 000000000..eb81e20ca --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/ObjectNames.php @@ -0,0 +1,41 @@ + + * @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; + } +} diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index 8c2679ca7..8ff16209d 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -107,6 +107,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index a1379c033..8632fa775 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -8360,6 +8360,44 @@ } } }, + "/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"],