From e973c4b174d9249cb05f01faa9d7662f2f04d55e Mon Sep 17 00:00:00 2001 From: Aleksey Dmitrevskiy Date: Tue, 5 Mar 2019 12:29:52 +0300 Subject: [PATCH] [change] control, openapi: Handle upstreams test with JSON --- control.go | 4 ++-- openapi/openapi.yaml | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/control.go b/control.go index 7b17321b..0bc6fc66 100644 --- a/control.go +++ b/control.go @@ -361,12 +361,12 @@ func checkBootstrapDNS(host string) error { func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) { 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 { httpError(w, http.StatusBadRequest, "Failed to read request body: %s", err) return } - hosts := strings.Fields(string(body)) if len(hosts) == 0 { httpError(w, http.StatusBadRequest, "No servers specified") diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 6d0aafb4..d84e90ec 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -111,21 +111,15 @@ paths: tags: - global operationId: testUpstreamDNS - summary: 'Test upstream DNS' + summary: "Test upstream DNS" consumes: - - text/plain + - application/json parameters: - - in: body - name: upstream - description: 'Upstream servers, separated by newline or space, port is optional after colon' + - in: "body" + name: "body" + description: "Upstream servers to be tested" schema: - # TODO: use JSON - type: string - example: | - 1.1.1.1 - 1.0.0.1 - 8.8.8.8 8.8.4.4 - 192.168.1.104:53535 + $ref: "#/definitions/TestUpstreams" responses: 200: 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: type: "boolean" 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: type: "object" description: "Filter subscription info"