Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ListObjectPoliciesResponse unmarshal failed #213

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions client/api_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,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 @@ -1339,7 +1355,7 @@ func (c *Client) ListObjectPolicies(ctx context.Context, objectName, bucketName

policies := types.ListObjectPoliciesResponse{}
bufStr := buf.String()
err = xml.Unmarshal([]byte(bufStr), &policies.Policies)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add more details in the function doc for actionType parameters

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add an e2e test on this API.

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
Loading