acim / hcdns

Go client library for Hetzner DNS API.
Apache License 2.0
5 stars 2 forks source link

[Bug] Zones and Records have `nil` pointer instead of reference to client #2

Closed marvinruder closed 1 year ago

marvinruder commented 1 year ago

In https://github.com/acim/hcdns/blob/67aba980225b00175b4cb6ba824405bd797be6e2/client.go#L75 it is attempted to add client references to the zones by iterating over an array using the syntax for _, z := range zones and modifying the variable z. This has no effect on the underlying array since the range operator returns a copy of the element rather than a reference, as documented e.g. here.

The same issue occurs at https://github.com/acim/hcdns/blob/67aba980225b00175b4cb6ba824405bd797be6e2/zone.go#L101

An error nil pointer dereference occurs when attempting to use the client of a zone or record, e.g. by calling record.UpdateValue(…). It can easily be reproduced by inserting

    err = records[1].UpdateValue(ctx, "ns.example.com.")
    if err != nil {
        t.Fatal(err)
    }

after https://github.com/acim/hcdns/blob/67aba980225b00175b4cb6ba824405bd797be6e2/zone_test.go#L36

I will propose a fix shortly.