CURL output flag works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-05 19:18:36 -06:00
parent d3536a2b28
commit 2ce239c6ce
3 changed files with 32 additions and 33 deletions

2
api.go
View File

@ -99,7 +99,7 @@ func SetRow(dnsRow *RRT) {
} }
func GetZonefile(c *ConfigT) *DNSRecords { func GetZonefile(c *ConfigT) *DNSRecords {
var url = cloudflareURL + c.ZoneID + "/dns_records/?per_page=10" var url = cloudflareURL + c.ZoneID + "/dns_records/?per_page=100"
log.Println("getZonefile()", c.Domain, url) log.Println("getZonefile()", c.Domain, url)
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {

View File

@ -7,8 +7,6 @@ import (
) )
var CURL log.LogFlag var CURL log.LogFlag
var POLL log.LogFlag
var BUG log.LogFlag
func init() { func init() {
CURL.B = true CURL.B = true

61
http.go
View File

@ -49,20 +49,22 @@ func doCurlDelete(auth string, email string, zoneId string, rrId string) string
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Auth-Key", auth) req.Header.Set("Authorization", "Bearer " + auth)
req.Header.Set("X-Auth-Email", email) // changed from this 2024-01-05
// req.Header.Set("X-Auth-Key", auth)
// req.Header.Set("X-Auth-Email", email)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
log.Println(err) log.Error(err)
return "" return ""
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Println(err) log.Error(err)
return "" return ""
} }
@ -80,32 +82,33 @@ func doCurlCreate(auth string, email string, zoneId string, data string) string
url := "https://api.cloudflare.com/client/v4/zones/" + zoneId + "/dns_records/" url := "https://api.cloudflare.com/client/v4/zones/" + zoneId + "/dns_records/"
log.Info("doCurlCreate() POST url =", url) log.Log(CURL, "doCurlCreate() POST url =", url)
log.Info("doCurlCreate() POST Auth =", auth) log.Log(CURL, "doCurlCreate() POST Auth =", auth)
log.Info("doCurlCreate() POST Email =", email) log.Log(CURL, "doCurlCreate() POST Email =", email)
log.Info("doCurlCreate() POST data =", data) log.Log(CURL, "doCurlCreate() POST data =", data)
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer( []byte(data) )) req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer( []byte(data) ))
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Auth-Key", auth) req.Header.Set("Authorization", "Bearer " + auth)
req.Header.Set("X-Auth-Email", email)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
log.Println(err) log.Error(err, "client.Do() failed")
return "" return ""
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Println(err) log.Error(err, "ioutil.ReadAll(body) failed")
return "" return ""
} }
pretty, _ := FormatJSON(string(body))
log.Log(CURL, "Create() result =", pretty)
return string(body) return string(body)
} }
@ -123,25 +126,24 @@ func doCurl(method string, rr *RRT) string {
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Auth-Key", rr.Auth) req.Header.Set("Authorization", "Bearer " + rr.Auth)
req.Header.Set("X-Auth-Email", rr.Email)
log.Println("http PUT url =", rr.url) log.Log(CURL, "http PUT url =", rr.url)
log.Println("http PUT Auth =", rr.Auth) log.Log(CURL, "http PUT Auth =", rr.Auth)
log.Println("http PUT Email =", rr.Email) log.Log(CURL, "http PUT Email =", rr.Email)
log.Println("http PUT data =", rr.data) log.Log(CURL, "http PUT data =", rr.data)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
log.Println(err) log.Error(err)
return "" return ""
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Println(err) log.Error(err)
return "" return ""
} }
@ -155,35 +157,34 @@ func curlPost(dnsRow *RRT) string {
url := dnsRow.url url := dnsRow.url
tmp := dnsRow.data tmp := dnsRow.data
log.Println("curlPost() START") log.Log(CURL, "curlPost() START")
log.Println("curlPost() authkey = ", authKey) log.Log(CURL, "curlPost() authkey = ", authKey)
log.Println("curlPost() email = ", email) log.Log(CURL, "curlPost() email = ", email)
log.Println("curlPost() url = ", url) log.Log(CURL, "curlPost() url = ", url)
data := []byte(tmp) data := []byte(tmp)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data)) req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Auth-Key", authKey) req.Header.Set("Authorization", "Bearer " + authKey)
req.Header.Set("X-Auth-Email", email)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
log.Println(err) log.Error(err, "client.Do() failed")
return "" return ""
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Println(err) log.Error(err)
return "" return ""
} }
log.Spew("http PUT body =", body) log.Spew("http PUT body =", body)
log.Println("result =", string(body))
log.Println("curl() END")
pretty, _ := FormatJSON(string(body)) pretty, _ := FormatJSON(string(body))
log.Log(CURL, "result =", pretty)
log.Log(CURL, "curl() END")
return pretty return pretty
} }