mirror of
https://github.com/versity/versitygw.git
synced 2026-09-06 16:16:53 +00:00
feat: Adds Ownder data in ListObjects(V2) result.
Closes #819 ListObjects returns object owner data in each object entity in the result, while ListObjectsV2 has fetch-owner query param, which indicates if the objects owner data should be fetched. Adds these changes in the gateway to add `Owner` data in `ListObjects` and `ListObjectsV2` result. In aws the objects can be owned by different users in the same bucket. In the gateway all the objects are owned by the bucket owner.
This commit is contained in:
@@ -218,6 +218,7 @@ func TestListObjects(s *S3Conf) {
|
||||
ListObjects_marker_not_from_obj_list(s)
|
||||
ListObjects_list_all_objs(s)
|
||||
ListObjects_nested_dir_file_objs(s)
|
||||
ListObjects_check_owner(s)
|
||||
//TODO: remove the condition after implementing checksums in azure
|
||||
if !s.azureTests {
|
||||
ListObjects_with_checksum(s)
|
||||
@@ -235,6 +236,7 @@ func TestListObjectsV2(s *S3Conf) {
|
||||
ListObjectsV2_all_objs_max_keys(s)
|
||||
ListObjectsV2_exceeding_max_keys(s)
|
||||
ListObjectsV2_list_all_objs(s)
|
||||
ListObjectsV2_with_owner(s)
|
||||
//TODO: remove the condition after implementing checksums in azure
|
||||
if !s.azureTests {
|
||||
ListObjectsV2_with_checksum(s)
|
||||
@@ -897,6 +899,7 @@ func GetIntTests() IntTests {
|
||||
"ListObjects_marker_not_from_obj_list": ListObjects_marker_not_from_obj_list,
|
||||
"ListObjects_list_all_objs": ListObjects_list_all_objs,
|
||||
"ListObjects_nested_dir_file_objs": ListObjects_nested_dir_file_objs,
|
||||
"ListObjects_check_owner": ListObjects_check_owner,
|
||||
"ListObjects_with_checksum": ListObjects_with_checksum,
|
||||
"ListObjectsV2_start_after": ListObjectsV2_start_after,
|
||||
"ListObjectsV2_both_start_after_and_continuation_token": ListObjectsV2_both_start_after_and_continuation_token,
|
||||
@@ -907,6 +910,7 @@ func GetIntTests() IntTests {
|
||||
"ListObjectsV2_truncated_common_prefixes": ListObjectsV2_truncated_common_prefixes,
|
||||
"ListObjectsV2_all_objs_max_keys": ListObjectsV2_all_objs_max_keys,
|
||||
"ListObjectsV2_list_all_objs": ListObjectsV2_list_all_objs,
|
||||
"ListObjectsV2_with_owner": ListObjectsV2_with_owner,
|
||||
"ListObjectsV2_with_checksum": ListObjectsV2_with_checksum,
|
||||
"ListObjectVersions_VD_success": ListObjectVersions_VD_success,
|
||||
"DeleteObject_non_existing_object": DeleteObject_non_existing_object,
|
||||
|
||||
@@ -4815,7 +4815,7 @@ func ListObjects_with_checksum(s *S3Conf) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !compareObjects(res.Contents, contents) {
|
||||
if !compareObjects(contents, res.Contents) {
|
||||
return fmt.Errorf("expected the objects list to be %v, instead got %v", contents, res.Contents)
|
||||
}
|
||||
|
||||
@@ -4899,6 +4899,38 @@ func ListObjects_nested_dir_file_objs(s *S3Conf) error {
|
||||
})
|
||||
}
|
||||
|
||||
func ListObjects_check_owner(s *S3Conf) error {
|
||||
testName := "ListObjects_check_owner"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
objs, err := putObjects(s3client, []string{"foo", "bar/baz", "quxx/xyz/eee", "abc/", "bcc"}, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
||||
res, err := s3client.ListObjects(ctx, &s3.ListObjectsInput{
|
||||
Bucket: &bucket,
|
||||
})
|
||||
cancel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range res.Contents {
|
||||
res.Contents[i].Owner = &types.Owner{
|
||||
ID: &s.awsID,
|
||||
}
|
||||
}
|
||||
|
||||
if !compareObjects(objs, res.Contents) {
|
||||
return fmt.Errorf("expected the contents to be %v, instead got %v", objs, res.Contents)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func ListObjectsV2_start_after(s *S3Conf) error {
|
||||
testName := "ListObjectsV2_start_after"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
@@ -5290,6 +5322,38 @@ func ListObjectsV2_list_all_objs(s *S3Conf) error {
|
||||
})
|
||||
}
|
||||
|
||||
func ListObjectsV2_with_owner(s *S3Conf) error {
|
||||
testName := "ListObjectsV2_with_owner"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
objs, err := putObjects(s3client, []string{"foo", "bar/baz", "quxx/xyz/eee", "abc/", "bcc"}, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
||||
res, err := s3client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
|
||||
Bucket: &bucket,
|
||||
FetchOwner: getBoolPtr(true),
|
||||
})
|
||||
cancel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range res.Contents {
|
||||
res.Contents[i].Owner = &types.Owner{
|
||||
ID: &s.awsID,
|
||||
}
|
||||
}
|
||||
|
||||
if !compareObjects(objs, res.Contents) {
|
||||
return fmt.Errorf("expected the contents to be %v, instead got %v", objs, res.Contents)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func ListObjectsV2_with_checksum(s *S3Conf) error {
|
||||
testName := "ListObjectsV2_with_checksum"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
|
||||
@@ -725,10 +725,16 @@ func compareObjects(list1, list2 []types.Object) bool {
|
||||
if obj.ChecksumType != "" {
|
||||
if obj.ChecksumType[0] != list2[i].ChecksumType[0] {
|
||||
fmt.Printf("checksum types are not equal: (%q %q) %v != %v\n",
|
||||
*obj.Key, *list2[i].Key, obj.ChecksumType[0], list2[i].ChecksumType[0])
|
||||
*obj.Key, *list2[i].Key, obj.ChecksumType, list2[i].ChecksumType)
|
||||
return false
|
||||
}
|
||||
}
|
||||
if obj.Owner != nil {
|
||||
if *obj.Owner.ID != *list2[i].Owner.ID {
|
||||
fmt.Printf("object owner IDs not equal: (%q %q) %v != %v\n",
|
||||
*obj.Key, *list2[i].Key, *obj.Owner.ID, *list2[i].Owner.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user