Skip to content

Commit

Permalink
fix: error check
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed Dec 6, 2022
1 parent f657e5d commit 72634bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

make lint
33 changes: 10 additions & 23 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (m MarketNodeImpl) ActorList(ctx context.Context) ([]types.User, error) {
}
ret := []types.User{}
for _, actor := range actors {
if err := m.checkPermissionByName(ctx, actor.Account); err != nil {
if err := m.checkPermissionByName(ctx, actor.Account); err == nil {
ret = append(ret, actor)
}
}
Expand Down Expand Up @@ -389,7 +389,7 @@ func (m *MarketNodeImpl) MarketCancelDataTransfer(ctx context.Context, transferI

func (m *MarketNodeImpl) MarketPendingDeals(ctx context.Context) ([]types.PendingDealInfo, error) {
dealInfos := m.DealPublisher.PendingDeals()
ret := make([]types.PendingDealInfo, len(dealInfos))
ret := make([]types.PendingDealInfo, 0, len(dealInfos))
for addr, dealInfo := range dealInfos {
if err := m.checkPermissionByMiner(ctx, addr); err == nil {
ret = append(ret, dealInfo)
Expand Down Expand Up @@ -1238,20 +1238,19 @@ func (m *MarketNodeImpl) checkPermissionBySigner(ctx context.Context, addrs ...a
}
user, exist := jwtclient.CtxGetName(ctx)
if !exist {
return nil
return ErrorUserNotFound
}
for _, addr := range addrs {
auth_users, err := m.AuthClient.GetUserBySigner(addr.String())

for _, wAddr := range addrs {
ok, err := m.AuthClient.SignerExistInUser(user, wAddr.String())
if err != nil {
return fmt.Errorf("get auth user by signer %s failed when check permission: %s", addr.String(), err)
return fmt.Errorf("check signer exist in user fail %s failed when check permission: %s", wAddr.String(), err)
}
for _, auth_user := range auth_users {
if auth_user.Name == user {
return nil
}
if !ok {
return ErrorPermissionDeny
}
}
return ErrorPermissionDeny
return nil
}

func (m *MarketNodeImpl) checkPermissionByMiner(ctx context.Context, addrs ...address.Address) error {
Expand Down Expand Up @@ -1286,18 +1285,6 @@ func (m *MarketNodeImpl) checkPermissionByName(ctx context.Context, name string)
return nil
}

// isAdmin check if the user is admin and return user name
func (m *MarketNodeImpl) isAdmin(ctx context.Context) (isAdmin bool, name string, err error) {
if auth.HasPerm(ctx, []auth.Permission{}, core.PermAdmin) {
isAdmin = true
}
name, exit := jwtclient.CtxGetName(ctx)
if !exit && !isAdmin {
err = ErrorUserNotFound
}
return
}

func (m *MarketNodeImpl) MarketAddBalance(ctx context.Context, wallet, addr address.Address, amt vTypes.BigInt) (cid.Cid, error) {
if err := m.checkPermissionBySigner(ctx, wallet); err != nil {
return cid.Undef, err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/specs-actors/v2 v2.3.6
github.com/filecoin-project/specs-actors/v7 v7.0.1
github.com/filecoin-project/venus v1.8.1-0.20221129064655-35d20069eca9
github.com/filecoin-project/venus v1.8.1-0.20221206012930-359e0521ac44
github.com/filecoin-project/venus-auth v1.8.1-0.20221124050656-73734ff50be5
github.com/filecoin-project/venus-messager v1.8.1-0.20221124093938-eee70cda6d54
github.com/golang/mock v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ github.com/filecoin-project/storetheindex v0.4.17 h1:w0dVc954TGPukoVbidlYvn9Xt+w
github.com/filecoin-project/storetheindex v0.4.17/go.mod h1:y2dL8C5D3PXi183hdxgGtM8vVYOZ1lg515tpl/D3tN8=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0=
github.com/filecoin-project/venus v1.8.1-0.20221129064655-35d20069eca9 h1:GfpGSkdyaBf8qosy8adQ51EFPWFiP86QLC694W7nOaU=
github.com/filecoin-project/venus v1.8.1-0.20221129064655-35d20069eca9/go.mod h1:AnTMHZERLQH9oOSGohEVJAwDfQAHcwLXQuAjjmHIvh4=
github.com/filecoin-project/venus v1.8.1-0.20221206012930-359e0521ac44 h1:IZUfYXN1Hu3FOaFclcXW2MzILITIBbEvv94rhLWRAsk=
github.com/filecoin-project/venus v1.8.1-0.20221206012930-359e0521ac44/go.mod h1:rGzt9i7hq/gA7GdMyeDwZ47gSF+Ycz2efIHdsECWXUI=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/filecoin-project/venus-auth v1.8.1-0.20221124050656-73734ff50be5 h1:y5Y6v5lhN3wKNYQkx5EqPh+8f31oe94iSoHIZz7Iado=
github.com/filecoin-project/venus-auth v1.8.1-0.20221124050656-73734ff50be5/go.mod h1:Ckj8F/iuSgXnCb9LvH0IiPR7swJZQAhabDOxVycLGWs=
Expand Down

0 comments on commit 72634bc

Please sign in to comment.