Skip to content

Commit

Permalink
refine codes
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Oct 17, 2023
1 parent d6f0094 commit 92bcef0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818 h1:HyAROtp8xHuuzZzJTXfwVm0c+qTJs3ahPFtEpJFs5lM=
github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20230918080629-546708eba818/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e h1:nHk7ex6a2iwYl/L5ZpffJSlWC81+2IVyw5q9S1dsnKU=
github.com/forcodedancing/greenfield-cosmos-sdk v0.2.1-0.20231016120649-fcdced9e012e/go.mod h1:BGVMW9gRFKGzCwK/8CmDGe3sK9r9QujL1Uz2FMMM+/s=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
Expand Down
44 changes: 19 additions & 25 deletions x/permission/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,35 +214,29 @@ func (s *Statement) ValidateBasic(resType resource.ResourceType) error {
return nil
}

func (s *Statement) ValidateAfterNagqu(resType resource.ResourceType) error {
if s.Effect == EFFECT_UNSPECIFIED {
return ErrInvalidStatement.Wrap("Please specify the Effect explicitly. Not allowed set EFFECT_UNSPECIFIED")
}
switch resType {
case resource.RESOURCE_TYPE_UNSPECIFIED:
return ErrInvalidStatement.Wrap("Please specify the ResourceType explicitly. Not allowed set RESOURCE_TYPE_UNSPECIFIED")
case resource.RESOURCE_TYPE_BUCKET:
for _, r := range s.Resources {
_, err := regexp.Compile(r)
if err != nil {
return ErrInvalidStatement.Wrapf("The Resources regexp compile failed, err: %s", err)
func (s *Statement) ValidateRuntime(ctx sdk.Context, resType resource.ResourceType) error {
if ctx.IsUpgraded(upgradetypes.Nagqu) {
switch resType {
case resource.RESOURCE_TYPE_BUCKET:
for _, r := range s.Resources {
_, err := regexp.Compile(r)
if err != nil {
return ErrInvalidStatement.Wrapf("The Resources regexp compile failed, err: %s", err)
}
}
case resource.RESOURCE_TYPE_OBJECT:
if s.Resources != nil {
return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ")
}
case resource.RESOURCE_TYPE_GROUP:
if s.Resources != nil {
return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ")
}
default:
return ErrInvalidStatement.Wrap("unknown resource type.")
}
case resource.RESOURCE_TYPE_OBJECT:
if s.Resources != nil {
return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ")
}
case resource.RESOURCE_TYPE_GROUP:
if s.Resources != nil {
return ErrInvalidStatement.Wrap("The Resources option can only be used at the bucket level. ")
}
default:
return ErrInvalidStatement.Wrap("unknown resource type.")
}
return nil
}

func (s *Statement) ValidateRuntime(ctx sdk.Context, resType resource.ResourceType) error {
var bucketAllowedActions map[ActionType]bool
if ctx.IsUpgraded(upgradetypes.Pampas) {
bucketAllowedActions = BucketAllowedActionsAfterPampas
Expand Down
7 changes: 0 additions & 7 deletions x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

types2 "github.com/bnb-chain/greenfield/types"
gnfderrors "github.com/bnb-chain/greenfield/types/errors"
Expand Down Expand Up @@ -370,12 +369,6 @@ func (k msgServer) PutPolicy(goCtx context.Context, msg *types.MsgPutPolicy) (*t
if s.ExpirationTime != nil && s.ExpirationTime.Before(ctx.BlockTime()) {
return nil, permtypes.ErrPermissionExpired.Wrapf("The specified statement expiration time is less than the current block time, block time: %s", ctx.BlockTime().String())
}
if ctx.IsUpgraded(upgradetypes.Nagqu) {
err := s.ValidateAfterNagqu(grn.ResourceType())
if err != nil {
return nil, err
}
}
}

policy := &permtypes.Policy{
Expand Down

0 comments on commit 92bcef0

Please sign in to comment.