Update to libdns v1.1.0

This commit is contained in:
Alexandre Almeida 2025-06-01 15:14:24 +02:00
parent b7b0ab2cab
commit 75a18cd47f
7 changed files with 290 additions and 66 deletions

View file

@ -21,6 +21,7 @@ import (
"time"
"github.com/libdns/libdns"
"github.com/libdns/vultr"
)
@ -35,8 +36,18 @@ func main() {
fmt.Printf("ZONE not set\n")
return
}
provider := vultr.Provider{APIToken: token}
zones, err := provider.ListZones(context.TODO())
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
}
for _, zone := range zones {
fmt.Printf("%s\n", zone.Name)
}
records, err := provider.GetRecords(context.TODO(), zone)
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
@ -45,11 +56,16 @@ func main() {
testName := "libdns-test"
testId := ""
for _, record := range records {
fmt.Printf("%s (.%s): %s, %s\n", record.Name, zone, record.Value, record.Type)
if record.Name == testName {
testId = record.ID
fmt.Printf("%s (.%s): %s, %s\n", record.RR().Name, zone, record.RR().Data, record.RR().Type)
recordId, err := vultr.GetRecordID(record)
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
}
if record.RR().Name == testName {
testId = recordId
}
}
if testId != "" {
@ -62,23 +78,22 @@ func main() {
// }
// Set only works if we have a record.ID
fmt.Printf("Replacing entry for %s\n", testName)
_, err = provider.SetRecords(context.TODO(), zone, []libdns.Record{libdns.Record{
Type: "TXT",
Name: testName,
Value: fmt.Sprintf("\"Replacement test entry created by libdns %s\"", time.Now()),
TTL: time.Duration(30) * time.Second,
ID: testId,
_, err = provider.SetRecords(context.TODO(), zone, []libdns.Record{libdns.TXT{
Name: testName,
Text: fmt.Sprintf("Replacement test entry created by libdns %s", time.Now()),
TTL: time.Duration(30) * time.Second,
ProviderData: testId,
}})
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
}
} else {
fmt.Printf("Creating new entry for %s\n", testName)
_, err = provider.AppendRecords(context.TODO(), zone, []libdns.Record{libdns.Record{
Type: "TXT",
Name: testName,
Value: fmt.Sprintf("\"This is a test entry created by libdns %s\"", time.Now()),
TTL: time.Duration(30) * time.Second,
_, err = provider.AppendRecords(context.TODO(), zone, []libdns.Record{libdns.RR{
Type: "TXT",
Name: testName,
Data: fmt.Sprintf("This is a test entry created by libdns %s", time.Now()),
TTL: time.Duration(30) * time.Second,
}})
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())