Skip to content

Commit

Permalink
Remove existing records in gcloud (go-acme#308)
Browse files Browse the repository at this point in the history
When record already exists in gcloud we can't add a new record without removing the other one first. This is a simple fix that doesn't attempt to create multiple entries for the record but just removes the previous data.

fixes go-acme#218
  • Loading branch information
buckett authored and xenolf committed Nov 2, 2016
1 parent 85200a1 commit 501b7b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions providers/dns/googlecloud/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func (c *DNSProvider) Present(domain, token, keyAuth string) error {
Additions: []*dns.ResourceRecordSet{rec},
}

// Look for existing records.
list, err := c.client.ResourceRecordSets.List(c.project, zone).Name(fqdn).Type("TXT").Do()
if err != nil {
return err
}
if len(list.Rrsets) > 0 {
// Attempt to delete the existing records when adding our new one.
change.Deletions = list.Rrsets
}

chg, err := c.client.Changes.Create(c.project, zone, change).Do()
if err != nil {
return err
Expand Down
14 changes: 14 additions & 0 deletions providers/dns/googlecloud/googlecloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ func TestLiveGoogleCloudPresent(t *testing.T) {
assert.NoError(t, err)
}

func TestLiveGoogleCloudPresentMultiple(t *testing.T) {
if !gcloudLiveTest {
t.Skip("skipping live test")
}

provider, err := NewDNSProviderCredentials(gcloudProject)
assert.NoError(t, err)

// Check that we're able to create multiple entries
err = provider.Present(gcloudDomain, "1", "123d==")
err = provider.Present(gcloudDomain, "2", "123d==")
assert.NoError(t, err)
}

func TestLiveGoogleCloudCleanUp(t *testing.T) {
if !gcloudLiveTest {
t.Skip("skipping live test")
Expand Down

0 comments on commit 501b7b6

Please sign in to comment.