mirror of https://github.com/status-im/go-waku.git
feat: add flags for enabling admin and private RPC methods
This commit is contained in:
parent
cc88d46773
commit
257847ebaa
12
waku.go
12
waku.go
|
@ -324,6 +324,18 @@ func main() {
|
|||
Usage: "Listening address of the rpc server",
|
||||
Destination: &options.RPCServer.Address,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "rpc-admin",
|
||||
Value: false,
|
||||
Usage: "Enable access to JSON-RPC Admin API",
|
||||
Destination: &options.RPCServer.Admin,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "rpc-private",
|
||||
Value: false,
|
||||
Usage: "Enable access to JSON-RPC Private API",
|
||||
Destination: &options.RPCServer.Private,
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
// for go-libp2p loggers
|
||||
|
|
|
@ -291,7 +291,7 @@ func Execute(options Options) {
|
|||
|
||||
var rpcServer *rpc.WakuRpc
|
||||
if options.RPCServer.Enable {
|
||||
rpcServer = rpc.NewWakuRpc(wakuNode, options.RPCServer.Address, options.RPCServer.Port, utils.Logger())
|
||||
rpcServer = rpc.NewWakuRpc(wakuNode, options.RPCServer.Address, options.RPCServer.Port, options.RPCServer.Admin, options.RPCServer.Private, utils.Logger())
|
||||
rpcServer.Start()
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ type RPCServerOptions struct {
|
|||
Enable bool
|
||||
Port int
|
||||
Address string
|
||||
Admin bool
|
||||
Private bool
|
||||
}
|
||||
|
||||
type WSOptions struct {
|
||||
|
|
|
@ -20,9 +20,10 @@ type WakuRpc struct {
|
|||
relayService *RelayService
|
||||
filterService *FilterService
|
||||
privateService *PrivateService
|
||||
adminService *AdminService
|
||||
}
|
||||
|
||||
func NewWakuRpc(node *node.WakuNode, address string, port int, log *zap.SugaredLogger) *WakuRpc {
|
||||
func NewWakuRpc(node *node.WakuNode, address string, port int, enableAdmin bool, enablePrivate bool, log *zap.SugaredLogger) *WakuRpc {
|
||||
wrpc := new(WakuRpc)
|
||||
wrpc.log = log.Named("rpc")
|
||||
|
||||
|
@ -46,9 +47,13 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, log *zap.SugaredL
|
|||
wrpc.log.Error(err)
|
||||
}
|
||||
|
||||
err = s.RegisterService(&AdminService{node, log.Named("admin")}, "Admin")
|
||||
if err != nil {
|
||||
wrpc.log.Error(err)
|
||||
if enableAdmin {
|
||||
adminService := &AdminService{node, log.Named("admin")}
|
||||
err = s.RegisterService(adminService, "Admin")
|
||||
if err != nil {
|
||||
wrpc.log.Error(err)
|
||||
}
|
||||
wrpc.adminService = adminService
|
||||
}
|
||||
|
||||
filterService := NewFilterService(node, log)
|
||||
|
@ -57,10 +62,13 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, log *zap.SugaredL
|
|||
wrpc.log.Error(err)
|
||||
}
|
||||
|
||||
privateService := NewPrivateService(node, log)
|
||||
err = s.RegisterService(privateService, "Private")
|
||||
if err != nil {
|
||||
wrpc.log.Error(err)
|
||||
if enablePrivate {
|
||||
privateService := NewPrivateService(node, log)
|
||||
err = s.RegisterService(privateService, "Private")
|
||||
if err != nil {
|
||||
wrpc.log.Error(err)
|
||||
}
|
||||
wrpc.privateService = privateService
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
@ -86,7 +94,6 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, log *zap.SugaredL
|
|||
wrpc.server = server
|
||||
wrpc.relayService = relayService
|
||||
wrpc.filterService = filterService
|
||||
wrpc.privateService = privateService
|
||||
|
||||
return wrpc
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestWakuRpc(t *testing.T) {
|
|||
n, err := node.New(context.Background(), options)
|
||||
require.NoError(t, err)
|
||||
|
||||
rpc := NewWakuRpc(n, "127.0.0.1", 8080, utils.Logger())
|
||||
rpc := NewWakuRpc(n, "127.0.0.1", 8080, true, true, utils.Logger())
|
||||
require.NotNil(t, rpc.server)
|
||||
require.Equal(t, rpc.server.Addr, "127.0.0.1:8080")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue