aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go27
-rw-r--r--httpd.go39
2 files changed, 66 insertions, 0 deletions
diff --git a/client.go b/client.go
index 53e057b..480fe53 100644
--- a/client.go
+++ b/client.go
@@ -33,6 +33,33 @@ func NewClient(serverUrl string, insecure bool) (cl *Client) {
return cl
}
+// Blockd return list of all block.d files on the server.
+func (cl *Client) Blockd() (hostBlockd map[string]*Blockd, err error) {
+ var (
+ logp = "Blockd"
+ res = libhttp.EndpointResponse{}
+
+ resb []byte
+ )
+
+ _, resb, err = cl.Get(apiBlockd, nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+
+ res.Data = &hostBlockd
+
+ err = json.Unmarshal(resb, &res)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+ if res.Code != http.StatusOK {
+ return nil, fmt.Errorf("%s: %d %s", logp, res.Code, res.Message)
+ }
+
+ return hostBlockd, nil
+}
+
// BlockdDisable disable specific hosts on block.d.
func (cl *Client) BlockdDisable(blockdName string) (an interface{}, err error) {
var (
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 (