RPC Auth: Add policygen.go: a tool to list all RPC endpoints.
This commit is contained in:
parent
26b0949b5e
commit
40fb0761da
66
rpcutil/policygen/policygen.go
Normal file
66
rpcutil/policygen/policygen.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
cluster "github.com/ipfs/ipfs-cluster"
|
||||
)
|
||||
|
||||
type svcIdComponent interface {
|
||||
SvcID() string
|
||||
}
|
||||
|
||||
func rpcTypeStr(t cluster.RPCEndpointType) string {
|
||||
switch t {
|
||||
case cluster.RPCClosed:
|
||||
return "RPCClosed"
|
||||
case cluster.RPCTrusted:
|
||||
return "RPCTrusted"
|
||||
case cluster.RPCOpen:
|
||||
return "RPCOpen"
|
||||
default:
|
||||
return "ERROR"
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
rpcComponents := []svcIdComponent{
|
||||
&cluster.ClusterRPCAPI{},
|
||||
&cluster.PinTrackerRPCAPI{},
|
||||
&cluster.IPFSConnectorRPCAPI{},
|
||||
&cluster.ConsensusRPCAPI{},
|
||||
&cluster.PeerMonitorRPCAPI{},
|
||||
}
|
||||
|
||||
fmt.Println(`
|
||||
// The below generated policy keeps the endpoint types
|
||||
// from the exiting one, marking new endpoints as NEW. Copy-paste this policy
|
||||
// into rpc_auth.go and set the NEW endpoints to their correct type.
|
||||
`)
|
||||
|
||||
fmt.Println("var RPCPolicy = map[string]RPCEndpointType{")
|
||||
|
||||
for _, c := range rpcComponents {
|
||||
t := reflect.TypeOf(c)
|
||||
|
||||
fmt.Println(" //", c.SvcID(), "methods")
|
||||
for i := 0; i < t.NumMethod(); i++ {
|
||||
method := t.Method(i)
|
||||
if method.Name == "SvcID" {
|
||||
continue
|
||||
}
|
||||
name := fmt.Sprintf("%s.%s", c.SvcID(), method.Name)
|
||||
rpcT, ok := cluster.DefaultRPCPolicy[name]
|
||||
rpcTStr := "NEW"
|
||||
if ok {
|
||||
rpcTStr = rpcTypeStr(rpcT)
|
||||
}
|
||||
|
||||
fmt.Printf(" \"%s\": %s,\n", name, rpcTStr)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
fmt.Println("}")
|
||||
}
|
Loading…
Reference in New Issue
Block a user