Rewrite logic for libdns v1.0.0, do not use ProviderData field
This commit is contained in:
parent
b3121a879b
commit
62cb30921f
3 changed files with 89 additions and 194 deletions
|
|
@ -7,8 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/libdns/libdns"
|
||||
|
||||
"github.com/libdns/vultr"
|
||||
"github.com/libdns/vultr/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -22,6 +21,7 @@ func main() {
|
|||
fmt.Printf("ZONE not set\n")
|
||||
return
|
||||
}
|
||||
shouldCleanup := os.Getenv("DELETE_RECORDS") == "true"
|
||||
|
||||
provider := vultr.Provider{APIToken: token}
|
||||
|
||||
|
|
@ -44,42 +44,46 @@ func main() {
|
|||
for _, record := range records {
|
||||
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
|
||||
testId = record.(vultr.VultrRecord).ID
|
||||
}
|
||||
}
|
||||
|
||||
if testId != "" {
|
||||
// fmt.Printf("Delete entry for %s (id:%s)\n", testName, testId)
|
||||
// _, err = provider.DeleteRecords(context.TODO(), zone, []libdns.Record{libdns.Record{
|
||||
// ID: testId,
|
||||
// }})
|
||||
// if err != nil {
|
||||
// fmt.Printf("ERROR: %s\n", err.Error())
|
||||
// }
|
||||
// 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.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())
|
||||
if shouldCleanup {
|
||||
fmt.Printf("Delete entry for %s (id:%s)\n", testName, testId)
|
||||
_, err = provider.DeleteRecords(context.TODO(), zone, []libdns.Record{vultr.VultrRecord{
|
||||
ID: testId,
|
||||
}})
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
}
|
||||
} else {
|
||||
// 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{vultr.VultrRecord{
|
||||
Record: libdns.RR{
|
||||
Name: testName,
|
||||
Type: "TXT",
|
||||
Data: fmt.Sprintf("Replacement test entry created by libdns %s", time.Now()),
|
||||
TTL: time.Duration(90) * time.Second,
|
||||
},
|
||||
ID: 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.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,
|
||||
_, err = provider.AppendRecords(context.TODO(), zone, []libdns.Record{vultr.VultrRecord{
|
||||
Record: libdns.RR{
|
||||
Type: "TXT",
|
||||
Name: testName,
|
||||
Data: fmt.Sprintf("This is a test entry created by libdns %s", time.Now()),
|
||||
TTL: time.Duration(60) * time.Second,
|
||||
},
|
||||
ID: testId,
|
||||
}})
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue