Skip to content

Commit

Permalink
fix: 增加对 aliyun oss 的支持||fix: Added support for Aliyun OSS (#1069)
Browse files Browse the repository at this point in the history
* 1、增加对 aliyun oss 的支持
   ListObjectsInput 增加 fetch_owner 表示是否获取 owner 信息
   ListObjectsOutput 中 Object 增加 type 表示Object 当前的状态

* 1、增加 Aliyun OSS 属性对于 Layotto 属性的转换

* 1、修复 ListObjectsInput fetch_owner 的类型错误

---------

Co-authored-by: zhengzhiqi.zzq <[email protected]>
  • Loading branch information
EraserTime and zhengzhiqi.zzq authored Sep 27, 2024
1 parent 9db2aa0 commit b4fed4d
Show file tree
Hide file tree
Showing 6 changed files with 1,151 additions and 1,089 deletions.
1 change: 1 addition & 0 deletions components/oss/aliyun/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (a *AliyunOSS) ListObjects(ctx context.Context, req *l8oss.ListObjectsInput
object := &l8oss.Object{
ETag: v.ETag,
Key: v.Key,
Type: v.Type,
LastModified: v.LastModified.Unix(),
Owner: &l8oss.Owner{ID: v.Owner.ID, DisplayName: v.Owner.DisplayName},
Size: v.Size,
Expand Down
2 changes: 2 additions & 0 deletions components/oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ type ListObjectsInput struct {
MaxKeys int32 `json:"maxKeys,omitempty"`
Prefix string `json:"prefix,omitempty"`
RequestPayer string `json:"request_payer,omitempty"`
FetchOwner bool `json:"fetch_owner,omitempty"`
}
type ListObjectsOutput struct {
CommonPrefixes []string `json:"common_prefixes,omitempty"`
Expand All @@ -254,6 +255,7 @@ type Object struct {
Owner *Owner `json:"owner,omitempty"`
Size int64 `json:"size,omitempty"`
StorageClass string `json:"storage_class,omitempty"`
Type string `json:"type,omitempty"`
}
type Owner struct {
DisplayName string `json:"display_name,omitempty"`
Expand Down
36 changes: 36 additions & 0 deletions pkg/grpc/extension/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ func TestListObjects(t *testing.T) {
MaxKeys: 1,
Prefix: "Prefix",
RequestPayer: "RequestPayer",
FetchOwner: true,
}
_, err := s3Server.ListObjects(ctx, req)
assert.Equal(t, status.Errorf(codes.InvalidArgument, NotSupportStoreName, "NoStore"), err)
Expand All @@ -354,13 +355,48 @@ func TestListObjects(t *testing.T) {
MaxKeys: 1,
Prefix: "Prefix",
RequestPayer: "RequestPayer",
FetchOwner: true,
},
).Return(output, nil)
req.StoreName = MOCKSERVER
resp, err := s3Server.ListObjects(ctx, req)
assert.Nil(t, err)
assert.Equal(t, true, resp.IsTruncated)
assert.Equal(t, "delimiter", resp.Delimiter)

ctx = context.TODO()
req = &s3.ListObjectsInput{
StoreName: "NoStore",
Bucket: "layotto",
Delimiter: "delimiter",
EncodingType: "EncodingType",
ExpectedBucketOwner: "ExpectedBucketOwner",
Marker: "Marker",
MaxKeys: 1,
Prefix: "Prefix",
RequestPayer: "RequestPayer",
}
_, err = s3Server.ListObjects(ctx, req)
assert.Equal(t, status.Errorf(codes.InvalidArgument, NotSupportStoreName, "NoStore"), err)
output = &l8s3.ListObjectsOutput{Delimiter: "delimiter", IsTruncated: true}
mockossServer.EXPECT().ListObjects(ctx,
&l8s3.ListObjectsInput{
Bucket: "layotto",
Delimiter: "delimiter",
EncodingType: "EncodingType",
ExpectedBucketOwner: "ExpectedBucketOwner",
Marker: "Marker",
MaxKeys: 1,
Prefix: "Prefix",
RequestPayer: "RequestPayer",
FetchOwner: false,
},
).Return(output, nil)
req.StoreName = MOCKSERVER
resp, err = s3Server.ListObjects(ctx, req)
assert.Nil(t, err)
assert.Equal(t, true, resp.IsTruncated)
assert.Equal(t, "delimiter", resp.Delimiter)
}

// TestGetObjectCannedAcl
Expand Down
Loading

0 comments on commit b4fed4d

Please sign in to comment.