@@ -7,10 +7,11 @@ import (
7
7
"encoding/json"
8
8
"errors"
9
9
"fmt"
10
+ "io"
10
11
"log"
11
12
"net/http"
13
+ "net/url"
12
14
"os"
13
- "os/exec"
14
15
"path/filepath"
15
16
"strings"
16
17
"time"
@@ -295,19 +296,30 @@ func registerHandler(c echo.Context) error {
295
296
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert user theme: "+err.Error())
296
297
// }
297
298
298
- if out , err := exec .Command ("pdnsutil" , "add-record" , "u.isucon.dev" , req .Name , "A" , "10" , powerDNSSubdomainAddress ).CombinedOutput (); err != nil {
299
- return echo .NewHTTPError (http .StatusInternalServerError , string (out )+ ": " + err .Error ())
299
+ // if out, err := exec.Command("pdnsutil", "add-record", "u.isucon.dev", req.Name, "A", "10", powerDNSSubdomainAddress).CombinedOutput(); err != nil {
300
+ // return echo.NewHTTPError(http.StatusInternalServerError, string(out)+": "+err.Error())
301
+ // }
302
+
303
+ url , err := url .Parse ("http://" + powerDNSSubdomainAddress + ":8081/api/v1/servers/localhost/zones/u.isucon.dev." )
304
+ if err != nil {
305
+ return echo .NewHTTPError (http .StatusInternalServerError , "failed to parse url: " + err .Error ())
300
306
}
301
307
302
- // url, err := url.Parse("http://" + powerDNSSubdomainAddress + "/api/v1/servers/localhost/zones/u.isucon.dev.")
303
- // client := &http.Client{}
304
- // client.Do(&http.Request{
305
- // Method: "PATCH",
306
- // URL: url,
307
- // Header: http.Header{
308
- // "X-API-Key": []string{"secret"},
309
- // },
310
- // })
308
+ payload := `{"rrsets": [{"name": "` + req .Name + `", "type": "A", "ttl": 10, "changetype": "REPLACE", "records": [{"content": "` + powerDNSSubdomainAddress + `", "disabled": false}]}]}`
309
+
310
+ client := & http.Client {}
311
+ _ , err = client .Do (& http.Request {
312
+ Method : "PATCH" ,
313
+ URL : url ,
314
+ Header : http.Header {
315
+ "X-API-Key" : []string {"isudns" },
316
+ },
317
+ Body : io .NopCloser (strings .NewReader (payload )),
318
+ })
319
+ if err != nil {
320
+ log .Println ("failed to request to powerdns: " , err )
321
+ return echo .NewHTTPError (http .StatusInternalServerError , "failed to request to powerdns: " + err .Error ())
322
+ }
311
323
312
324
user , err := fillUserResponse (ctx , tx , userModel )
313
325
if err != nil {
0 commit comments