Fix permissions after split and rebase

This commit is contained in:
Łukasz Magiera 2019-07-24 03:10:26 +02:00
parent 772dd6c549
commit c6b4fadba1
7 changed files with 26 additions and 20 deletions

View File

@ -54,7 +54,6 @@ type Common interface {
// Version provides information about API provider
Version(context.Context) (Version, error)
}
// FullNode API is a low-level interface to the Filecoin network full node
@ -111,6 +110,4 @@ type FullNode interface {
// Full API is a low-level interface to the Filecoin network storage miner node
type StorageMiner interface {
Common
}

View File

@ -29,4 +29,4 @@ func NewStorageMinerRPC(addr string, requestHeader http.Header) (api.StorageMine
}, requestHeader)
return &res, err
}
}

View File

@ -27,11 +27,23 @@ func WithPerm(ctx context.Context, perms []string) context.Context {
return context.WithValue(ctx, permCtxKey, perms)
}
func Permissioned(a FullNode) FullNode {
var out FullNodeStruct
func PermissionedStorMinerAPI(a StorageMiner) StorageMiner {
var out StorageMinerStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
return &out
}
rint := reflect.ValueOf(&out.Internal).Elem()
ra := reflect.ValueOf(a)
func PermissionedFullAPI(a FullNode) FullNode {
var out FullNodeStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
return &out
}
func permissionedAny(in interface{}, out interface{}) {
rint := reflect.ValueOf(out).Elem()
ra := reflect.ValueOf(in)
for f := 0; f < rint.NumField(); f++ {
field := rint.Type().Field(f)
@ -81,6 +93,4 @@ func Permissioned(a FullNode) FullNode {
}))
}
return &out
}

View File

@ -15,7 +15,7 @@ import (
var _ = AllPermissions
type CommonStruct struct {
Internal struct{
Internal struct {
AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"`
@ -61,8 +61,7 @@ type FullNodeStruct struct {
type StorageMinerStruct struct {
CommonStruct
Internal struct{
Internal struct {
}
}

View File

@ -68,7 +68,7 @@ var runCmd = &cli.Command{
log.Infof("Remote version %s", v)
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", minerapi)
rpcServer.Register("Filecoin", api.PermissionedStorMinerAPI(minerapi))
http.Handle("/rpc/v0", rpcServer)
return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux)
},

View File

@ -7,9 +7,9 @@ import (
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
)
func serveRPC(api api.FullNode, addr string) error {
func serveRPC(a api.FullNode, addr string) error {
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", api)
rpcServer.Register("Filecoin", api.PermissionedFullAPI(a))
http.Handle("/rpc/v0", rpcServer)
return http.ListenAndServe(addr, http.DefaultServeMux)
}

View File

@ -22,10 +22,10 @@ type FullNodeAPI struct {
CommonAPI
Chain *chain.ChainStore
PubSub *pubsub.PubSub
Mpool *chain.MessagePool
Wallet *chain.Wallet
Chain *chain.ChainStore
PubSub *pubsub.PubSub
Mpool *chain.MessagePool
Wallet *chain.Wallet
}
func (a *FullNodeAPI) ChainSubmitBlock(ctx context.Context, blk *chain.BlockMsg) error {