GANDI-LIVE: Print actual changes to be pushed (#546)

* gandi/livedns: Print actual changes to be pushed

Currently, preview & push output prints all domain records values:

    $ dnscontrol preview
    ----- DNS Provider: gandi...1 correction
    #1: Setting dns records for example.com:
    mail.example.com.
    1.2.3.4
    "ga"
    "bu"
    "zo"

With this change, it would only show what changes from current state:

    $ dnscontrol preview
    ----- DNS Provider: gandi...1 correction
    #1: Setting dns records for example.com:
    CREATE TXT ga.example.com "ga" ttl=10800
    MODIFY TXT bu.example.com "bu" ttl=10800
    DELETE TXT meu.example.com "meu" ttl=10800

* Add import
This commit is contained in:
rdalverny 2019-08-26 19:38:07 +02:00 committed by Tom Limoncelli
parent 2ee086d41c
commit b968de3ef7

View file

@ -1,6 +1,7 @@
package gandi
import (
"bytes"
"encoding/json"
"fmt"
"strings"
@ -103,11 +104,26 @@ func (c *liveClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
differ := diff.New(dc)
_, create, del, mod := differ.IncrementalDiff(foundRecords)
if len(create)+len(del)+len(mod) > 0 {
message := fmt.Sprintf("Setting dns records for %s:", dc.Name)
for _, record := range dc.Records {
message += "\n" + record.GetTargetCombined()
buf := &bytes.Buffer{}
// Print a list of changes. Generate an actual change that is the zone
changes := false
for _, i := range create {
changes = true
fmt.Fprintln(buf, i)
}
for _, i := range del {
changes = true
fmt.Fprintln(buf, i)
}
for _, i := range mod {
changes = true
fmt.Fprintln(buf, i)
}
if changes {
message := fmt.Sprintf("Setting dns records for %s:", dc.Name)
message += "\n" + buf.String()
return []*models.Correction{
{
Msg: message,