Browse Source

add search to config item endpoint

CauseFX 4 years ago
parent
commit
c748a14339
3 changed files with 73 additions and 3 deletions
  1. 15 1
      api/functions/config-functions.php
  2. 18 2
      api/v2/routes/config.php
  3. 40 0
      docs/api.json

+ 15 - 1
api/functions/config-functions.php

@@ -2,8 +2,22 @@
 
 trait ConfigFunctions
 {
-	public function getConfigItem($item)
+	public function getConfigItem($item, $term = null)
 	{
+		if (strtolower($item) == 'search') {
+			$configItems = $this->config;
+			$results = [];
+			foreach ($configItems as $configItem => $configItemValue) {
+				if (stripos($configItem, $term) !== false) {
+					$results[$configItem] = $configItemValue;
+					if ($configItem == 'organizrHash') {
+						$results[$configItem] = '***Secure***';
+					}
+				}
+			}
+			$this->setAPIResponse('success', 'Search results for term: ' . $term, 200, $results);
+			return $results;
+		}
 		if ($this->config[$item]) {
 			$configItem = $this->config[$item];
 			if ($item == 'organizrHash') {

+ 18 - 2
api/v2/routes/config.php

@@ -5,7 +5,7 @@
  *     description="Organizr Configuration Items"
  * )
  */
-$app->get('/config[/{item}]', function ($request, $response, $args) {
+$app->get('/config[/{item}[/{term}]]', function ($request, $response, $args) {
 	/**
 	 * @OA\Get(
 	 *     tags={"config"},
@@ -35,10 +35,26 @@ $app->get('/config[/{item}]', function ($request, $response, $args) {
 	 *     security={{ "api_key":{} }}
 	 * )
 	 */
+	/**
+	 * @OA\Get(
+	 *     tags={"config"},
+	 *     path="/api/v2/config/search/{term}",
+	 *     summary="Search Organizr Coniguration Items",
+	 *     @OA\Parameter(name="term",description="The term of the items you want to grab",@OA\Schema(type="string"),in="path",required=true,example="version"),
+	 *     @OA\Response(
+	 *      response="200",
+	 *      description="Success",
+	 *      @OA\JsonContent(ref="#/components/schemas/success-message"),
+	 *     ),
+	 *     @OA\Response(response="401",description="Unauthorized"),
+	 *     security={{ "api_key":{} }}
+	 * )
+	 */
 	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
 	if ($Organizr->qualifyRequest(1, true)) {
 		if (isset($args['item'])) {
-			$Organizr->getConfigItem($args['item']);
+			$search = ($args['term']) ?? null;
+			$Organizr->getConfigItem($args['item'], $search);
 		} else {
 			$GLOBALS['api']['response']['data'] = $Organizr->getConfigItems();
 		}

+ 40 - 0
docs/api.json

@@ -1188,6 +1188,46 @@
                 ]
             }
         },
+        "/api/v2/config/search/{term}": {
+            "get": {
+                "tags": [
+                    "config"
+                ],
+                "summary": "Search Organizr Coniguration Items",
+                "parameters": [
+                    {
+                        "name": "term",
+                        "in": "path",
+                        "description": "The term of the items you want to grab",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        },
+                        "example": "version"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "Success",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/success-message"
+                                }
+                            }
+                        }
+                    },
+                    "401": {
+                        "description": "Unauthorized"
+                    }
+                },
+                "security": [
+                    {
+                        "api_key": []
+                    }
+                ]
+            }
+        },
         "/api/v2/test/ldap": {
             "post": {
                 "tags": [