Skip to content

Commit

Permalink
Validating recordType to prevent other types of records from being ov…
Browse files Browse the repository at this point in the history
…erwritten
  • Loading branch information
Nícolas Castillo committed May 7, 2022
1 parent 803530e commit 45100ab
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,26 @@ func updateDNSRecord(fqdnArr []string, recordType string, ip string, checkMode b
}

for _, r := range records {
if r.Content == ip {
log.Printf("%s points to current IP address, no change is needed.", r.Name)
continue
}
log.Printf("%s points to %s, the record will be updated.", r.Name, r.Content)

if checkMode {
log.Println("Check mode is active, no changes will be made.")
} else {
log.Println("Setting", fqdn, "=>", ip, "...")
r.Content = ip
err := api.UpdateDNSRecord(context.Background(), zoneID, r.ID, r)
if err != nil {
log.Println(err)
updateErrors++
if r.Type == recordType {
if r.Content == ip {
log.Printf("%s points to current IP address, no change is needed.", r.Name)
continue
}
log.Printf("%s points to %s, the record will be updated.", r.Name, r.Content)

if checkMode {
log.Println("Check mode is active, no changes will be made.")
} else {
log.Println("Setting", fqdn, "=>", ip, "...")
r.Content = ip
err := api.UpdateDNSRecord(context.Background(), zoneID, r.ID, r)
if err != nil {
log.Println(err)
updateErrors++
}
log.Println("Success!")
}
log.Println("Success!")
}

}
}

Expand Down

0 comments on commit 45100ab

Please sign in to comment.