mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-11 22:56:09 +08:00
[WIP] Update infomaniakProvider.go
This commit is contained in:
parent
540df588fe
commit
a616f2d283
1 changed files with 72 additions and 4 deletions
|
|
@ -3,8 +3,10 @@ package infomaniak
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||
)
|
||||
|
||||
|
|
@ -16,7 +18,14 @@ type infomaniakProvider struct {
|
|||
var features = providers.DocumentationNotes{
|
||||
// The default for unlisted capabilities is 'Cannot'.
|
||||
// See providers/capabilities.go for the entire list of capabilities.
|
||||
providers.CanGetZones: providers.Can(),
|
||||
providers.CanGetZones: providers.Can(),
|
||||
providers.CanUseCAA: providers.Can(),
|
||||
providers.CanUseDNAME: providers.Can(),
|
||||
providers.CanUseDS: providers.Can(),
|
||||
providers.CanUseSSHFP: providers.Can(),
|
||||
providers.CanUseTLSA: providers.Can(),
|
||||
providers.CanUseSRV: providers.Can(),
|
||||
providers.DocCreateDomains: providers.Can(),
|
||||
}
|
||||
|
||||
func newInfomaniak(m map[string]string, message json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||
|
|
@ -33,7 +42,8 @@ func init() {
|
|||
const providerName = "INFOMANIAK"
|
||||
const providerMaintainer = "@jbelien"
|
||||
fns := providers.DspFuncs{
|
||||
Initializer: newInfomaniak,
|
||||
Initializer: newInfomaniak,
|
||||
RecordAuditor: AuditRecords,
|
||||
}
|
||||
providers.RegisterDomainServiceProviderType(providerName, fns, features)
|
||||
providers.RegisterMaintainer(providerName, providerMaintainer)
|
||||
|
|
@ -49,9 +59,67 @@ func (p *infomaniakProvider) GetNameservers(domain string) ([]*models.Nameserver
|
|||
}
|
||||
|
||||
func (p *infomaniakProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
|
||||
panic("GetZoneRecords not implemented")
|
||||
records, err := p.getDNSRecords(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cleanRecords := make(models.Records, 0)
|
||||
|
||||
for _, r := range records {
|
||||
recConfig := &models.RecordConfig{
|
||||
Original: r,
|
||||
TTL: uint32(r.TTL),
|
||||
Type: r.Type,
|
||||
}
|
||||
recConfig.SetLabelFromFQDN(r.Source, domain)
|
||||
recConfig.SetTarget(r.Target)
|
||||
|
||||
cleanRecords = append(cleanRecords, recConfig)
|
||||
}
|
||||
|
||||
return cleanRecords, nil
|
||||
}
|
||||
|
||||
func (p *infomaniakProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, int, error) {
|
||||
panic("GetZoneRecordsCorrections not implemented")
|
||||
var corrections []*models.Correction
|
||||
|
||||
changes, actualChangeCount, err := diff2.ByRecord(existingRecords, dc, nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
for _, change := range changes {
|
||||
switch change.Type {
|
||||
case diff2.REPORT:
|
||||
corrections = append(corrections, &models.Correction{Msg: change.MsgsJoined})
|
||||
case diff2.CHANGE:
|
||||
fmt.Printf("CHANGE: %+v\n", change.New)
|
||||
// corrections = append(corrections, &models.Correction{
|
||||
// Msg: change.Msgs[0],
|
||||
// F: func() error {
|
||||
// return p.updateRecord(change.Old[0].Original.(dnsRecord), change.New[0], dc.Name)
|
||||
// },
|
||||
// })
|
||||
case diff2.CREATE:
|
||||
fmt.Printf("CREATE: %+v\n", change.New)
|
||||
// corrections = append(corrections, &models.Correction{
|
||||
// Msg: change.Msgs[0],
|
||||
// F: func() error {
|
||||
// _, err := p.createDNSRecord(dc.Name, change.New[0])
|
||||
// return err
|
||||
// },
|
||||
// })
|
||||
case diff2.DELETE:
|
||||
rec := change.Old[0].Original.(dnsRecord)
|
||||
corrections = append(corrections, &models.Correction{
|
||||
Msg: change.Msgs[0],
|
||||
F: func() error {
|
||||
return p.deleteDNSRecord(dc.Name, fmt.Sprintf("%v", rec.ID))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return corrections, actualChangeCount, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue