Fix: gcloud wildcard (#643)

* fix: gcloud wildcard.

* refactor: minor changes.
This commit is contained in:
Ludovic Fernandez 2018-09-21 17:28:50 +02:00 committed by Wyatt Johnson
parent ab0048544f
commit 3a46680b73
4 changed files with 22 additions and 12 deletions

View file

@ -593,7 +593,7 @@ func (c *Client) solveChallengeForAuthz(authorizations []authorization) error {
} }
} }
// for all valid presolvers, first submit the challenges so they have max time to propigate // for all valid presolvers, first submit the challenges so they have max time to propagate
for _, item := range authSolvers { for _, item := range authSolvers {
authz := item.authz authz := item.authz
i := item.challengeIndex i := item.challengeIndex

View file

@ -30,6 +30,9 @@ const (
// DefaultPollingInterval default polling interval // DefaultPollingInterval default polling interval
DefaultPollingInterval = 2 * time.Second DefaultPollingInterval = 2 * time.Second
// DefaultTTL default TTL
DefaultTTL = 120
) )
var defaultNameservers = []string{ var defaultNameservers = []string{
@ -67,7 +70,7 @@ func DNS01Record(domain, keyAuth string) (fqdn string, value string, ttl int) {
keyAuthShaBytes := sha256.Sum256([]byte(keyAuth)) keyAuthShaBytes := sha256.Sum256([]byte(keyAuth))
// base64URL encoding without padding // base64URL encoding without padding
value = base64.RawURLEncoding.EncodeToString(keyAuthShaBytes[:sha256.Size]) value = base64.RawURLEncoding.EncodeToString(keyAuthShaBytes[:sha256.Size])
ttl = 120 ttl = DefaultTTL
fqdn = fmt.Sprintf("_acme-challenge.%s.", domain) fqdn = fmt.Sprintf("_acme-challenge.%s.", domain)
return return
} }
@ -149,6 +152,7 @@ func checkDNSPropagation(fqdn, value string) (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
if r.Rcode == dns.RcodeSuccess { if r.Rcode == dns.RcodeSuccess {
// If we see a CNAME here then use the alias // If we see a CNAME here then use the alias
for _, rr := range r.Answer { for _, rr := range r.Answer {

View file

@ -131,26 +131,33 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("googlecloud: %v", err) return fmt.Errorf("googlecloud: %v", err)
} }
// Look for existing records.
existing, err := d.findTxtRecords(zone, fqdn)
if err != nil {
return fmt.Errorf("googlecloud: %v", err)
}
rec := &dns.ResourceRecordSet{ rec := &dns.ResourceRecordSet{
Name: fqdn, Name: fqdn,
Rrdatas: []string{value}, Rrdatas: []string{value},
Ttl: int64(d.config.TTL), Ttl: int64(d.config.TTL),
Type: "TXT", Type: "TXT",
} }
change := &dns.Change{
Additions: []*dns.ResourceRecordSet{rec},
}
// Look for existing records. change := &dns.Change{}
existing, err := d.findTxtRecords(zone, fqdn)
if err != nil {
return fmt.Errorf("googlecloud: %v", err)
}
if len(existing) > 0 { if len(existing) > 0 {
// Attempt to delete the existing records when adding our new one. // Attempt to delete the existing records when adding our new one.
change.Deletions = existing change.Deletions = existing
// Append existing TXT record data to the new TXT record data
for _, value := range existing {
rec.Rrdatas = append(rec.Rrdatas, value.Rrdatas...)
}
} }
change.Additions = []*dns.ResourceRecordSet{rec}
chg, err := d.client.Changes.Create(d.config.Project, zone, change).Do() chg, err := d.client.Changes.Create(d.config.Project, zone, change).Do()
if err != nil { if err != nil {
return fmt.Errorf("googlecloud: %v", err) return fmt.Errorf("googlecloud: %v", err)

View file

@ -5,11 +5,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/oauth2/google" "golang.org/x/oauth2/google"
"google.golang.org/api/dns/v1" "google.golang.org/api/dns/v1"
"github.com/stretchr/testify/assert"
) )
var ( var (