owlwalks / rind

DNS server with REST interface for records management built on Golang
BSD 3-Clause "New" or "Revised" License
147 stars 48 forks source link

How do you manually add rules? #5

Open xeoncross opened 5 years ago

xeoncross commented 5 years ago

It looks like the library implementation for querying records is public - but saving is private. How can I start the server with some seed records without using a separate HTTP client to insert the rules via the HTTP/S interface?

var initialRules = []string{`{
    "Host": "_sip._tcp.example.com.",
    "TTL": 300,
    "Type": "SRV",
    "SRV": {
        "Priority": 0,
        "Weight": 5,
        "Port": 5060,
        "Target": "sipserver.example.com."
    }`}

dns := rind.Start("", []net.UDPAddr{{IP: net.IP{1, 1, 1, 1}, Port: 53}})

for _, rule := range initialRules {

    var req rind.Request
    if err := json.NewDecoder(rule).Decode(&req); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    resource, err := rind.toResource(req)
    if err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    dns.save(rind.ntString(resource.Header.Name, resource.Header.Type), resource, nil)
}
gcstang commented 5 years ago

you should be able to use curl and in doing so execute a bash script or similar to load it.

xeoncross commented 5 years ago

No reason to execute an external program. As I said, I could create an http.Request object, start an HTTP server, run the client requests, etc.. all within Go... but why?

If @owlwalks can just change the save() function to public we won't need workarounds.

owlwalks commented 5 years ago

Static rules will open whole range of parsing, I wouldn't suggest http.Request to start with, a text zone file is more of a favored practice:

example.com.  IN  A     192.0.2.1
xeoncross commented 5 years ago

The whole zone-file would be great, but can't we just make save() public for now so that I can add a few records?