mirror of
https://github.com/cert-manager/webhook-example.git
synced 2026-03-16 18:02:51 +01:00
report non-200 status codes
This commit is contained in:
parent
604c8b02d0
commit
78539b35e2
1 changed files with 11 additions and 0 deletions
11
dns/dns.go
11
dns/dns.go
|
|
@ -2,6 +2,8 @@ package dns
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -17,6 +19,7 @@ var (
|
|||
func SetTXTRecord(domain string, dnsName string, key string, login string, apiKey string) error {
|
||||
urlPath := fmt.Sprintf("/dns/%s/addRR", domain)
|
||||
requestUrl := fmt.Sprintf("%s%s", baseUrl, urlPath)
|
||||
log.Printf("Request URL: %v", requestUrl)
|
||||
|
||||
values := url.Values{"name": {dnsName}, "type": {"TXT"}, "data": {key}}
|
||||
body := values.Encode()
|
||||
|
|
@ -53,5 +56,13 @@ func send(login string, apiKey string, urlPath string, body string, requestUrl s
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
bytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("HTTP error code %v: %v", resp.StatusCode, string(bytes))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue