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 provides information about API provider
Version(context.Context) (Version, error) Version(context.Context) (Version, error)
} }
// FullNode API is a low-level interface to the Filecoin network full node // 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 // Full API is a low-level interface to the Filecoin network storage miner node
type StorageMiner interface { type StorageMiner interface {
Common Common
} }

View File

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

View File

@ -27,11 +27,23 @@ func WithPerm(ctx context.Context, perms []string) context.Context {
return context.WithValue(ctx, permCtxKey, perms) return context.WithValue(ctx, permCtxKey, perms)
} }
func Permissioned(a FullNode) FullNode { func PermissionedStorMinerAPI(a StorageMiner) StorageMiner {
var out FullNodeStruct var out StorageMinerStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
return &out
}
rint := reflect.ValueOf(&out.Internal).Elem() func PermissionedFullAPI(a FullNode) FullNode {
ra := reflect.ValueOf(a) 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++ { for f := 0; f < rint.NumField(); f++ {
field := rint.Type().Field(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 var _ = AllPermissions
type CommonStruct struct { type CommonStruct struct {
Internal struct{ Internal struct {
AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"` AuthVerify func(ctx context.Context, token string) ([]string, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"` AuthNew func(ctx context.Context, perms []string) ([]byte, error) `perm:"admin"`
@ -61,8 +61,7 @@ type FullNodeStruct struct {
type StorageMinerStruct struct { type StorageMinerStruct struct {
CommonStruct CommonStruct
Internal struct{ Internal struct {
} }
} }

View File

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

View File

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