Skip to content

Commit

Permalink
Merge pull request #144 from ipfs-force-community/chore/merge-release…
Browse files Browse the repository at this point in the history
…-v1.12

Chore/merge release v1.12
  • Loading branch information
LinZexiao authored Jul 10, 2023
2 parents c71fd27 + eb0055f commit ae3dbe4
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# sophon-gateway changelog

## v1.12.0

* feat: move RandomBytes to venus share by @LinZexiao in [[#141](https://github.com/ipfs-force-community/sophon-gateway/pull/141)]
* doc: fix link by @0x5459 in [[#139](https://github.com/ipfs-force-community/sophon-gateway/pull/139)]

## v1.12.0-rc1

* chore: merge release/v1.11 into master [[#131](https://github.com/ipfs-force-community/sophon-gateway/pull/131)]
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ ifdef PRIVATE_REGISTRY
endif

docker-push: docker
ifdef PRIVATE_REGISTRY
docker push $(PRIVATE_REGISTRY)/filvenus/sophon-gateway:$(TAG)
else
docker push filvenus/sophon-gateway:$(TAG)
docker tag filvenus/sophon-gateway:$(TAG) filvenus/sophon-gateway:latest
docker push filvenus/sophon-gateway:latest
endif
45 changes: 45 additions & 0 deletions cmds/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmds

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/filecoin-project/go-jsonrpc"
Expand All @@ -14,11 +16,17 @@ import (
"github.com/ipfs-force-community/sophon-gateway/config"
)

const oldRepoPath = "~/.venusgateway"

func NewGatewayClient(ctx *cli.Context) (v2API.IGateway, jsonrpc.ClientCloser, error) {
repoPath, err := homedir.Expand(ctx.String("repo"))
if err != nil {
return nil, nil, err
}
repoPath, err = GetRepoPath(repoPath)
if err != nil {
return nil, nil, err
}

cfg, err := config.ReadConfig(filepath.Join(repoPath, config.ConfigFile))
if err != nil {
Expand All @@ -37,3 +45,40 @@ func NewGatewayClient(ctx *cli.Context) (v2API.IGateway, jsonrpc.ClientCloser, e

return v2API.DialIGatewayRPC(ctx.Context, listen, string(token), nil)
}

func HasRepo(path string) (bool, error) {
fi, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
if !fi.IsDir() {
return false, fmt.Errorf("%s is not a directory", path)
}

return true, nil
}

func GetRepoPath(repoPath string) (string, error) {
has, err := HasRepo(repoPath)
if err != nil {
return "", err
}
if !has {
// check old repo path
rPath, err := homedir.Expand(oldRepoPath)
if err != nil {
return "", err
}
has, err = HasRepo(rPath)
if err != nil {
return "", err
}
if has {
return rPath, nil
}
}
return repoPath, nil
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/filecoin-project/go-address v1.1.0
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.11.1
github.com/filecoin-project/venus v1.12.0-rc1.0.20230625012554-af257e1b803a
github.com/filecoin-project/venus v1.12.0-rc1.0.20230625063248-c74fd729cc2d
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466
github.com/ipfs-force-community/sophon-auth v1.12.0-rc1
github.com/ipfs-force-community/sophon-auth v1.12.0
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-log/v2 v2.5.1
github.com/modern-go/reflect2 v1.0.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ github.com/filecoin-project/specs-storage v0.2.2/go.mod h1:6cc/lncmAxMUocPi0z1EP
github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI=
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.12.0-rc1.0.20230625012554-af257e1b803a h1:ocGzKa1QzFiCPtWLCTCYyMGvyW62sY2O8LRVeajRVuA=
github.com/filecoin-project/venus v1.12.0-rc1.0.20230625012554-af257e1b803a/go.mod h1:t5AL4ksL7QHaeKZ6sl6u6kW3jBvHK+m1xV0AdtGfjPE=
github.com/filecoin-project/venus v1.12.0-rc1.0.20230625063248-c74fd729cc2d h1:X/LrJlbxQtL1tobiN0xsWrv/4ZZuBGsEWuxTjlf2QQs=
github.com/filecoin-project/venus v1.12.0-rc1.0.20230625063248-c74fd729cc2d/go.mod h1:t5AL4ksL7QHaeKZ6sl6u6kW3jBvHK+m1xV0AdtGfjPE=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
Expand Down Expand Up @@ -732,8 +732,8 @@ github.com/ipfs-force-community/metrics v1.0.0/go.mod h1:mn40SioMuKtjmRumHFy/fJ2
github.com/ipfs-force-community/metrics v1.0.1-0.20211022060227-11142a08b729/go.mod h1:mn40SioMuKtjmRumHFy/fJ26Pn028XuDjUJE9dorjyw=
github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466 h1:oPQtpBVmYot48fGuUwqVuzD1ilMnHUXkkGSWy5VzUL8=
github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466/go.mod h1:MOGtsAHKkSXi/ce9Ggci7nXq5jShePzwPDvdBSGDETk=
github.com/ipfs-force-community/sophon-auth v1.12.0-rc1 h1:Rm91rxnwbx6ejEIPh7Bmf/+cWaNezhSj/zwmIkG9MG4=
github.com/ipfs-force-community/sophon-auth v1.12.0-rc1/go.mod h1:cGYCfjA/BDB/Km9P7Za6t1hmwpFlPKf8ho/CHmLG81Y=
github.com/ipfs-force-community/sophon-auth v1.12.0 h1:nqjsA6bIv9Rd9+7lHxGDvNJ7gvt/M2yGSxymA6AoxXI=
github.com/ipfs-force-community/sophon-auth v1.12.0/go.mod h1:cGYCfjA/BDB/Km9P7Za6t1hmwpFlPKf8ho/CHmLG81Y=
github.com/ipfs-force-community/venus-common-utils v0.0.0-20210924063144-1d3a5b30de87/go.mod h1:RTVEOzM+hkpqmcEWpyLDkx1oGO5r9ZWCgYxG/CsXzJQ=
github.com/ipfs/bbloom v0.0.1/go.mod h1:oqo8CVWsJFMOZqTglBG4wydCE4IQA/G2/SEofB0rjUI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
Expand Down
41 changes: 2 additions & 39 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ var runCmd = &cli.Command{
return err
}
// todo: remove compatibility code
repoPath, err = getRepoPath(repoPath)
repoPath, err = cmds.GetRepoPath(repoPath)
if err != nil {
return err
}

hasRepo, err := hasRepo(repoPath)
hasRepo, err := cmds.HasRepo(repoPath)
if err != nil {
return err
}
Expand All @@ -137,43 +137,6 @@ var runCmd = &cli.Command{
},
}

func hasRepo(path string) (bool, error) {
fi, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
if !fi.IsDir() {
return false, fmt.Errorf("%s is not a directory", path)
}

return true, nil
}

func getRepoPath(repoPath string) (string, error) {
has, err := hasRepo(repoPath)
if err != nil {
return "", err
}
if !has {
// check old repo path
rPath, err := homedir.Expand(oldRepoPath)
if err != nil {
return "", err
}
has, err = hasRepo(rPath)
if err != nil {
return "", err
}
if has {
return rPath, nil
}
}
return repoPath, nil
}

func parseFlag(cctx *cli.Context, cfg *config.Config) {
if cctx.IsSet("listen") {
cfg.API.ListenAddress = cctx.String("listen")
Expand Down
14 changes: 6 additions & 8 deletions validator/miner_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ func (amv *AuthMinerValidator) Validate(ctx context.Context, miner address.Addre
if !exist {
return fmt.Errorf("user name not exist in rpc context")
}
user, err := amv.authClient.GetUserByMiner(ctx, miner)

ok, err := amv.authClient.MinerExistInUser(ctx, account, miner)
if err != nil {
return fmt.Errorf("get user by miner(%s), failed:%w", miner.String(), err)
}
if user.State != core.UserStateEnabled {
return fmt.Errorf("user:%s is disabled, please enable it on 'venus-auth'", account)
return fmt.Errorf("check miner(%s) exist in user(%s), failed:%w", miner.String(), account, err)
}
if user.Name != account {
return fmt.Errorf("your account is:%s, but miner:%s is currently bind to user:%s, change this on 'venus-auth'",
account, miner.String(), user.Name)
if !ok {
return fmt.Errorf("miner:%s not exist in user:%s, please bind it on 'sophon-auth'", miner.String(), account)
}

return nil
}

Expand Down
17 changes: 15 additions & 2 deletions validator/mocks/mock_authclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,21 @@ func (m *AuthClient) GetUserRateLimit(ctx context.Context, name, id string) (aut
panic("Don't call me")
}

func (m *AuthClient) MinerExistInUser(ctx context.Context, user string, miner address.Address) (bool, error) {
panic("Don't call me")
func (m *AuthClient) MinerExistInUser(ctx context.Context, targetUser string, miner address.Address) (bool, error) {
m.lkUser.Lock()
defer m.lkUser.Unlock()

for _, user := range m.users {
if user.Name == targetUser {
for _, m := range user.Miners {
if m.Miner == miner {
return true, nil
}
}
}
}

return false, nil
}

func (m *AuthClient) SignerExistInUser(ctx context.Context, user string, signer address.Address) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package version
var CurrentCommit string

// BuildVersion is the local build version, set by build system
const BuildVersion = "1.12.0-rc1"
const BuildVersion = "1.12.0"

var UserVersion = BuildVersion + CurrentCommit

0 comments on commit ae3dbe4

Please sign in to comment.