Add api endpoint to query the DNS cache database including the memory cache

This commit is contained in:
Daniel 2021-04-16 21:32:18 +02:00
parent ccefcd6b3b
commit 317962be5d

View file

@ -1,7 +1,10 @@
package resolver
import (
"net/http"
"github.com/safing/portbase/api"
"github.com/safing/portbase/database/record"
)
func registerAPI() error {
@ -25,6 +28,24 @@ func registerAPI() error {
return err
}
if err := api.RegisterEndpoint(api.Endpoint{
Path: `dns/cache`,
Read: api.PermitUser,
RecordFunc: func(r *api.Request) (record.Record, error) {
return recordDatabase.Get(nameRecordsKeyPrefix + r.URL.Query().Get("q"))
},
Name: "Get DNS Record from Cache",
Description: "Returns cached dns records from the internal cache.",
Parameters: []api.Parameter{{
Method: http.MethodGet,
Field: "q",
Value: "fqdn and query type",
Description: "Specify the query like this: `example.com.A`.",
}},
}); err != nil {
return err
}
return nil
}