[change] control, openapi: Handle upstreams test with JSON

This commit is contained in:
Aleksey Dmitrevskiy 2019-03-05 12:29:52 +03:00
parent d9d641941c
commit e973c4b174
2 changed files with 22 additions and 14 deletions

View File

@ -361,12 +361,12 @@ func checkBootstrapDNS(host string) error {
func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) { func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL) log.Tracef("%s %v", r.Method, r.URL)
body, err := ioutil.ReadAll(r.Body) hosts := []string{}
err := json.NewDecoder(r.Body).Decode(&hosts)
if err != nil { if err != nil {
httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err)
return return
} }
hosts := strings.Fields(string(body))
if len(hosts) == 0 { if len(hosts) == 0 {
httpError(w, http.StatusBadRequest, "No servers specified") httpError(w, http.StatusBadRequest, "No servers specified")

View File

@ -111,21 +111,15 @@ paths:
tags: tags:
- global - global
operationId: testUpstreamDNS operationId: testUpstreamDNS
summary: 'Test upstream DNS' summary: "Test upstream DNS"
consumes: consumes:
- text/plain - application/json
parameters: parameters:
- in: body - in: "body"
name: upstream name: "body"
description: 'Upstream servers, separated by newline or space, port is optional after colon' description: "Upstream servers to be tested"
schema: schema:
# TODO: use JSON $ref: "#/definitions/TestUpstreams"
type: string
example: |
1.1.1.1
1.0.0.1
8.8.8.8 8.8.4.4
192.168.1.104:53535
responses: responses:
200: 200:
description: 'Status of testing each requested server, with "OK" meaning that server works, any other text means an error.' description: 'Status of testing each requested server, with "OK" meaning that server works, any other text means an error.'
@ -820,6 +814,20 @@ definitions:
all_servers: all_servers:
type: "boolean" type: "boolean"
description: "If true, parallel queries to all configured upstream servers are enabled" description: "If true, parallel queries to all configured upstream servers are enabled"
TestUpstreams:
type: "object"
description: "Upstream servers to be tested"
required:
- "upstream_dns"
properties:
upstream_dns:
type: "array"
description: 'Upstream servers, port is optional after colon'
items:
type: "string"
example:
- "tls://1.1.1.1"
- "tls://1.0.0.1"
Filter: Filter:
type: "object" type: "object"
description: "Filter subscription info" description: "Filter subscription info"