From b968de3ef717237b042d3d3809b6650b95e06797 Mon Sep 17 00:00:00 2001 From: rdalverny Date: Mon, 26 Aug 2019 19:38:07 +0200 Subject: [PATCH] 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 --- providers/gandi/livedns.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/providers/gandi/livedns.go b/providers/gandi/livedns.go index 608741e84..97789d352 100644 --- a/providers/gandi/livedns.go +++ b/providers/gandi/livedns.go @@ -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 { + + 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) - for _, record := range dc.Records { - message += "\n" + record.GetTargetCombined() - } + message += "\n" + buf.String() return []*models.Correction{ { Msg: message,