Skip to content

Commit

Permalink
chore: more add to dns records
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed May 23, 2024
1 parent 0d11c08 commit ef756e4
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions dnsprovider/dnsprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ import (

// DNSRecord represents a DNS record in the API.
type DNSRecord struct {
ID string `json:"id,omitempty"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
ID string `json:"_id"`
Enabled bool `json:"enabled"`
Key string `json:"key"`
Port int `json:"port"`
Priority int `json:"priority"`
RecordType string `json:"record_type"`
TTL endpoint.TTL `json:"ttl"`
Value string `json:"value"`
Weight int `json:"weight"`
}

// Client is the DNS provider client.
Expand Down Expand Up @@ -186,9 +192,11 @@ func (p *DNSProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
var endpoints []*endpoint.Endpoint
for _, record := range records {
endpoints = append(endpoints, &endpoint.Endpoint{
DNSName: record.Hostname,
Targets: endpoint.Targets{record.IP},
RecordType: "A",
DNSName: record.Key,
Targets: []string{record.Value},
RecordType: record.RecordType,
SetIdentifier: record.ID,
RecordTTL: record.TTL,
})
}
return endpoints, nil
Expand All @@ -198,8 +206,11 @@ func (p *DNSProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
func (p *DNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
for _, ep := range changes.Create {
record := DNSRecord{
Hostname: ep.DNSName,
IP: ep.Targets[0],
ID: ep.SetIdentifier,
Key: ep.DNSName,
Value: ep.Targets[0],
RecordType: ep.RecordType,
TTL: ep.RecordTTL,
}
if _, err := p.client.CreateRecord(record); err != nil {
return err
Expand All @@ -208,8 +219,11 @@ func (p *DNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) e

for _, ep := range changes.UpdateNew {
record := DNSRecord{
Hostname: ep.DNSName,
IP: ep.Targets[0],
ID: ep.SetIdentifier,
Key: ep.DNSName,
Value: ep.Targets[0],
RecordType: ep.RecordType,
TTL: ep.RecordTTL,
}
// Assuming ID can be obtained from DNS name
id := ep.DNSName // This needs to be changed to actual ID fetching logic
Expand Down Expand Up @@ -244,4 +258,4 @@ func (p *DNSProvider) GetDomainFilter() endpoint.DomainFilter {
// GetDNSName returns the DNS provider's name.
func (p *DNSProvider) GetDNSName() string {
return "external-dns-unifi-webhook"
}
}

0 comments on commit ef756e4

Please sign in to comment.