VULTR: Implemented get-zones (#628) (#670)

This commit is contained in:
Patrick Gaskin 2020-02-29 09:04:00 -05:00 committed by GitHub
parent b7b0b20798
commit 6c316993ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 22 deletions

View file

@ -1002,8 +1002,8 @@
<td class="info">
<i class="fa fa-circle-o text-info" aria-hidden="true"></i>
</td>
<td class="info">
<i class="fa fa-circle-o text-info" aria-hidden="true"></i>
<td class="success">
<i class="fa fa-check text-success" aria-hidden="true"></i>
</td>
</tr>
</tbody>

View file

@ -59,7 +59,7 @@ func TestConversion(t *testing.T) {
}
for _, record := range records {
rc, err := toRecordConfig(dc, record)
rc, err := toRecordConfig(dc.Name, record)
if err != nil {
t.Error("Error converting Vultr record", record)
}

View file

@ -34,7 +34,7 @@ var features = providers.DocumentationNotes{
providers.CanUseSSHFP: providers.Can(),
providers.DocCreateDomains: providers.Can(),
providers.DocOfficiallySupported: providers.Cannot(),
providers.CanGetZones: providers.Unimplemented(),
providers.CanGetZones: providers.Can(),
}
func init() {
@ -68,31 +68,33 @@ func NewProvider(m map[string]string, metadata json.RawMessage) (providers.DNSSe
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (client *Provider) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented")
// This enables the get-zones subcommand.
// Implement this by extracting the code from GetDomainCorrections into
// a single function. For most providers this should be relatively easy.
func (api *Provider) GetZoneRecords(domain string) (models.Records, error) {
records, err := api.client.DNSRecord.List(context.Background(), domain)
if err != nil {
return nil, err
}
curRecords := make(models.Records, len(records))
for i := range records {
r, err := toRecordConfig(domain, &records[i])
if err != nil {
return nil, err
}
curRecords[i] = r
}
return curRecords, nil
}
// GetDomainCorrections gets the corrections for a DomainConfig.
func (api *Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
dc.Punycode()
records, err := api.client.DNSRecord.List(context.Background(), dc.Name)
curRecords, err := api.GetZoneRecords(dc.Name)
if err != nil {
return nil, err
}
curRecords := make([]*models.RecordConfig, len(records))
for i := range records {
r, err := toRecordConfig(dc, &records[i])
if err != nil {
return nil, err
}
curRecords[i] = r
}
models.PostProcessRecords(curRecords)
differ := diff.New(dc)
@ -164,13 +166,13 @@ func (api *Provider) isDomainInAccount(domain string) (bool, error) {
}
// toRecordConfig converts a Vultr DNSRecord to a RecordConfig. #rtype_variations
func toRecordConfig(dc *models.DomainConfig, r *govultr.DNSRecord) (*models.RecordConfig, error) {
origin, data := dc.Name, r.Data
func toRecordConfig(domain string, r *govultr.DNSRecord) (*models.RecordConfig, error) {
origin, data := domain, r.Data
rc := &models.RecordConfig{
TTL: uint32(r.TTL),
Original: r,
}
rc.SetLabel(r.Name, dc.Name)
rc.SetLabel(r.Name, domain)
switch rtype := r.Type; rtype {
case "CNAME", "NS":