fix DELETE
just send request for delete without checking if record exist
This commit is contained in:
parent
fd543c4855
commit
7669aee818
69
main.go
69
main.go
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
"github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||||
"github.com/jetstack/cert-manager/pkg/acme/webhook/cmd"
|
"github.com/jetstack/cert-manager/pkg/acme/webhook/cmd"
|
||||||
|
"github.com/jetstack/cert-manager/pkg/issuer/acme/dns/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var GroupName = os.Getenv("GROUP_NAME")
|
var GroupName = os.Getenv("GROUP_NAME")
|
||||||
@ -147,7 +148,7 @@ func (c *manituDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
|||||||
body := bytes.NewBuffer(entry)
|
body := bytes.NewBuffer(entry)
|
||||||
|
|
||||||
// Create request
|
// Create request
|
||||||
req, err = http.NewRequest("POST", "https://dnsapi.elutions-network.de/api/v1/records", body)
|
req, err = http.NewRequest("POST", "https://dnsapi.elutions-network.de/api/v1/zones/"+zone+"/records", body)
|
||||||
// Headers
|
// Headers
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
req.Header.Add("Authorization", cfg.APIKey)
|
req.Header.Add("Authorization", cfg.APIKey)
|
||||||
@ -189,7 +190,7 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
|||||||
// Get Zones (GET https://dnsapi.elutions-network.de/api/v1/zones)
|
// Get Zones (GET https://dnsapi.elutions-network.de/api/v1/zones)
|
||||||
// Create client
|
// Create client
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
/*
|
||||||
// Create request
|
// Create request
|
||||||
zReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/zones/"+zone, nil)
|
zReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/zones/"+zone, nil)
|
||||||
// Headers
|
// Headers
|
||||||
@ -230,35 +231,39 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
|||||||
|
|
||||||
fmt.Println("response Status : ", eResp.Status)
|
fmt.Println("response Status : ", eResp.Status)
|
||||||
fmt.Println("response Headers : ", eResp.Header)
|
fmt.Println("response Headers : ", eResp.Header)
|
||||||
fmt.Println("response Body : ", eRespBody)
|
fmt.Println("response Body : ", eRespBody)*/
|
||||||
|
|
||||||
for _, e := range eRespBody.Records {
|
/*for _, e := range eRespBody.Records {
|
||||||
|
fmt.Println("Try DOMAIN: ", e)
|
||||||
|
fmt.Println(e.Type,"== TXT")
|
||||||
|
fmt.Println(e.Name,"==", name)
|
||||||
|
fmt.Println(e.Value,"==", ch.Key)
|
||||||
if e.Type == "TXT" && e.Name == name && e.Value == ch.Key {
|
if e.Type == "TXT" && e.Name == name && e.Value == ch.Key {
|
||||||
fmt.Println("Found DOMAIN: ", e)
|
fmt.Println("Found DOMAIN: ", e)*/
|
||||||
// Delete Record
|
// Delete Record
|
||||||
// Create request
|
// Create request
|
||||||
req, err := http.NewRequest("DELETE", "https://dnsapi.elutions-network.de/api/v1/zones/"+zRespBody.ZoneID+"/records?host="+e.Name+"&value="+e.Value+"&type="+e.Type, nil)
|
req, err := http.NewRequest("DELETE", "https://dnsapi.elutions-network.de/api/v1/zones/"+zone+"/records?host="+name+"&value="+ch.Key+"&type=TXT", nil)
|
||||||
|
|
||||||
// Headers
|
// Headers
|
||||||
req.Header.Add("Authorization", cfg.APIKey)
|
req.Header.Add("Authorization", cfg.APIKey)
|
||||||
|
|
||||||
// Fetch Request
|
// Fetch Request
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failure : ", err)
|
fmt.Println("Failure : ", err)
|
||||||
}
|
|
||||||
|
|
||||||
// Read Response Body
|
|
||||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
|
|
||||||
// Display Results
|
|
||||||
fmt.Println("response Status : ", resp.Status)
|
|
||||||
fmt.Println("response Headers : ", resp.Header)
|
|
||||||
fmt.Println("response Body : ", string(respBody))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read Response Body
|
||||||
|
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
// Display Results
|
||||||
|
fmt.Println("response Status : ", resp.Status)
|
||||||
|
fmt.Println("response Headers : ", resp.Header)
|
||||||
|
fmt.Println("response Body : ", string(respBody))
|
||||||
|
/*}
|
||||||
|
}*/
|
||||||
|
|
||||||
// TODO: add code that deletes a record from the DNS provider's console
|
// TODO: add code that deletes a record from the DNS provider's console
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -293,8 +298,18 @@ func loadConfig(cfgJSON *extapi.JSON) (manituDNSProviderConfig, error) {
|
|||||||
|
|
||||||
func (c *manituDNSProviderSolver) getDomainAndEntry(ch *v1alpha1.ChallengeRequest) (string, string) {
|
func (c *manituDNSProviderSolver) getDomainAndEntry(ch *v1alpha1.ChallengeRequest) (string, string) {
|
||||||
// Both ch.ResolvedZone and ch.ResolvedFQDN end with a dot: '.'
|
// Both ch.ResolvedZone and ch.ResolvedFQDN end with a dot: '.'
|
||||||
entry := strings.TrimSuffix(ch.ResolvedFQDN, ch.ResolvedZone)
|
domain := util.UnFqdn(ch.ResolvedZone)
|
||||||
entry = strings.TrimSuffix(entry, ".")
|
entry := getSubDomain(domain, ch.ResolvedFQDN)
|
||||||
domain := strings.TrimSuffix(ch.ResolvedZone, ".")
|
fmt.Println("ResolvedFQDN : ", ch.ResolvedFQDN)
|
||||||
|
fmt.Println("ResolvedZone : ", ch.ResolvedZone)
|
||||||
|
fmt.Println("domain : ", domain)
|
||||||
|
fmt.Println("entry : ", entry)
|
||||||
return entry, domain
|
return entry, domain
|
||||||
}
|
}
|
||||||
|
func getSubDomain(domain, fqdn string) string {
|
||||||
|
if idx := strings.Index(fqdn, "."+domain); idx != -1 {
|
||||||
|
return fqdn[:idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.UnFqdn(fqdn)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user