From 6b2baba3c76b756337872bb38fb802e30fbc1d89 Mon Sep 17 00:00:00 2001
From: Aleksey Dmitrevskiy <ad@adguard.com>
Date: Thu, 28 Feb 2019 11:10:43 +0300
Subject: [PATCH] Add set_upstreams_config function

---
 control.go           |  5 +++++
 openapi/openapi.yaml | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/control.go b/control.go
index d27a7cfc..d57114ce 100644
--- a/control.go
+++ b/control.go
@@ -306,6 +306,10 @@ func sortByValue(m map[string]int) []string {
 // upstreams configuration
 // -----------------------
 
+func handleSetUpstreamConfig(w http.ResponseWriter, r *http.Request) {
+	log.Tracef("%s %v", r.Method, r.URL)
+}
+
 func handleSetUpstreamDNS(w http.ResponseWriter, r *http.Request) {
 	log.Tracef("%s %v", r.Method, r.URL)
 	body, err := ioutil.ReadAll(r.Body)
@@ -1293,6 +1297,7 @@ func registerControlHandlers() {
 	http.HandleFunc("/control/querylog_enable", postInstall(optionalAuth(ensurePOST(handleQueryLogEnable))))
 	http.HandleFunc("/control/querylog_disable", postInstall(optionalAuth(ensurePOST(handleQueryLogDisable))))
 	http.HandleFunc("/control/set_upstream_dns", postInstall(optionalAuth(ensurePOST(handleSetUpstreamDNS))))
+	http.HandleFunc("/control/set_upstreams_config", postInstall(optionalAuth(ensurePOST(handleSetUpstreamConfig))))
 	http.HandleFunc("/control/test_upstream_dns", postInstall(optionalAuth(ensurePOST(handleTestUpstreamDNS))))
 	http.HandleFunc("/control/all_servers/enable", postInstall(optionalAuth(ensurePOST(handleAllServersEnable))))
 	http.HandleFunc("/control/all_servers/disable", postInstall(optionalAuth(ensurePOST(handleAllServersDisable))))
diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml
index e83d6360..f0fb68ee 100644
--- a/openapi/openapi.yaml
+++ b/openapi/openapi.yaml
@@ -87,6 +87,25 @@ paths:
                 200:
                     description: OK
 
+    /set_upstreams_config:
+        post:
+            tags:
+                - global
+            operationId: setUpstreamsConfig
+            summary: "Updates the current upstreams configuration"
+            consumes:
+                - application/json
+            parameters:
+                - in: "body"
+                  name: "body"
+                  description: "Upstreams configuration JSON"
+                  required: true
+                  schema:
+                      $ref: "#/definitions/UpstreamsConfig"
+            responses:
+                200:
+                    description: OK
+
     /set_upstream_dns:
         post:
             tags:
@@ -831,6 +850,25 @@ definitions:
             language:
                 type: "string"
                 example: "en"
+    UpstreamsConfig:
+        type: "object"
+        description: "Upstreams configuration"
+        required:
+            - "bootstrap_dns"
+            - "upstream_dns"
+        properties:
+            bootstrap_dns:
+                type: "string"
+                example: "8.8.8.8:53"
+            upstream_dns:
+                type: "array"
+                items:
+                    type: "string"
+                example:
+                    - "tls://1.1.1.1"
+                    - "tls://1.0.0.1"
+            all_servers:
+                type: "boolean"
     Filter:
         type: "object"
         description: "Filter subscription info"