diff options
| author | Jeff Carr <[email protected]> | 2024-01-05 19:18:36 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-05 19:18:36 -0600 | 
| commit | 2ce239c6ce339597e140f645cdcec1e2b303111b (patch) | |
| tree | 1e4b062233d42898b4ba9638bb083c781df9bef0 | |
| parent | d3536a2b2881c6103bd39fb14ffa0b8484c3edc5 (diff) | |
CURL output flag works
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | api.go | 2 | ||||
| -rw-r--r-- | args.go | 2 | ||||
| -rw-r--r-- | http.go | 61 | 
3 files changed, 32 insertions, 33 deletions
@@ -99,7 +99,7 @@ func SetRow(dnsRow *RRT) {  }  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)  	req, err := http.NewRequest("GET", url, nil)  	if err != nil { @@ -7,8 +7,6 @@ import (  )  var CURL log.LogFlag -var POLL log.LogFlag -var BUG log.LogFlag  func init() {  	CURL.B = true @@ -49,20 +49,22 @@ func doCurlDelete(auth string, email string, zoneId string, rrId string) string  	// Set headers  	req.Header.Set("Content-Type", "application/json") -	req.Header.Set("X-Auth-Key", auth) -	req.Header.Set("X-Auth-Email", email) +	req.Header.Set("Authorization", "Bearer " + auth) +	// changed from this 2024-01-05 +	// req.Header.Set("X-Auth-Key", auth) +	// req.Header.Set("X-Auth-Email", email)  	client := &http.Client{}  	resp, err := client.Do(req)  	if err != nil { -		log.Println(err) +		log.Error(err)  		return ""  	}  	defer resp.Body.Close()  	body, err := ioutil.ReadAll(resp.Body)  	if err != nil { -		log.Println(err) +		log.Error(err)  		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/" -	log.Info("doCurlCreate() POST url =", url) -	log.Info("doCurlCreate() POST Auth =", auth) -	log.Info("doCurlCreate() POST Email =", email) -	log.Info("doCurlCreate() POST data =", data) +	log.Log(CURL, "doCurlCreate() POST url =", url) +	log.Log(CURL, "doCurlCreate() POST Auth =", auth) +	log.Log(CURL, "doCurlCreate() POST Email =", email) +	log.Log(CURL, "doCurlCreate() POST data =", data)  	req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer( []byte(data) ))  	// Set headers  	req.Header.Set("Content-Type", "application/json") -	req.Header.Set("X-Auth-Key", auth) -	req.Header.Set("X-Auth-Email", email) +	req.Header.Set("Authorization", "Bearer " + auth)  	client := &http.Client{}  	resp, err := client.Do(req)  	if err != nil { -		log.Println(err) +		log.Error(err, "client.Do() failed")  		return ""  	}  	defer resp.Body.Close()  	body, err := ioutil.ReadAll(resp.Body)  	if err != nil { -		log.Println(err) +		log.Error(err, "ioutil.ReadAll(body) failed")  		return ""  	} +	pretty, _ := FormatJSON(string(body)) +	log.Log(CURL, "Create() result =", pretty)  	return string(body)  } @@ -123,25 +126,24 @@ func doCurl(method string, rr *RRT) string {  	// Set headers  	req.Header.Set("Content-Type", "application/json") -	req.Header.Set("X-Auth-Key", rr.Auth) -	req.Header.Set("X-Auth-Email", rr.Email) +	req.Header.Set("Authorization", "Bearer " + rr.Auth) -	log.Println("http PUT url =", rr.url) -	log.Println("http PUT Auth =", rr.Auth) -	log.Println("http PUT Email =", rr.Email) -	log.Println("http PUT data =", rr.data) +	log.Log(CURL, "http PUT url =", rr.url) +	log.Log(CURL, "http PUT Auth =", rr.Auth) +	log.Log(CURL, "http PUT Email =", rr.Email) +	log.Log(CURL, "http PUT data =", rr.data)  	client := &http.Client{}  	resp, err := client.Do(req)  	if err != nil { -		log.Println(err) +		log.Error(err)  		return ""  	}  	defer resp.Body.Close()  	body, err := ioutil.ReadAll(resp.Body)  	if err != nil { -		log.Println(err) +		log.Error(err)  		return ""  	} @@ -155,35 +157,34 @@ func curlPost(dnsRow *RRT) string {  	url := dnsRow.url  	tmp := dnsRow.data -	log.Println("curlPost() START") -	log.Println("curlPost() authkey = ", authKey) -	log.Println("curlPost() email   = ", email) -	log.Println("curlPost() url     = ", url) +	log.Log(CURL, "curlPost() START") +	log.Log(CURL, "curlPost() authkey = ", authKey) +	log.Log(CURL, "curlPost() email   = ", email) +	log.Log(CURL, "curlPost() url     = ", url)  	data := []byte(tmp)  	req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))  	// Set headers  	req.Header.Set("Content-Type", "application/json") -	req.Header.Set("X-Auth-Key", authKey) -	req.Header.Set("X-Auth-Email", email) +	req.Header.Set("Authorization", "Bearer " + authKey)  	client := &http.Client{}  	resp, err := client.Do(req)  	if err != nil { -		log.Println(err) +		log.Error(err, "client.Do() failed")  		return ""  	}  	defer resp.Body.Close()  	body, err := ioutil.ReadAll(resp.Body)  	if err != nil { -		log.Println(err) +		log.Error(err)  		return ""  	}  	log.Spew("http PUT body =", body) -	log.Println("result =", string(body)) -	log.Println("curl() END")  	pretty, _ := FormatJSON(string(body)) +	log.Log(CURL, "result =", pretty) +	log.Log(CURL, "curl() END")  	return pretty  }  | 
