From 17a73452d433a4a20a091c28e2eccea431fc8a83 Mon Sep 17 00:00:00 2001 From: Yannik Lieblinger Date: Tue, 10 Oct 2023 17:02:47 +0200 Subject: [PATCH] [IMP] Hetzner: Compare ip on create --- internal/provider/providers/hetzner/create.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/provider/providers/hetzner/create.go b/internal/provider/providers/hetzner/create.go index 24d306b6b..f59d102be 100644 --- a/internal/provider/providers/hetzner/create.go +++ b/internal/provider/providers/hetzner/create.go @@ -69,12 +69,17 @@ func (p *Provider) createRecord(ctx context.Context, client *http.Client, ip net decoder := json.NewDecoder(response.Body) var parsedJSON struct { Record struct { - ID string `json:"id"` + ID string `json:"id"` + Value netip.Addr `json:"value"` } `json:"record"` } err = decoder.Decode(&parsedJSON) + newIP := parsedJSON.Record.Value if err != nil { return fmt.Errorf("json decoding response body: %w", err) + } else if newIP.Compare(ip) != 0 { + return fmt.Errorf("%w: sent ip %s to update but received %s", + errors.ErrIPReceivedMismatch, ip, newIP) } if parsedJSON.Record.ID == "" {