From 7347a79bd96a5803e49510e59e6f405b352a4856 Mon Sep 17 00:00:00 2001 From: Marton Pentek Date: Tue, 3 Jan 2023 13:56:14 +0100 Subject: [PATCH] fix cleanup bug --- client/client.go | 3 ++- client/client_test.go | 3 +-- main.go | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index 34805c8..b93d542 100644 --- a/client/client.go +++ b/client/client.go @@ -95,7 +95,8 @@ func (c *SimplyClient) AddTxtRecord(FQDNName string, Value string, credentials C // RemoveTxtRecord Remove TXT record from symply func (c *SimplyClient) RemoveTxtRecord(RecordId int, DnsName string, credentials Credentials) bool { - req, err := http.NewRequest("DELETE", apiUrl+"/my/products/"+DnsName+"/dns/records/"+strconv.Itoa(RecordId), nil) + dnsName := cutTrailingDotIfExist(DnsName) + req, err := http.NewRequest("DELETE", apiUrl+"/my/products/"+domainutil.Domain(dnsName)+"/dns/records/"+strconv.Itoa(RecordId), nil) req.SetBasicAuth(credentials.AccountName, credentials.ApiKey) client := &http.Client{} response, err := client.Do(req) diff --git a/client/client_test.go b/client/client_test.go index 13a9e77..ebb1b34 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -19,7 +19,6 @@ type testData struct { // Plot in your own api details for testing. func TestAll(t *testing.T) { data := testData{ //add your credentials here to test. - basedomain: "foo.com", domain: "_acme-challenge.foo.com", data: "test_txt_data", data2: "test_txt_data_2", @@ -71,7 +70,7 @@ func testRemove(t *testing.T, data testData, id int) { t.Fail() } - res := fixture.RemoveTxtRecord(id, data.basedomain, Credentials{ + res := fixture.RemoveTxtRecord(id, data.domain, Credentials{ AccountName: data.accountname, ApiKey: data.apikey, }) diff --git a/main.go b/main.go index b95cf90..e3db1f3 100644 --- a/main.go +++ b/main.go @@ -95,9 +95,12 @@ func (e *SimplyDnsSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { res := e.client.RemoveTxtRecord(id, ch.DNSName, cred) if res == true { fmt.Println("Record(", id, ") have been cleaned up.") + return nil + } else { + _ = fmt.Errorf("record(%d) have no tbeen cleaned up", id) return err } - return nil + } func (e *SimplyDnsSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error {