Records update
This commit is contained in:
parent
97058d036d
commit
2ae93b6fd4
4 changed files with 136 additions and 191 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -105,8 +106,8 @@ func (dev *RouterosDevice) GetIdentity() (identity string, err error) { // {{{
|
|||
return
|
||||
} // }}}
|
||||
|
||||
func (dev *RouterosDevice) StaticDNSEntries() (entries []DNSRecord, err error) {
|
||||
entries = []DNSRecord{}
|
||||
func (dev *RouterosDevice) StaticDNSEntries() (entries []*DNSRecord, err error) {
|
||||
entries = []*DNSRecord{}
|
||||
|
||||
var body []byte
|
||||
body, err = dev.query("GET", "/ip/dns/static", []byte{})
|
||||
|
|
@ -119,6 +120,26 @@ func (dev *RouterosDevice) StaticDNSEntries() (entries []DNSRecord, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
entry.ParsedValue = entry.String()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
func (dev *RouterosDevice) UpdateDNSEntry(record DNSEntry) (err error) {
|
||||
req, _ := json.Marshal(record)
|
||||
|
||||
_, err = dev.query("PATCH", "/ip/dns/static/"+record.ID, req)
|
||||
if err != nil {
|
||||
rosError := struct{ Detail string }{}
|
||||
if jsonError := json.Unmarshal([]byte(err.Error()), &rosError); jsonError == nil {
|
||||
logger.Error("routeros", "error", jsonError)
|
||||
err = errors.New(rosError.Detail)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue