aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
diff options
context:
space:
mode:
Diffstat (limited to 'httpd.go')
-rw-r--r--httpd.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/httpd.go b/httpd.go
index 3f8964d..389bc1f 100644
--- a/httpd.go
+++ b/httpd.go
@@ -119,6 +119,17 @@ func (srv *Server) httpdRegisterEndpoints() (err error) {
}
err = srv.httpd.RegisterEndpoint(&libhttp.Endpoint{
+ Method: libhttp.RequestMethodGet,
+ Path: apiBlockd,
+ RequestType: libhttp.RequestTypeNone,
+ ResponseType: libhttp.ResponseTypeJSON,
+ Call: srv.httpApiBlockdList,
+ })
+ if err != nil {
+ return err
+ }
+
+ err = srv.httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
Path: apiBlockd,
RequestType: libhttp.RequestTypeJSON,
@@ -301,6 +312,34 @@ func (srv *Server) httpdRun() {
}
}
+// httpApiBlockdList fetch the list of block.d files.
+//
+// # Request
+//
+// GET /api/block.d
+//
+// # Response
+//
+// On success it will return list of hosts in block.d,
+//
+// {
+// "data": {
+// "<name>": <Blockd>
+// ...
+// }
+// }
+func (srv *Server) httpApiBlockdList(epr *libhttp.EndpointRequest) (resBody []byte, err error) {
+ var (
+ res = libhttp.EndpointResponse{}
+ )
+
+ res.Code = http.StatusOK
+ res.Data = srv.env.HostBlockd
+
+ resBody, err = json.Marshal(&res)
+ return resBody, err
+}
+
// httpApiBlockdDisable disable the hosts block.d.
func (srv *Server) httpApiBlockdDisable(epr *libhttp.EndpointRequest) (resBody []byte, err error) {
var (