Browse Source

add get config items from api

CauseFX 4 years ago
parent
commit
f05ee47591
3 changed files with 262 additions and 2 deletions
  1. 16 0
      api/functions/config-functions.php
  2. 30 1
      api/v2/routes/config.php
  3. 216 1
      docs/api.json

+ 16 - 0
api/functions/config-functions.php

@@ -15,6 +15,22 @@ trait ConfigFunctions
 			$this->setAPIResponse('error', $item . ' is not defined or is blank', 404);
 			return false;
 		}
+	}
+	
+	public function getConfigItems()
+	{
+		$configItems = $this->config;
+		/*
+		foreach ($configItems as $configItem => $configItemValue) {
+			// should we keep this to filter more items?
+			if ($configItem == 'organizrHash') {
+				$configItems[$configItem] = '***Secure***';
+			}
+		}
+		*/
+		$configItems['organizrHash'] = '***Secure***';
+		$this->setAPIResponse('success', null, 200, $configItems);
+		return $configItems;
 		
 	}
 }

+ 30 - 1
api/v2/routes/config.php

@@ -6,12 +6,41 @@
  * )
  */
 $app->get('/config[/{item}]', function ($request, $response, $args) {
+	/**
+	 * @OA\Get(
+	 *     tags={"config"},
+	 *     path="/api/v2/config",
+	 *     summary="Get Organizr Coniguration Items",
+	 *     @OA\Response(
+	 *      response="200",
+	 *      description="Success",
+	 *      @OA\JsonContent(ref="#/components/schemas/success-message"),
+	 *     ),
+	 *     @OA\Response(response="401",description="Unauthorized"),
+	 *     security={{ "api_key":{} }}
+	 * )
+	 */
+	/**
+	 * @OA\Get(
+	 *     tags={"config"},
+	 *     path="/api/v2/config/{item}",
+	 *     summary="Get Organizr Coniguration Item",
+	 *     @OA\Parameter(name="item",description="The key of the item you want to grab",@OA\Schema(type="string"),in="path",required=true,example="configVersion"),
+	 *     @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']);
 		} else {
-			$GLOBALS['api']['response']['data'] = $Organizr->config;
+			$GLOBALS['api']['response']['data'] = $Organizr->getConfigItems();
 		}
 		
 	}

+ 216 - 1
docs/api.json

@@ -1084,6 +1084,32 @@
             }
         },
         "/api/v2/config": {
+            "get": {
+                "tags": [
+                    "config"
+                ],
+                "summary": "Get Organizr Coniguration Items",
+                "responses": {
+                    "200": {
+                        "description": "Success",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/success-message"
+                                }
+                            }
+                        }
+                    },
+                    "401": {
+                        "description": "Unauthorized"
+                    }
+                },
+                "security": [
+                    {
+                        "api_key": []
+                    }
+                ]
+            },
             "put": {
                 "tags": [
                     "config"
@@ -1122,6 +1148,46 @@
                 ]
             }
         },
+        "/api/v2/config/{item}": {
+            "get": {
+                "tags": [
+                    "config"
+                ],
+                "summary": "Get Organizr Coniguration Item",
+                "parameters": [
+                    {
+                        "name": "item",
+                        "in": "path",
+                        "description": "The key of the item you want to grab",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        },
+                        "example": "configVersion"
+                    }
+                ],
+                "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": [
@@ -1937,6 +2003,61 @@
                 ]
             }
         },
+        "/api/v2/test/overseerr": {
+            "post": {
+                "tags": [
+                    "test connection"
+                ],
+                "summary": "Test connection to Overseerr",
+                "responses": {
+                    "200": {
+                        "description": "Success",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/success-message"
+                                }
+                            }
+                        }
+                    },
+                    "401": {
+                        "description": "Unauthorized",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/unauthorized-message"
+                                }
+                            }
+                        }
+                    },
+                    "422": {
+                        "description": "Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/error-message"
+                                }
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/error-message"
+                                }
+                            }
+                        }
+                    }
+                },
+                "security": [
+                    {
+                        "api_key": []
+                    }
+                ]
+            }
+        },
         "/api/v2/test/nzbget": {
             "post": {
                 "tags": [
@@ -1992,6 +2113,61 @@
                 ]
             }
         },
+        "/api/v2/test/utorrent": {
+            "post": {
+                "tags": [
+                    "test connection"
+                ],
+                "summary": "Test connection to uTorrent",
+                "responses": {
+                    "200": {
+                        "description": "Success",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/success-message"
+                                }
+                            }
+                        }
+                    },
+                    "401": {
+                        "description": "Unauthorized",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/unauthorized-message"
+                                }
+                            }
+                        }
+                    },
+                    "400": {
+                        "description": "Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/error-message"
+                                }
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/error-message"
+                                }
+                            }
+                        }
+                    }
+                },
+                "security": [
+                    {
+                        "api_key": []
+                    }
+                ]
+            }
+        },
         "/api/v2/test/deluge": {
             "post": {
                 "tags": [
@@ -2400,6 +2576,45 @@
                 }
             }
         },
+        "/api/v2/organizr/{page}": {
+            "get": {
+                "tags": [
+                    "page"
+                ],
+                "summary": "Get HTML for Organizr Pages",
+                "parameters": [
+                    {
+                        "name": "page",
+                        "in": "path",
+                        "description": "Page to get",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "Success",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/get-html"
+                                }
+                            }
+                        }
+                    },
+                    "401": {
+                        "description": "Unauthorized"
+                    }
+                },
+                "security": [
+                    {
+                        "api_key": []
+                    }
+                ]
+            }
+        },
         "/api/v2/page/{page}": {
             "get": {
                 "tags": [
@@ -3781,4 +3996,4 @@
             "description": "Organizr Update"
         }
     ]
-}
+}