rind icon indicating copy to clipboard operation
rind copied to clipboard

How do you manually add rules?

Open xeoncross opened this issue 5 years ago • 4 comments

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)
}

xeoncross avatar Dec 10 '18 19:12 xeoncross

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

gcstang avatar Dec 11 '18 23:12 gcstang

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.

xeoncross avatar Dec 12 '18 01:12 xeoncross

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

owlwalks avatar Dec 12 '18 04:12 owlwalks

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?

xeoncross avatar Jan 10 '19 16:01 xeoncross