Merge apistruct with the api package
This commit is contained in:
parent
759ea5b14f
commit
7a23b411ae
6
Makefile
6
Makefile
@ -320,7 +320,7 @@ dist-clean:
|
||||
|
||||
type-gen:
|
||||
go run ./gen/main.go
|
||||
go generate ./...
|
||||
go generate -x ./...
|
||||
goimports -w api/
|
||||
|
||||
method-gen:
|
||||
@ -328,8 +328,8 @@ method-gen:
|
||||
|
||||
api-gen:
|
||||
go run ./gen/api
|
||||
goimports -w api/apistruct api/v0api
|
||||
goimports -w api/apistruct api/v0api
|
||||
goimports -w api
|
||||
goimports -w api
|
||||
.PHONY: api-gen
|
||||
|
||||
docsgen: docsgen-md docsgen-openrpc
|
||||
|
@ -113,3 +113,9 @@ func TestReturnTypes(t *testing.T) {
|
||||
t.Run("miner", tst(new(StorageMiner)))
|
||||
t.Run("worker", tst(new(Worker)))
|
||||
}
|
||||
|
||||
func TestPermTags(t *testing.T) {
|
||||
_ = PermissionedFullAPI(&FullNodeStruct{})
|
||||
_ = PermissionedStorMinerAPI(&StorageMinerStruct{})
|
||||
_ = PermissionedWorkerAPI(&WorkerStruct{})
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
package apistruct
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPermTags(t *testing.T) {
|
||||
_ = PermissionedFullAPI(&FullNodeStruct{})
|
||||
_ = PermissionedStorMinerAPI(&StorageMinerStruct{})
|
||||
_ = PermissionedWorkerAPI(&WorkerStruct{})
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package apistruct
|
||||
|
||||
import "github.com/filecoin-project/lotus/api"
|
||||
|
||||
type ChainIO = api.ChainIO
|
||||
type Common = api.Common
|
||||
type FullNode = api.FullNode
|
||||
type Gateway = api.Gateway
|
||||
type Signable = api.Signable
|
||||
type StorageMiner = api.StorageMiner
|
||||
type Wallet = api.Wallet
|
||||
type Worker = api.Worker
|
@ -10,7 +10,6 @@ import (
|
||||
"github.com/filecoin-project/go-jsonrpc"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/api/v0api"
|
||||
"github.com/filecoin-project/lotus/api/v1api"
|
||||
"github.com/filecoin-project/lotus/lib/rpcenc"
|
||||
@ -71,7 +70,7 @@ func NewWorkerRPC(ctx context.Context, addr string, requestHeader http.Header) (
|
||||
|
||||
u.Path = path.Join(u.Path, "../streams/v0/push")
|
||||
|
||||
var res apistruct.WorkerStruct
|
||||
var res api.WorkerStruct
|
||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||
[]interface{}{
|
||||
&res.Internal,
|
||||
@ -87,7 +86,7 @@ func NewWorkerRPC(ctx context.Context, addr string, requestHeader http.Header) (
|
||||
|
||||
// NewGatewayRPC creates a new http jsonrpc client for a gateway node.
|
||||
func NewGatewayRPC(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) {
|
||||
var res apistruct.GatewayStruct
|
||||
var res api.GatewayStruct
|
||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||
[]interface{}{
|
||||
&res.Internal,
|
||||
@ -100,7 +99,7 @@ func NewGatewayRPC(ctx context.Context, addr string, requestHeader http.Header,
|
||||
}
|
||||
|
||||
func NewWalletRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Wallet, jsonrpc.ClientCloser, error) {
|
||||
var res apistruct.WalletStruct
|
||||
var res api.WalletStruct
|
||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||
[]interface{}{
|
||||
&res.Internal,
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/api/docgen"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
docgen_openrpc "github.com/filecoin-project/lotus/api/docgen-openrpc"
|
||||
)
|
||||
|
||||
@ -35,14 +34,8 @@ func main() {
|
||||
|
||||
doc := docgen_openrpc.NewLotusOpenRPCDocument(Comments, GroupDocs)
|
||||
|
||||
switch os.Args[2] {
|
||||
case "FullNode":
|
||||
doc.RegisterReceiverName("Filecoin", &apistruct.FullNodeStruct{})
|
||||
case "StorageMiner":
|
||||
doc.RegisterReceiverName("Filecoin", &apistruct.StorageMinerStruct{})
|
||||
case "Worker":
|
||||
doc.RegisterReceiverName("Filecoin", &apistruct.WorkerStruct{})
|
||||
}
|
||||
i, _, _, _ := docgen.GetAPIType(os.Args[2], os.Args[3])
|
||||
doc.RegisterReceiverName("Filecoin", i)
|
||||
|
||||
out, err := doc.Discover()
|
||||
if err != nil {
|
||||
|
@ -4,12 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/api/docgen"
|
||||
)
|
||||
|
||||
@ -18,25 +15,7 @@ func main() {
|
||||
|
||||
groups := make(map[string]*docgen.MethodGroup)
|
||||
|
||||
var t reflect.Type
|
||||
var permStruct, commonPermStruct reflect.Type
|
||||
|
||||
switch os.Args[2] {
|
||||
case "FullNode":
|
||||
t = reflect.TypeOf(new(struct{ api.FullNode })).Elem()
|
||||
permStruct = reflect.TypeOf(apistruct.FullNodeStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(apistruct.CommonStruct{}.Internal)
|
||||
case "StorageMiner":
|
||||
t = reflect.TypeOf(new(struct{ api.StorageMiner })).Elem()
|
||||
permStruct = reflect.TypeOf(apistruct.StorageMinerStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(apistruct.CommonStruct{}.Internal)
|
||||
case "Worker":
|
||||
t = reflect.TypeOf(new(struct{ api.Worker })).Elem()
|
||||
permStruct = reflect.TypeOf(apistruct.WorkerStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(apistruct.WorkerStruct{}.Internal)
|
||||
default:
|
||||
panic("unknown type")
|
||||
}
|
||||
_, t, permStruct, commonPermStruct := docgen.GetAPIType(os.Args[2], os.Args[3])
|
||||
|
||||
for i := 0; i < t.NumMethod(); i++ {
|
||||
m := t.Method(i)
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/filecoin-project/lotus/api/v0api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
||||
@ -262,6 +263,42 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func GetAPIType(name, pkg string) (i interface{}, t, permStruct, commonPermStruct reflect.Type) {
|
||||
switch pkg {
|
||||
case "api": // latest
|
||||
switch name {
|
||||
case "FullNode":
|
||||
i = &api.FullNodeStruct{}
|
||||
t = reflect.TypeOf(new(struct{ api.FullNode })).Elem()
|
||||
permStruct = reflect.TypeOf(api.FullNodeStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(api.CommonStruct{}.Internal)
|
||||
case "StorageMiner":
|
||||
i = &api.StorageMinerStruct{}
|
||||
t = reflect.TypeOf(new(struct{ api.StorageMiner })).Elem()
|
||||
permStruct = reflect.TypeOf(api.StorageMinerStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(api.CommonStruct{}.Internal)
|
||||
case "Worker":
|
||||
i = &api.WorkerStruct{}
|
||||
t = reflect.TypeOf(new(struct{ api.Worker })).Elem()
|
||||
permStruct = reflect.TypeOf(api.WorkerStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(api.WorkerStruct{}.Internal)
|
||||
default:
|
||||
panic("unknown type")
|
||||
}
|
||||
case "v0api":
|
||||
switch name {
|
||||
case "FullNode":
|
||||
i = v0api.FullNodeStruct{}
|
||||
t = reflect.TypeOf(new(struct{ v0api.FullNode })).Elem()
|
||||
permStruct = reflect.TypeOf(v0api.FullNodeStruct{}.Internal)
|
||||
commonPermStruct = reflect.TypeOf(v0api.CommonStruct{}.Internal)
|
||||
default:
|
||||
panic("unknown type")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ExampleValue(method string, t, parent reflect.Type) interface{} {
|
||||
v, ok := ExampleValues[t]
|
||||
if ok {
|
||||
|
@ -1,8 +1,7 @@
|
||||
package apistruct
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -17,27 +16,27 @@ const (
|
||||
var AllPermissions = []auth.Permission{PermRead, PermWrite, PermSign, PermAdmin}
|
||||
var DefaultPerms = []auth.Permission{PermRead}
|
||||
|
||||
func PermissionedStorMinerAPI(a api.StorageMiner) api.StorageMiner {
|
||||
func PermissionedStorMinerAPI(a StorageMiner) StorageMiner {
|
||||
var out StorageMinerStruct
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.CommonStruct.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func PermissionedFullAPI(a api.FullNode) api.FullNode {
|
||||
func PermissionedFullAPI(a FullNode) FullNode {
|
||||
var out FullNodeStruct
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.CommonStruct.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func PermissionedWorkerAPI(a api.Worker) api.Worker {
|
||||
func PermissionedWorkerAPI(a Worker) Worker {
|
||||
var out WorkerStruct
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func PermissionedWalletAPI(a api.Wallet) api.Wallet {
|
||||
func PermissionedWalletAPI(a Wallet) Wallet {
|
||||
var out WalletStruct
|
||||
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
|
||||
return &out
|
File diff suppressed because it is too large
Load Diff
@ -1,77 +0,0 @@
|
||||
package v0api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
)
|
||||
|
||||
type Common interface {
|
||||
|
||||
// MethodGroup: Auth
|
||||
|
||||
AuthVerify(ctx context.Context, token string) ([]auth.Permission, error) //perm:read
|
||||
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error) //perm:admin
|
||||
|
||||
// MethodGroup: Net
|
||||
|
||||
NetConnectedness(context.Context, peer.ID) (network.Connectedness, error) //perm:read
|
||||
NetPeers(context.Context) ([]peer.AddrInfo, error) //perm:read
|
||||
NetConnect(context.Context, peer.AddrInfo) error //perm:write
|
||||
NetAddrsListen(context.Context) (peer.AddrInfo, error) //perm:read
|
||||
NetDisconnect(context.Context, peer.ID) error //perm:write
|
||||
NetFindPeer(context.Context, peer.ID) (peer.AddrInfo, error) //perm:read
|
||||
NetPubsubScores(context.Context) ([]api.PubsubScore, error) //perm:read
|
||||
NetAutoNatStatus(context.Context) (api.NatInfo, error) //perm:read
|
||||
NetAgentVersion(ctx context.Context, p peer.ID) (string, error) //perm:read
|
||||
NetPeerInfo(context.Context, peer.ID) (*api.ExtendedPeerInfo, error) //perm:read
|
||||
|
||||
// NetBandwidthStats returns statistics about the nodes total bandwidth
|
||||
// usage and current rate across all peers and protocols.
|
||||
NetBandwidthStats(ctx context.Context) (metrics.Stats, error) //perm:read
|
||||
|
||||
// NetBandwidthStatsByPeer returns statistics about the nodes bandwidth
|
||||
// usage and current rate per peer
|
||||
NetBandwidthStatsByPeer(ctx context.Context) (map[string]metrics.Stats, error) //perm:read
|
||||
|
||||
// NetBandwidthStatsByProtocol returns statistics about the nodes bandwidth
|
||||
// usage and current rate per protocol
|
||||
NetBandwidthStatsByProtocol(ctx context.Context) (map[protocol.ID]metrics.Stats, error) //perm:read
|
||||
|
||||
// ConnectionGater API
|
||||
NetBlockAdd(ctx context.Context, acl api.NetBlockList) error //perm:admin
|
||||
NetBlockRemove(ctx context.Context, acl api.NetBlockList) error //perm:admin
|
||||
NetBlockList(ctx context.Context) (api.NetBlockList, error) //perm:read
|
||||
|
||||
// MethodGroup: Common
|
||||
|
||||
// Discover returns an OpenRPC document describing an RPC API.
|
||||
Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) //perm:read
|
||||
|
||||
// ID returns peerID of libp2p node backing this API
|
||||
ID(context.Context) (peer.ID, error) //perm:read
|
||||
|
||||
// Version provides information about API provider
|
||||
Version(context.Context) (api.APIVersion, error) //perm:read
|
||||
|
||||
LogList(context.Context) ([]string, error) //perm:write
|
||||
LogSetLevel(context.Context, string, string) error //perm:write
|
||||
|
||||
// trigger graceful shutdown
|
||||
Shutdown(context.Context) error //perm:admin
|
||||
|
||||
// Session returns a random UUID of api provider session
|
||||
Session(context.Context) (uuid.UUID, error) //perm:read
|
||||
|
||||
Closing(context.Context) (<-chan struct{}, error) //perm:read
|
||||
}
|
24
api/v0api/latest.go
Normal file
24
api/v0api/latest.go
Normal file
@ -0,0 +1,24 @@
|
||||
package v0api
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
type Common = api.Common
|
||||
type CommonStruct = api.CommonStruct
|
||||
|
||||
type Gateway = api.Gateway
|
||||
|
||||
type StorageMiner = api.StorageMiner
|
||||
type StorageMinerStruct = api.StorageMinerStruct
|
||||
|
||||
type Worker = api.Worker
|
||||
type WorkerStruct = api.WorkerStruct
|
||||
|
||||
func PermissionedStorMinerAPI(a StorageMiner) StorageMiner {
|
||||
return api.PermissionedStorMinerAPI(a)
|
||||
}
|
||||
|
||||
func PermissionedWorkerAPI(a Worker) Worker {
|
||||
return api.PermissionedWorkerAPI(a)
|
||||
}
|
13
api/v0api/permissioned.go
Normal file
13
api/v0api/permissioned.go
Normal file
@ -0,0 +1,13 @@
|
||||
package v0api
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
)
|
||||
|
||||
func PermissionedFullAPI(a FullNode) FullNode {
|
||||
var out FullNodeStruct
|
||||
auth.PermissionedProxy(api.AllPermissions, api.DefaultPerms, a, &out.Internal)
|
||||
auth.PermissionedProxy(api.AllPermissions, api.DefaultPerms, a, &out.CommonStruct.Internal)
|
||||
return &out
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package v0api
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
)
|
||||
|
||||
type StorageMiner = api.StorageMiner
|
||||
type StorageMinerStruct = apistruct.StorageMinerStruct
|
@ -9,7 +9,6 @@ import (
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
"github.com/filecoin-project/go-multistore"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
@ -21,70 +20,10 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/google/uuid"
|
||||
"github.com/ipfs/go-cid"
|
||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
)
|
||||
|
||||
type CommonStruct struct {
|
||||
Internal struct {
|
||||
AuthNew func(p0 context.Context, p1 []auth.Permission) ([]byte, error) `perm:"admin"`
|
||||
|
||||
AuthVerify func(p0 context.Context, p1 string) ([]auth.Permission, error) `perm:"read"`
|
||||
|
||||
Closing func(p0 context.Context) (<-chan struct{}, error) `perm:"read"`
|
||||
|
||||
Discover func(p0 context.Context) (apitypes.OpenRPCDocument, error) `perm:"read"`
|
||||
|
||||
ID func(p0 context.Context) (peer.ID, error) `perm:"read"`
|
||||
|
||||
LogList func(p0 context.Context) ([]string, error) `perm:"write"`
|
||||
|
||||
LogSetLevel func(p0 context.Context, p1 string, p2 string) error `perm:"write"`
|
||||
|
||||
NetAddrsListen func(p0 context.Context) (peer.AddrInfo, error) `perm:"read"`
|
||||
|
||||
NetAgentVersion func(p0 context.Context, p1 peer.ID) (string, error) `perm:"read"`
|
||||
|
||||
NetAutoNatStatus func(p0 context.Context) (api.NatInfo, error) `perm:"read"`
|
||||
|
||||
NetBandwidthStats func(p0 context.Context) (metrics.Stats, error) `perm:"read"`
|
||||
|
||||
NetBandwidthStatsByPeer func(p0 context.Context) (map[string]metrics.Stats, error) `perm:"read"`
|
||||
|
||||
NetBandwidthStatsByProtocol func(p0 context.Context) (map[protocol.ID]metrics.Stats, error) `perm:"read"`
|
||||
|
||||
NetBlockAdd func(p0 context.Context, p1 api.NetBlockList) error `perm:"admin"`
|
||||
|
||||
NetBlockList func(p0 context.Context) (api.NetBlockList, error) `perm:"read"`
|
||||
|
||||
NetBlockRemove func(p0 context.Context, p1 api.NetBlockList) error `perm:"admin"`
|
||||
|
||||
NetConnect func(p0 context.Context, p1 peer.AddrInfo) error `perm:"write"`
|
||||
|
||||
NetConnectedness func(p0 context.Context, p1 peer.ID) (network.Connectedness, error) `perm:"read"`
|
||||
|
||||
NetDisconnect func(p0 context.Context, p1 peer.ID) error `perm:"write"`
|
||||
|
||||
NetFindPeer func(p0 context.Context, p1 peer.ID) (peer.AddrInfo, error) `perm:"read"`
|
||||
|
||||
NetPeerInfo func(p0 context.Context, p1 peer.ID) (*api.ExtendedPeerInfo, error) `perm:"read"`
|
||||
|
||||
NetPeers func(p0 context.Context) ([]peer.AddrInfo, error) `perm:"read"`
|
||||
|
||||
NetPubsubScores func(p0 context.Context) ([]api.PubsubScore, error) `perm:"read"`
|
||||
|
||||
Session func(p0 context.Context) (uuid.UUID, error) `perm:"read"`
|
||||
|
||||
Shutdown func(p0 context.Context) error `perm:"admin"`
|
||||
|
||||
Version func(p0 context.Context) (api.APIVersion, error) `perm:"read"`
|
||||
}
|
||||
}
|
||||
|
||||
type FullNodeStruct struct {
|
||||
CommonStruct
|
||||
|
||||
@ -435,110 +374,6 @@ type FullNodeStruct struct {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CommonStruct) AuthNew(p0 context.Context, p1 []auth.Permission) ([]byte, error) {
|
||||
return s.Internal.AuthNew(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) AuthVerify(p0 context.Context, p1 string) ([]auth.Permission, error) {
|
||||
return s.Internal.AuthVerify(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) Closing(p0 context.Context) (<-chan struct{}, error) {
|
||||
return s.Internal.Closing(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) Discover(p0 context.Context) (apitypes.OpenRPCDocument, error) {
|
||||
return s.Internal.Discover(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) ID(p0 context.Context) (peer.ID, error) {
|
||||
return s.Internal.ID(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) LogList(p0 context.Context) ([]string, error) {
|
||||
return s.Internal.LogList(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) LogSetLevel(p0 context.Context, p1 string, p2 string) error {
|
||||
return s.Internal.LogSetLevel(p0, p1, p2)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetAddrsListen(p0 context.Context) (peer.AddrInfo, error) {
|
||||
return s.Internal.NetAddrsListen(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetAgentVersion(p0 context.Context, p1 peer.ID) (string, error) {
|
||||
return s.Internal.NetAgentVersion(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetAutoNatStatus(p0 context.Context) (api.NatInfo, error) {
|
||||
return s.Internal.NetAutoNatStatus(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBandwidthStats(p0 context.Context) (metrics.Stats, error) {
|
||||
return s.Internal.NetBandwidthStats(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBandwidthStatsByPeer(p0 context.Context) (map[string]metrics.Stats, error) {
|
||||
return s.Internal.NetBandwidthStatsByPeer(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBandwidthStatsByProtocol(p0 context.Context) (map[protocol.ID]metrics.Stats, error) {
|
||||
return s.Internal.NetBandwidthStatsByProtocol(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBlockAdd(p0 context.Context, p1 api.NetBlockList) error {
|
||||
return s.Internal.NetBlockAdd(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBlockList(p0 context.Context) (api.NetBlockList, error) {
|
||||
return s.Internal.NetBlockList(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetBlockRemove(p0 context.Context, p1 api.NetBlockList) error {
|
||||
return s.Internal.NetBlockRemove(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetConnect(p0 context.Context, p1 peer.AddrInfo) error {
|
||||
return s.Internal.NetConnect(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetConnectedness(p0 context.Context, p1 peer.ID) (network.Connectedness, error) {
|
||||
return s.Internal.NetConnectedness(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetDisconnect(p0 context.Context, p1 peer.ID) error {
|
||||
return s.Internal.NetDisconnect(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetFindPeer(p0 context.Context, p1 peer.ID) (peer.AddrInfo, error) {
|
||||
return s.Internal.NetFindPeer(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetPeerInfo(p0 context.Context, p1 peer.ID) (*api.ExtendedPeerInfo, error) {
|
||||
return s.Internal.NetPeerInfo(p0, p1)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetPeers(p0 context.Context) ([]peer.AddrInfo, error) {
|
||||
return s.Internal.NetPeers(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) NetPubsubScores(p0 context.Context) ([]api.PubsubScore, error) {
|
||||
return s.Internal.NetPubsubScores(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) Session(p0 context.Context) (uuid.UUID, error) {
|
||||
return s.Internal.Session(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) Shutdown(p0 context.Context) error {
|
||||
return s.Internal.Shutdown(p0)
|
||||
}
|
||||
|
||||
func (s *CommonStruct) Version(p0 context.Context) (api.APIVersion, error) {
|
||||
return s.Internal.Version(p0)
|
||||
}
|
||||
|
||||
func (s *FullNodeStruct) BeaconGetEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) {
|
||||
return s.Internal.BeaconGetEntry(p0, p1)
|
||||
}
|
||||
@ -1227,5 +1062,4 @@ func (s *FullNodeStruct) WalletVerify(p0 context.Context, p1 address.Address, p2
|
||||
return s.Internal.WalletVerify(p0, p1, p2, p3)
|
||||
}
|
||||
|
||||
var _ Common = new(CommonStruct)
|
||||
var _ FullNode = new(FullNodeStruct)
|
||||
|
@ -2,8 +2,11 @@ package v1api
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
)
|
||||
|
||||
type FullNode = api.FullNode
|
||||
type FullNodeStruct = apistruct.FullNodeStruct
|
||||
type FullNodeStruct = api.FullNodeStruct
|
||||
|
||||
func PermissionedFullAPI(a FullNode) FullNode {
|
||||
return api.PermissionedFullAPI(a)
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
14
cli/auth.go
14
cli/auth.go
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
)
|
||||
@ -47,18 +47,18 @@ var AuthCreateAdminToken = &cli.Command{
|
||||
|
||||
perm := cctx.String("perm")
|
||||
idx := 0
|
||||
for i, p := range apistruct.AllPermissions {
|
||||
for i, p := range api.AllPermissions {
|
||||
if auth.Permission(perm) == p {
|
||||
idx = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
if idx == 0 {
|
||||
return fmt.Errorf("--perm flag has to be one of: %s", apistruct.AllPermissions)
|
||||
return fmt.Errorf("--perm flag has to be one of: %s", api.AllPermissions)
|
||||
}
|
||||
|
||||
// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
|
||||
token, err := napi.AuthNew(ctx, apistruct.AllPermissions[:idx])
|
||||
token, err := napi.AuthNew(ctx, api.AllPermissions[:idx])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -95,18 +95,18 @@ var AuthApiInfoToken = &cli.Command{
|
||||
|
||||
perm := cctx.String("perm")
|
||||
idx := 0
|
||||
for i, p := range apistruct.AllPermissions {
|
||||
for i, p := range api.AllPermissions {
|
||||
if auth.Permission(perm) == p {
|
||||
idx = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
if idx == 0 {
|
||||
return fmt.Errorf("--perm flag has to be one of: %s", apistruct.AllPermissions)
|
||||
return fmt.Errorf("--perm flag has to be one of: %s", api.AllPermissions)
|
||||
}
|
||||
|
||||
// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
|
||||
token, err := napi.AuthNew(ctx, apistruct.AllPermissions[:idx])
|
||||
token, err := napi.AuthNew(ctx, api.AllPermissions[:idx])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import (
|
||||
"github.com/filecoin-project/go-statestore"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
lcli "github.com/filecoin-project/lotus/cli"
|
||||
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||
@ -366,7 +365,7 @@ var runCmd = &cli.Command{
|
||||
|
||||
fh := &stores.FetchHandler{Local: localStore}
|
||||
remoteHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
if !auth.HasPerm(r.Context(), nil, apistruct.PermAdmin) {
|
||||
if !auth.HasPerm(r.Context(), nil, api.PermAdmin) {
|
||||
w.WriteHeader(401)
|
||||
_ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing admin permission"})
|
||||
return
|
||||
@ -394,7 +393,7 @@ var runCmd = &cli.Command{
|
||||
|
||||
readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder()
|
||||
rpcServer := jsonrpc.NewServer(readerServerOpt)
|
||||
rpcServer.Register("Filecoin", apistruct.PermissionedWorkerAPI(metrics.MetricedWorkerAPI(workerApi)))
|
||||
rpcServer.Register("Filecoin", api.PermissionedWorkerAPI(metrics.MetricedWorkerAPI(workerApi)))
|
||||
|
||||
mux.Handle("/rpc/v0", rpcServer)
|
||||
mux.Handle("/rpc/streams/v0/push/{uuid}", readerHandler)
|
||||
|
@ -15,7 +15,8 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/node/modules"
|
||||
)
|
||||
@ -98,19 +99,19 @@ var jwtTokenCmd = &cli.Command{
|
||||
perms := []auth.Permission{}
|
||||
|
||||
if cctx.Bool("read") {
|
||||
perms = append(perms, apistruct.PermRead)
|
||||
perms = append(perms, api.PermRead)
|
||||
}
|
||||
|
||||
if cctx.Bool("write") {
|
||||
perms = append(perms, apistruct.PermWrite)
|
||||
perms = append(perms, api.PermWrite)
|
||||
}
|
||||
|
||||
if cctx.Bool("sign") {
|
||||
perms = append(perms, apistruct.PermSign)
|
||||
perms = append(perms, api.PermSign)
|
||||
}
|
||||
|
||||
if cctx.Bool("admin") {
|
||||
perms = append(perms, apistruct.PermAdmin)
|
||||
perms = append(perms, api.PermAdmin)
|
||||
}
|
||||
|
||||
p := modules.JwtPayload{
|
||||
@ -152,7 +153,7 @@ var jwtNewCmd = &cli.Command{
|
||||
}
|
||||
|
||||
p := modules.JwtPayload{
|
||||
Allow: apistruct.AllPermissions,
|
||||
Allow: api.AllPermissions,
|
||||
}
|
||||
|
||||
token, err := jwt.Sign(&p, jwt.NewHS256(keyInfo.PrivateKey))
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
lcli "github.com/filecoin-project/lotus/cli"
|
||||
"github.com/filecoin-project/lotus/lib/ulimit"
|
||||
@ -165,7 +164,7 @@ var runCmd = &cli.Command{
|
||||
mux := mux.NewRouter()
|
||||
|
||||
rpcServer := jsonrpc.NewServer()
|
||||
rpcServer.Register("Filecoin", apistruct.PermissionedStorMinerAPI(metrics.MetricedStorMinerAPI(minerapi)))
|
||||
rpcServer.Register("Filecoin", api.PermissionedStorMinerAPI(metrics.MetricedStorMinerAPI(minerapi)))
|
||||
|
||||
mux.Handle("/rpc/v0", rpcServer)
|
||||
mux.PathPrefix("/remote").HandlerFunc(minerapi.(*impl.StorageMinerAPI).ServeRemote)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"github.com/filecoin-project/go-jsonrpc"
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/v0api"
|
||||
"github.com/filecoin-project/lotus/api/v1api"
|
||||
"github.com/filecoin-project/lotus/metrics"
|
||||
@ -48,7 +48,7 @@ func serveRPC(a v1api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, sh
|
||||
http.Handle(path, ah)
|
||||
}
|
||||
|
||||
pma := apistruct.PermissionedFullAPI(metrics.MetricedFullAPI(a))
|
||||
pma := api.PermissionedFullAPI(metrics.MetricedFullAPI(a))
|
||||
|
||||
serveRpc("/rpc/v1", pma)
|
||||
serveRpc("/rpc/v0", &v0api.WrapperV1Full{FullNode: pma})
|
||||
@ -116,7 +116,7 @@ func handleImport(a *impl.FullNodeAPI) func(w http.ResponseWriter, r *http.Reque
|
||||
w.WriteHeader(404)
|
||||
return
|
||||
}
|
||||
if !auth.HasPerm(r.Context(), nil, apistruct.PermWrite) {
|
||||
if !auth.HasPerm(r.Context(), nil, api.PermWrite) {
|
||||
w.WriteHeader(401)
|
||||
_ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
|
||||
return
|
||||
|
@ -54,7 +54,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
|
||||
}
|
||||
func main() {
|
||||
// latest (v1)
|
||||
if err := generate("./api", "api", "apistruct", "./api/apistruct/struct.go"); err != nil {
|
||||
if err := generate("./api", "api", "api", "./api/struct.go"); err != nil {
|
||||
fmt.Println("error: ", err)
|
||||
}
|
||||
|
||||
@ -64,34 +64,34 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func typeName(e ast.Expr) (string, error) {
|
||||
func typeName(e ast.Expr, pkg string) (string, error) {
|
||||
switch t := e.(type) {
|
||||
case *ast.SelectorExpr:
|
||||
return t.X.(*ast.Ident).Name + "." + t.Sel.Name, nil
|
||||
case *ast.Ident:
|
||||
pstr := t.Name
|
||||
if !unicode.IsLower(rune(pstr[0])) {
|
||||
if !unicode.IsLower(rune(pstr[0])) && pkg != "api" {
|
||||
pstr = "api." + pstr // todo src pkg name
|
||||
}
|
||||
return pstr, nil
|
||||
case *ast.ArrayType:
|
||||
subt, err := typeName(t.Elt)
|
||||
subt, err := typeName(t.Elt, pkg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "[]" + subt, nil
|
||||
case *ast.StarExpr:
|
||||
subt, err := typeName(t.X)
|
||||
subt, err := typeName(t.X, pkg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "*" + subt, nil
|
||||
case *ast.MapType:
|
||||
k, err := typeName(t.Key)
|
||||
k, err := typeName(t.Key, pkg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
v, err := typeName(t.Value)
|
||||
v, err := typeName(t.Value, pkg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -107,7 +107,7 @@ func typeName(e ast.Expr) (string, error) {
|
||||
}
|
||||
return "interface{}", nil
|
||||
case *ast.ChanType:
|
||||
subt, err := typeName(t.Value)
|
||||
subt, err := typeName(t.Value, pkg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -197,7 +197,7 @@ func generate(path, pkg, outpkg, outfile string) error {
|
||||
if _, ok := info.Methods[mname]; !ok {
|
||||
var params, pnames []string
|
||||
for _, param := range node.ftype.Params.List {
|
||||
pstr, err := typeName(param.Type)
|
||||
pstr, err := typeName(param.Type, outpkg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -216,7 +216,7 @@ func generate(path, pkg, outpkg, outfile string) error {
|
||||
|
||||
var results []string
|
||||
for _, result := range node.ftype.Results.List {
|
||||
rs, err := typeName(result.Type)
|
||||
rs, err := typeName(result.Type, outpkg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,37 +7,36 @@ import (
|
||||
"go.opencensus.io/tag"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
)
|
||||
|
||||
func MetricedStorMinerAPI(a api.StorageMiner) api.StorageMiner {
|
||||
var out apistruct.StorageMinerStruct
|
||||
var out api.StorageMinerStruct
|
||||
proxy(a, &out.Internal)
|
||||
proxy(a, &out.CommonStruct.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func MetricedFullAPI(a api.FullNode) api.FullNode {
|
||||
var out apistruct.FullNodeStruct
|
||||
var out api.FullNodeStruct
|
||||
proxy(a, &out.Internal)
|
||||
proxy(a, &out.CommonStruct.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func MetricedWorkerAPI(a api.Worker) api.Worker {
|
||||
var out apistruct.WorkerStruct
|
||||
var out api.WorkerStruct
|
||||
proxy(a, &out.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func MetricedWalletAPI(a api.Wallet) api.Wallet {
|
||||
var out apistruct.WalletStruct
|
||||
var out api.WalletStruct
|
||||
proxy(a, &out.Internal)
|
||||
return &out
|
||||
}
|
||||
|
||||
func MetricedGatewayAPI(a api.Gateway) api.Gateway {
|
||||
var out apistruct.GatewayStruct
|
||||
var out api.GatewayStruct
|
||||
proxy(a, &out.Internal)
|
||||
return &out
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/markets/storageadapter"
|
||||
@ -86,7 +85,7 @@ type StorageMinerAPI struct {
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
|
||||
if !auth.HasPerm(r.Context(), nil, apistruct.PermAdmin) {
|
||||
if !auth.HasPerm(r.Context(), nil, api.PermAdmin) {
|
||||
w.WriteHeader(401)
|
||||
_ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
|
||||
return
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/api/apistruct"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/addrutil"
|
||||
@ -163,7 +163,7 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err
|
||||
|
||||
// TODO: make this configurable
|
||||
p := JwtPayload{
|
||||
Allow: apistruct.AllPermissions,
|
||||
Allow: api.AllPermissions,
|
||||
}
|
||||
|
||||
cliToken, err := jwt.Sign(&p, jwt.NewHS256(key.PrivateKey))
|
||||
|
Loading…
Reference in New Issue
Block a user