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 82cd921
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 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 @@ -245,3 +259,31 @@ func (p *DNSProvider) GetDomainFilter() endpoint.DomainFilter {
func (p *DNSProvider) GetDNSName() string {
return "external-dns-unifi-webhook"
}


[
{
"dnsName": "test.outsideour.casa",
"targets": [
"1.1.1.1"
],
"recordType": "A",
"setIdentifier": "664fc203df28fb6a8bc4b7d9"
},
{
"dnsName": "new.outsideour.casa",
"targets": [
"test.outsideour.casa"
],
"recordType": "CNAME",
"setIdentifier": "664fc68cdf28fb6a8bc4b89e"
},
{
"dnsName": "test.outsideour.casa",
"targets": [
"1.1.1.2"
],
"recordType": "A",
"setIdentifier": "664fccc5df28fb6a8bc4b9de"
}
]

0 comments on commit 82cd921

Please sign in to comment.