ipfs-cluster/rpcutil/policygen/policygen.go
Hector Sanjuan c5a2e7fdc5 RPC auth: Fix tests
I cannot have RPCAPIs expose a SvcID() method as gorpc will warn about it not
having the right signature. So I have created an RPCServiceID() method instead.
2019-05-09 16:33:59 +02:00

60 lines
1.3 KiB
Go

package main
import (
"fmt"
"reflect"
cluster "github.com/ipfs/ipfs-cluster"
)
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 := []interface{}{
&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()
fmt.Println("var RPCPolicy = map[string]RPCEndpointType{")
for _, c := range rpcComponents {
t := reflect.TypeOf(c)
fmt.Println(" //", cluster.RPCServiceID(c), "methods")
for i := 0; i < t.NumMethod(); i++ {
method := t.Method(i)
name := fmt.Sprintf("%s.%s", cluster.RPCServiceID(c), 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("}")
}