mirror of
https://codeberg.org/lauralani/ipam.git
synced 2024-11-23 20:20:39 +01:00
Merge pull request 'Fix DNS Zone matching for PowerDNS API integration' (#8) from bug-1 into main
Reviewed-on: https://codeberg.org/lauralani/ipam/pulls/8
This commit is contained in:
commit
34e4e6fc3e
3 changed files with 370 additions and 371 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -23,5 +23,6 @@ go.work
|
|||
# build output
|
||||
bin/
|
||||
|
||||
# vs code stuff
|
||||
# IDE stuff
|
||||
.vscode/
|
||||
.idea/
|
||||
|
|
|
@ -78,7 +78,7 @@ var ipaddCmd = &cobra.Command{
|
|||
fmt.Printf("added ip:\nip: %v\nhostname: %v\n", ipaddress, hostname)
|
||||
dnserr := AddDNSFqdn(hostname, ip)
|
||||
if dnserr != nil {
|
||||
fmt.Println("[ERROR]", writeerr)
|
||||
fmt.Println("[ERROR]", dnserr)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,11 +109,7 @@ func (z DNSZone) SendPATCH(record string, value string, recordtype string, chang
|
|||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, resperr := client.Do(req)
|
||||
if resperr != nil {
|
||||
return resperr
|
||||
}
|
||||
|
||||
resp, _ := client.Do(req)
|
||||
if resp.StatusCode != 204 {
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
@ -121,7 +117,7 @@ func (z DNSZone) SendPATCH(record string, value string, recordtype string, chang
|
|||
if readerr != nil {
|
||||
fmt.Println(readerr)
|
||||
}
|
||||
return errors.New("HTTP Error: " + resp.Status + "\n" + string(body))
|
||||
return fmt.Errorf("[HTTP ERROR] %v: %q", resp.Status, string(body))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -236,7 +232,7 @@ func GetBestDNSZone(fqdn string) (DNSZone, error) {
|
|||
var matchfound bool = false
|
||||
|
||||
for _, zone := range zones {
|
||||
if strings.HasSuffix(fqdn, zone.Name) {
|
||||
if strings.HasSuffix(fqdn, "."+zone.Name) {
|
||||
if !matchfound {
|
||||
matchfound = true
|
||||
bestmatch = zone
|
||||
|
@ -292,7 +288,9 @@ func AddDNSFqdn(fqdn string, addr netip.Addr) error {
|
|||
if frecordexists {
|
||||
fmt.Printf("[DNS] DNS Record for %v already exists, no need to change DNS.\n", fqdn)
|
||||
} else {
|
||||
fpatcherr := fzone.SendPATCH(strings.Replace(fqdn+".", "."+fzone.Name, "", 1), addr.String(), recordtype, "REPLACE")
|
||||
var dotfqdn, dotfzone string = fqdn + ".", "." + fzone.Name
|
||||
record := strings.Replace(dotfqdn, dotfzone, "", 1)
|
||||
fpatcherr := fzone.SendPATCH(record, addr.String(), recordtype, "REPLACE")
|
||||
if fpatcherr != nil {
|
||||
return fpatcherr
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue