mirror of
https://github.com/mudler/edgevpn.git
synced 2025-10-23 08:39:28 +08:00
⚙️ Add summary to client API
This commit is contained in:
14
api/api.go
14
api/api.go
@@ -86,10 +86,16 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
|
||||
|
||||
blockchain := ledger.Index()
|
||||
|
||||
return c.JSON(http.StatusOK, struct {
|
||||
Files, Machines, Users, Services, BlockChain, OnChainNodes, Peers int
|
||||
NodeID string
|
||||
}{files, machines, users, services, blockchain, onChainNodes, p2pPeers, nodeID})
|
||||
return c.JSON(http.StatusOK, types.Summary{
|
||||
Files: files,
|
||||
Machines: machines,
|
||||
Users: users,
|
||||
Services: services,
|
||||
BlockChain: blockchain,
|
||||
OnChainNodes: onChainNodes,
|
||||
Peers: p2pPeers,
|
||||
NodeID: nodeID,
|
||||
})
|
||||
})
|
||||
|
||||
ec.GET("/api/machines", func(c echo.Context) error {
|
||||
|
@@ -40,6 +40,7 @@ const (
|
||||
serviceURL = "/api/services"
|
||||
blockchainURL = "/api/blockchain"
|
||||
ledgerURL = "/api/ledger"
|
||||
summaryURL = "/api/summary"
|
||||
fileURL = "/api/files"
|
||||
)
|
||||
|
||||
@@ -157,6 +158,22 @@ func (c *Client) Ledger() (data map[string]map[string]blockchain.Data, err error
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) Summary() (data types.Summary, err error) {
|
||||
res, err := c.do(http.MethodGet, summaryURL, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
if err = json.Unmarshal(body, &data); err != nil {
|
||||
return data, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) Blockchain() (data blockchain.Block, err error) {
|
||||
res, err := c.do(http.MethodGet, blockchainURL, nil)
|
||||
if err != nil {
|
||||
|
@@ -52,6 +52,13 @@ var _ = Describe("Client", func() {
|
||||
testBucket = randStringBytes(10)
|
||||
})
|
||||
|
||||
It("Summary returns some info", func() {
|
||||
Eventually(func() string {
|
||||
s, _ := c.Summary()
|
||||
return s.NodeID
|
||||
}, 100*time.Second, 1*time.Second).ShouldNot(BeEmpty())
|
||||
})
|
||||
|
||||
It("Puts string data", func() {
|
||||
err := c.Put(testBucket, "foo", "bar")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@@ -35,7 +35,7 @@ A simple UI interface is available to display network data.`,
|
||||
&cli.StringFlag{
|
||||
Name: "listen",
|
||||
Value: ":8080",
|
||||
Usage: "Listening address",
|
||||
Usage: "Listening address. To listen to a socket, prefix with unix://, e.g. unix:///socket.path",
|
||||
},
|
||||
),
|
||||
Action: func(c *cli.Context) error {
|
||||
|
21
pkg/types/summary.go
Normal file
21
pkg/types/summary.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright © 2022 Ettore Di Giacinto <mudler@mocaccino.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package types
|
||||
|
||||
type Summary struct {
|
||||
Files, Machines, Users, Services, BlockChain, OnChainNodes, Peers int
|
||||
NodeID string
|
||||
}
|
Reference in New Issue
Block a user