1
0
Fork 0
mirror of https://gitlab.com/pnx-tools/dns-updater.git synced 2026-06-16 05:54:56 +02:00

dns/service/vultr/service.go: fix govultr bug

This commit is contained in:
Henrik Hautakoski 2025-10-15 12:12:02 +02:00
parent 555c553686
commit 4591f89f5f

View file

@ -13,6 +13,11 @@ import (
type Service struct {
api govultr.DomainRecordService
// HACK(domainreq): govultr does not set "omitempty" on the govultr.DomainRecordReq.Name field
// this makes the api call update the name of the record to a empty string.
// workaround is to keep a map of recordID's and their names so we can set it
// in Update()
names map[string]string
}
func New(token string) Service {
@ -22,7 +27,8 @@ func New(token string) Service {
client := govultr.NewClient(oauth2.NewClient(ctx, ts))
return Service{
api: client.DomainRecord,
api: client.DomainRecord,
names: map[string]string{},
}
}
@ -40,7 +46,7 @@ func Factory(args map[string]any) (any, error) {
return New(token), nil
}
func (p Service) List(domain_name string) (dns.RecordList, error) {
func (p *Service) List(domain_name string) (dns.RecordList, error) {
fetchedRecords, _, _, err := p.api.List(context.Background(), domain_name, nil)
if err != nil {
return nil, err
@ -53,6 +59,9 @@ func (p Service) List(domain_name string) (dns.RecordList, error) {
continue
}
// HACK(domainreq):
p.names[record.ID] = record.Name
records.Add(dns.Record{
Id: record.ID,
Name: record.Name,
@ -63,7 +72,14 @@ func (p Service) List(domain_name string) (dns.RecordList, error) {
}
func (p Service) Update(domain, recordID, ip string) error {
return p.api.Update(context.Background(), domain, recordID, &govultr.DomainRecordReq{
req := &govultr.DomainRecordReq{
Data: ip,
})
}
// HACK(domainreq):
if name, ok := p.names[recordID]; ok {
req.Name = name
}
return p.api.Update(context.Background(), domain, recordID, req)
}