|
6 | 6 | "errors" |
7 | 7 | "fmt" |
8 | 8 | "strconv" |
9 | | - "strings" |
10 | 9 | "time" |
11 | 10 |
|
12 | 11 | "github.com/dnsimple/dnsimple-go/dnsimple" |
@@ -103,7 +102,11 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { |
103 | 102 | return fmt.Errorf("dnsimple: %w", err) |
104 | 103 | } |
105 | 104 |
|
106 | | - recordAttributes := newTxtRecord(zoneName, fqdn, value, d.config.TTL) |
| 105 | + recordAttributes, err := newTxtRecord(zoneName, fqdn, value, d.config.TTL) |
| 106 | + if err != nil { |
| 107 | + return fmt.Errorf("dnsimple: %w", err) |
| 108 | + } |
| 109 | + |
107 | 110 | _, err = d.client.Zones.CreateRecord(context.Background(), accountID, zoneName, recordAttributes) |
108 | 111 | if err != nil { |
109 | 112 | return fmt.Errorf("dnsimple: API call failed: %w", err) |
@@ -186,33 +189,31 @@ func (d *DNSProvider) findTxtRecords(fqdn string) ([]dnsimple.ZoneRecord, error) |
186 | 189 | return nil, err |
187 | 190 | } |
188 | 191 |
|
189 | | - recordName := extractRecordName(fqdn, zoneName) |
| 192 | + subDomain, err := dns01.ExtractSubDomain(fqdn, zoneName) |
| 193 | + if err != nil { |
| 194 | + return nil, err |
| 195 | + } |
190 | 196 |
|
191 | | - result, err := d.client.Zones.ListRecords(context.Background(), accountID, zoneName, &dnsimple.ZoneRecordListOptions{Name: &recordName, Type: dnsimple.String("TXT"), ListOptions: dnsimple.ListOptions{}}) |
| 197 | + result, err := d.client.Zones.ListRecords(context.Background(), accountID, zoneName, &dnsimple.ZoneRecordListOptions{Name: &subDomain, Type: dnsimple.String("TXT"), ListOptions: dnsimple.ListOptions{}}) |
192 | 198 | if err != nil { |
193 | 199 | return nil, fmt.Errorf("API call has failed: %w", err) |
194 | 200 | } |
195 | 201 |
|
196 | 202 | return result.Data, nil |
197 | 203 | } |
198 | 204 |
|
199 | | -func newTxtRecord(zoneName, fqdn, value string, ttl int) dnsimple.ZoneRecordAttributes { |
200 | | - name := extractRecordName(fqdn, zoneName) |
| 205 | +func newTxtRecord(zoneName, fqdn, value string, ttl int) (dnsimple.ZoneRecordAttributes, error) { |
| 206 | + subDomain, err := dns01.ExtractSubDomain(fqdn, zoneName) |
| 207 | + if err != nil { |
| 208 | + return dnsimple.ZoneRecordAttributes{}, err |
| 209 | + } |
201 | 210 |
|
202 | 211 | return dnsimple.ZoneRecordAttributes{ |
203 | 212 | Type: "TXT", |
204 | | - Name: &name, |
| 213 | + Name: &subDomain, |
205 | 214 | Content: value, |
206 | 215 | TTL: ttl, |
207 | | - } |
208 | | -} |
209 | | - |
210 | | -func extractRecordName(fqdn, zone string) string { |
211 | | - name := dns01.UnFqdn(fqdn) |
212 | | - if idx := strings.Index(name, "."+zone); idx != -1 { |
213 | | - return name[:idx] |
214 | | - } |
215 | | - return name |
| 216 | + }, nil |
216 | 217 | } |
217 | 218 |
|
218 | 219 | func (d *DNSProvider) getAccountID() (string, error) { |
|
0 commit comments