Skip to content

Commit

Permalink
Merge pull request #143 from filecoin-project/dev/v1.10.0
Browse files Browse the repository at this point in the history
Dev/v1.10.0
  • Loading branch information
diwufeiwen authored Feb 17, 2023
2 parents 18159ea + d2f90dd commit ddfaa1f
Show file tree
Hide file tree
Showing 29 changed files with 822 additions and 421 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# venus-auth changelog

## v1.10.0-rc2

* 简化 authClient 接口,并增加 context [[#126](https://github.com/filecoin-project/venus-auth/pull/126)]
* 重写 url 中的地址参数 [[#127](https://github.com/filecoin-project/venus-auth/pull/127)]
* 增加用户数据隔离的工具 [[#130](https://github.com/filecoin-project/venus-auth/pull/130)]
* 调整 jwtclient.IAtuhClient 接口 [[#137](https://github.com/filecoin-project/venus-auth/pull/137)]

## v1.10.0-rc1

* github action 增加 dispatch 事件 [[#138](https://github.com/filecoin-project/venus-auth/pull/138)]
Expand Down
90 changes: 20 additions & 70 deletions auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,15 @@ func (o *jwtOAuth) RecoverUser(ctx *gin.Context, req *RecoverUserRequest) error
}

func (o *jwtOAuth) GetUserByMiner(ctx context.Context, req *GetUserByMinerRequest) (*OutputUser, error) {
mAddr, err := address.NewFromString(req.Miner)
if err != nil {
return nil, err
}
user, err := o.store.GetUserByMiner(mAddr)
user, err := o.store.GetUserByMiner(req.Miner)
if err != nil {
return nil, err
}
return o.mp.ToOutPutUser(user), nil
}

func (o *jwtOAuth) GetUserBySigner(ctx context.Context, req *GetUserBySignerReq) ([]*OutputUser, error) {
addr, err := address.NewFromString(req.Signer)
if err != nil {
return nil, err
}
users, err := o.store.GetUserBySigner(addr)
users, err := o.store.GetUserBySigner(req.Signer)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -371,38 +363,24 @@ func (o jwtOAuth) DelUserRateLimit(ctx context.Context, req *DelUserRateLimitReq
}

func (o *jwtOAuth) UpsertMiner(ctx context.Context, req *UpsertMinerReq) (bool, error) {
maddr, err := address.NewFromString(req.Miner)
if err != nil || maddr.Empty() {
return false, xerrors.Errorf("invalid miner address:%s, error: %w", req.Miner, err)
}

if maddr.Protocol() != address.ID {
return false, fmt.Errorf("invalid protocol type: %v", maddr.Protocol())
mAddr := req.Miner
if mAddr.Protocol() != address.ID {
return false, fmt.Errorf("invalid protocol type: %v", mAddr.Protocol())
}

return o.store.UpsertMiner(maddr, req.User, req.OpenMining)
return o.store.UpsertMiner(mAddr, req.User, req.OpenMining)
}

func (o *jwtOAuth) HasMiner(ctx context.Context, req *HasMinerRequest) (bool, error) {
mAddr, err := address.NewFromString(req.Miner)
if err != nil {
return false, err
}

has, err := o.store.HasMiner(mAddr)
has, err := o.store.HasMiner(req.Miner)
if err != nil {
return false, err
}
return has, nil
}

func (o *jwtOAuth) MinerExistInUser(ctx context.Context, req *MinerExistInUserRequest) (bool, error) {
mAddr, err := address.NewFromString(req.Miner)
if err != nil {
return false, err
}

exist, err := o.store.MinerExistInUser(mAddr, req.User)
exist, err := o.store.MinerExistInUser(req.Miner, req.User)
if err != nil {
return false, err
}
Expand All @@ -417,9 +395,8 @@ func (o *jwtOAuth) ListMiners(ctx context.Context, req *ListMinerReq) (ListMiner

outs := make([]*OutputMiner, len(miners))
for idx, m := range miners {
addrStr := m.Miner.Address().String()
outs[idx] = &OutputMiner{
Miner: addrStr,
Miner: m.Miner.Address(),
User: m.User,
OpenMining: *m.OpenMining,
CreatedAt: m.CreatedAt,
Expand All @@ -430,25 +407,16 @@ func (o *jwtOAuth) ListMiners(ctx context.Context, req *ListMinerReq) (ListMiner
}

func (o jwtOAuth) DelMiner(ctx context.Context, req *DelMinerReq) (bool, error) {
miner, err := address.NewFromString(req.Miner)
if err != nil {
return false, xerrors.Errorf("invalid miner address:%s, %w", req.Miner, err)
}
return o.store.DelMiner(miner)
return o.store.DelMiner(req.Miner)
}

func (o *jwtOAuth) RegisterSigners(ctx context.Context, req *RegisterSignersReq) error {
for _, signer := range req.Signers {
addr, err := address.NewFromString(signer)
if err != nil || addr.Empty() {
return fmt.Errorf("invalid signer address: %s, error: %w", signer, err)
}

if !isSignerAddress(addr) {
return fmt.Errorf("invalid protocol type: %v", addr.Protocol())
if !isSignerAddress(signer) {
return fmt.Errorf("invalid protocol type: %v", signer.Protocol())
}

err = o.store.RegisterSigner(addr, req.User)
err := o.store.RegisterSigner(signer, req.User)
if err != nil {
return fmt.Errorf("unregister signer:%s, error: %w", signer, err)
}
Expand All @@ -458,11 +426,7 @@ func (o *jwtOAuth) RegisterSigners(ctx context.Context, req *RegisterSignersReq)
}

func (o *jwtOAuth) SignerExistInUser(ctx context.Context, req *SignerExistInUserReq) (bool, error) {
addr, err := address.NewFromString(req.Signer)
if err != nil {
return false, err
}

addr := req.Signer
if !isSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}
Expand All @@ -482,9 +446,8 @@ func (o *jwtOAuth) ListSigner(ctx context.Context, req *ListSignerReq) (ListSign

outs := make([]*OutputSigner, len(signers))
for idx, m := range signers {
addrStr := m.Signer.Address().String()
outs[idx] = &OutputSigner{
Signer: addrStr,
Signer: m.Signer.Address(),
User: m.User,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
Expand All @@ -495,16 +458,11 @@ func (o *jwtOAuth) ListSigner(ctx context.Context, req *ListSignerReq) (ListSign

func (o *jwtOAuth) UnregisterSigners(ctx context.Context, req *UnregisterSignersReq) error {
for _, signer := range req.Signers {
addr, err := address.NewFromString(signer)
if err != nil || addr.Empty() {
return fmt.Errorf("invalid signer address: %s, error: %w", signer, err)
if !isSignerAddress(signer) {
return fmt.Errorf("invalid protocol type: %v", signer.Protocol())
}

if !isSignerAddress(addr) {
return fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}

err = o.store.UnregisterSigner(addr, req.User)
err := o.store.UnregisterSigner(signer, req.User)
if err != nil {
return fmt.Errorf("unregister signer:%s, error: %w", signer, err)
}
Expand All @@ -514,11 +472,7 @@ func (o *jwtOAuth) UnregisterSigners(ctx context.Context, req *UnregisterSigners
}

func (o jwtOAuth) HasSigner(ctx context.Context, req *HasSignerReq) (bool, error) {
addr, err := address.NewFromString(req.Signer)
if err != nil {
return false, xerrors.Errorf("invalid signer address:%s, %w", req.Signer, err)
}

addr := req.Signer
if !isSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}
Expand All @@ -527,11 +481,7 @@ func (o jwtOAuth) HasSigner(ctx context.Context, req *HasSignerReq) (bool, error
}

func (o jwtOAuth) DelSigner(ctx context.Context, req *DelSignerReq) (bool, error) {
addr, err := address.NewFromString(req.Signer)
if err != nil {
return false, xerrors.Errorf("invalid signer address:%s, %w", req.Signer, err)
}

addr := req.Signer
if !isSignerAddress(addr) {
return false, fmt.Errorf("invalid protocol type: %v", addr.Protocol())
}
Expand Down
Loading

0 comments on commit ddfaa1f

Please sign in to comment.