feat: Implement NGINX proxy host and location management endpoints

- Add `get_location` endpoint to retrieve location information with optional upstream inclusion.
- Introduce `get_proxy_list` and `get_proxy` endpoints for listing and retrieving proxy hosts.
- Implement `remove_location` and `remove_proxy` endpoints for deleting locations and proxy hosts respectively.
- Add `update_location` and `update_proxy` endpoints for modifying existing locations and proxy hosts.
- Create response structures for location and proxy host information.
- Implement tests for all new endpoints to ensure correct functionality and error handling.
This commit is contained in:
GW_MC
2026-01-07 15:58:21 +08:00
parent 83e02acb22
commit 9b8232d94d
14 changed files with 2606 additions and 1 deletions

View File

@@ -106,6 +106,365 @@
}
}
},
"/api/nginx/locations/{location_id}": {
"get": {
"tags": [
"Nginx"
],
"operationId": "get_location",
"parameters": [
{
"name": "location_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Get location info",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LocationInfoResponse"
}
}
}
},
"404": {
"description": "Not found"
},
"500": {
"description": "Internal server error"
}
}
},
"delete": {
"tags": [
"Nginx"
],
"operationId": "remove_location",
"parameters": [
{
"name": "location_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Location removed successfully",
"content": {
"application/json": {
"schema": {
"default": null
}
}
}
},
"401": {
"description": "Unauthorized"
},
"404": {
"description": "Not found"
},
"500": {
"description": "Internal server error"
}
}
},
"patch": {
"tags": [
"Nginx"
],
"operationId": "update_location",
"parameters": [
{
"name": "location_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateLocationRequestBody"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Location updated successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LocationInfoResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"404": {
"description": "Not found"
},
"422": {
"description": "Invalid request"
},
"500": {
"description": "Internal server error"
}
}
}
},
"/api/nginx/proxy_hosts": {
"get": {
"tags": [
"Nginx"
],
"operationId": "get_proxy_list",
"responses": {
"200": {
"description": "List proxies",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProxyListResponse"
}
}
}
},
"500": {
"description": "Internal server error"
}
}
},
"post": {
"tags": [
"Nginx"
],
"operationId": "create_proxy",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateProxyRequestBody"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Proxy created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProxyHostInfoResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"422": {
"description": "Invalid request"
},
"500": {
"description": "Internal server error"
}
}
}
},
"/api/nginx/proxy_hosts/{proxy_id}": {
"get": {
"tags": [
"Nginx"
],
"operationId": "get_proxy",
"parameters": [
{
"name": "proxy_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Get proxy info",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProxyHostInfoResponse"
}
}
}
},
"404": {
"description": "Not found"
},
"500": {
"description": "Internal server error"
}
}
},
"delete": {
"tags": [
"Nginx"
],
"operationId": "remove_proxy",
"parameters": [
{
"name": "proxy_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Proxy removed successfully",
"content": {
"application/json": {
"schema": {
"default": null
}
}
}
},
"401": {
"description": "Unauthorized"
},
"404": {
"description": "Not found"
},
"500": {
"description": "Internal server error"
}
}
},
"patch": {
"tags": [
"crate::routes::api::restricted::nginx::proxy_host::update_proxy"
],
"operationId": "update_proxy",
"parameters": [
{
"name": "proxy_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateProxyRequestBody"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Proxy updated successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProxyHostInfoResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"422": {
"description": "Invalid request"
},
"500": {
"description": "Internal server error"
}
}
}
},
"/api/nginx/proxy_hosts/{proxy_id}/locations": {
"post": {
"tags": [
"Nginx"
],
"operationId": "create_location",
"parameters": [
{
"name": "proxy_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateLocationRequestBody"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Location created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LocationInfoResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"422": {
"description": "Invalid request"
},
"500": {
"description": "Internal server error"
}
}
}
},
"/api/nginx/upstream_targets/{upstream_target_id}": {
"get": {
"tags": [
@@ -508,6 +867,130 @@
}
}
},
"CreateLocationReq": {
"type": "object",
"required": [
"path",
"match_type",
"order"
],
"properties": {
"match_type": {
"type": "string"
},
"order": {
"type": "integer",
"format": "int64"
},
"path": {
"type": "string"
},
"upstream_id": {
"type": [
"string",
"null"
],
"format": "uuid"
}
}
},
"CreateLocationRequestBody": {
"type": "object",
"required": [
"path",
"match_type",
"order"
],
"properties": {
"match_type": {
"type": "string"
},
"order": {
"type": "integer",
"format": "int64"
},
"path": {
"type": "string"
},
"upstream_id": {
"type": [
"string",
"null"
],
"format": "uuid"
}
}
},
"CreateProxyRequestBody": {
"type": "object",
"required": [
"domain",
"scheme",
"listen_port",
"forward_scheme",
"preserve_host_header",
"enable_websocket",
"enabled",
"locations"
],
"properties": {
"default_upstream_id": {
"type": [
"string",
"null"
],
"format": "uuid"
},
"domain": {
"type": "string"
},
"enable_websocket": {
"type": "boolean"
},
"enabled": {
"type": "boolean"
},
"forward_host": {
"type": [
"string",
"null"
]
},
"forward_port": {
"type": [
"integer",
"null"
],
"format": "int64"
},
"forward_scheme": {
"type": "string"
},
"listen_port": {
"type": "integer",
"format": "int64"
},
"locations": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CreateLocationReq"
}
},
"meta": {},
"name": {
"type": [
"string",
"null"
]
},
"preserve_host_header": {
"type": "boolean"
},
"scheme": {
"type": "string"
}
}
},
"CreateUpstreamRequestBody": {
"type": "object",
"required": [
@@ -643,6 +1126,57 @@
}
}
},
"LocationInfoResponse": {
"type": "object",
"required": [
"id",
"host_id",
"path",
"match_type",
"order",
"enabled",
"created_at",
"updated_at"
],
"properties": {
"created_at": {
"type": "string",
"format": "date-time"
},
"enabled": {
"type": "boolean"
},
"host_id": {
"type": "string",
"format": "uuid"
},
"id": {
"type": "string",
"format": "uuid"
},
"match_type": {
"type": "string"
},
"order": {
"type": "integer",
"format": "int64"
},
"path": {
"type": "string"
},
"updated_at": {
"type": "string",
"format": "date-time"
},
"upstream_id": {
"type": [
"string",
"null"
],
"format": "uuid"
}
}
},
"LoginRequest": {
"type": "object",
"description": "Login request payload",
@@ -695,6 +1229,179 @@
}
}
},
"ProxyHostInfoResponse": {
"type": "object",
"required": [
"id",
"domain",
"scheme",
"listen_port",
"forward_scheme",
"preserve_host_header",
"enable_websocket",
"enabled",
"created_at",
"updated_at",
"locations"
],
"properties": {
"created_at": {
"type": "string",
"format": "date-time"
},
"domain": {
"type": "string"
},
"enable_websocket": {
"type": "boolean"
},
"enabled": {
"type": "boolean"
},
"forward_host": {
"type": [
"string",
"null"
]
},
"forward_port": {
"type": [
"integer",
"null"
],
"format": "int64"
},
"forward_scheme": {
"type": "string"
},
"id": {
"type": "string",
"format": "uuid"
},
"listen_port": {
"type": "integer",
"format": "int64"
},
"locations": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LocationInfoResponse"
}
},
"name": {
"type": [
"string",
"null"
]
},
"preserve_host_header": {
"type": "boolean"
},
"scheme": {
"type": "string"
},
"updated_at": {
"type": "string",
"format": "date-time"
},
"upstream": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/ProxyHostUpstreamBasic"
}
]
}
}
},
"ProxyHostUpstreamBasic": {
"type": "object",
"required": [
"id",
"name",
"protocol"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string"
},
"protocol": {
"type": "string"
}
}
},
"ProxyListResponse": {
"type": "object",
"required": [
"items",
"pagination"
],
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ProxyHostInfoResponse"
}
},
"pagination": {
"$ref": "#/components/schemas/PaginationInfo"
}
}
},
"UpdateLocationRequestBody": {
"type": "object",
"properties": {
"match_type": {
"type": [
"string",
"null"
]
},
"order": {
"type": [
"integer",
"null"
],
"format": "int64"
},
"path": {
"type": [
"string",
"null"
]
},
"upstream_id": {
"type": [
"string",
"null"
],
"format": "uuid"
}
}
},
"UpdateProxyRequestBody": {
"type": "object",
"properties": {
"domain": {
"type": [
"string",
"null"
]
},
"name": {
"type": [
"string",
"null"
]
}
}
},
"UpdateUpstreamInfoResponse": {
"type": "object",
"required": [