Skip to content

Commit

Permalink
Merge pull request #213 from bnb-chain/fix-list-policies
Browse files Browse the repository at this point in the history
fix: ListObjectPoliciesResponse unmarshal failed
  • Loading branch information
ruojunm authored Nov 28, 2023
2 parents 47bc4c6 + 452b913 commit b433179
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client/api_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,23 @@ func (c *Client) ListObjectsByObjectID(ctx context.Context, objectIds []uint64,
//
// - bucketName: The bucket name identifies the bucket.
//
// - actionType: The action type defines the requested action type of permission.
// - actionType: The action type defines the requested action type of permission.
// | Value | Description |
// | ----- | -------------------------- |
// | 0 | ACTION_UNSPECIFIED |89
// | 1 | ACTION_UPDATE_BUCKET_INFO |
// | 2 | ACTION_DELETE_BUCKET |
// | 3 | ACTION_CREATE_OBJECT |
// | 4 | ACTION_DELETE_OBJECT |
// | 5 | ACTION_COPY_OBJECT |
// | 6 | ACTION_GET_OBJECT |
// | 7 | ACTION_EXECUTE_OBJECT |
// | 8 | ACTION_LIST_OBJECT |
// | 9 | ACTION_UPDATE_GROUP_MEMBER |
// | 10 | ACTION_DELETE_GROUP |
// | 11 | ACTION_UPDATE_OBJECT_INFO |
// | 12 | ACTION_UPDATE_GROUP_EXTRA |
// | 99 | ACTION_TYPE_ALL |
//
// - opts: The options to set the meta to list object policies
//
Expand Down Expand Up @@ -1342,7 +1358,7 @@ func (c *Client) ListObjectPolicies(ctx context.Context, objectName, bucketName

policies := types.ListObjectPoliciesResponse{}
bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &policies.Policies)
err = xml.Unmarshal([]byte(bufStr), &policies)
if err != nil {
log.Error().Msgf("the list object policies in bucket name:%s, object name:%s failed: %s", bucketName, objectName, err.Error())
return types.ListObjectPoliciesResponse{}, err
Expand Down
7 changes: 7 additions & 0 deletions e2e/e2e_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/bnb-chain/greenfield-go-sdk/types"
types2 "github.com/bnb-chain/greenfield/sdk/types"
storageTestUtil "github.com/bnb-chain/greenfield/testutil/storage"
"github.com/bnb-chain/greenfield/types/resource"
permTypes "github.com/bnb-chain/greenfield/x/permission/types"
spTypes "github.com/bnb-chain/greenfield/x/sp/types"
storageTypes "github.com/bnb-chain/greenfield/x/storage/types"
Expand Down Expand Up @@ -237,6 +238,12 @@ func (s *StorageTestSuite) Test_Object() {
s.Require().NoError(err)
s.T().Logf("get object policy:%s\n", objectPolicy.String())

s.T().Log("---> ListObjectPolicies <---")
objectPolicies, err := s.Client.ListObjectPolicies(s.ClientContext, objectName, bucketName, uint32(permTypes.ACTION_GET_OBJECT), types.ListObjectPoliciesOptions{})
s.Require().NoError(err)
s.Require().Equal(resource.RESOURCE_TYPE_OBJECT.String(), resource.ResourceType_name[objectPolicies.Policies[0].ResourceType])
s.T().Logf("list object policies principal type:%d principal value:%s \n", objectPolicies.Policies[0].PrincipalType, objectPolicies.Policies[0].PrincipalValue)

s.T().Log("---> DeleteObjectPolicy <---")

principalStr, err := utils.NewPrincipalWithAccount(principal.GetAddress())
Expand Down

0 comments on commit b433179

Please sign in to comment.