Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

How do you manually add rules? #5

Open
xeoncross opened this issue Dec 10, 2018 · 4 comments
Open

How do you manually add rules? #5

xeoncross opened this issue Dec 10, 2018 · 4 comments

Comments

@xeoncross
Copy link

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
Copy link

gcstang commented Dec 11, 2018

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

@xeoncross
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants