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

Add support for StorageClass #1826

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ObjectAttrs struct {
BucketName string
Name string
Size int64
StorageClass string
ContentType string
ContentEncoding string
ContentDisposition string
Expand Down Expand Up @@ -59,6 +60,7 @@ type jsonObject struct {
BucketName string `json:"bucket"`
Name string `json:"name"`
Size int64 `json:"size,string"`
StorageClass string `json:"storageClass"`
ContentType string `json:"contentType"`
ContentEncoding string `json:"contentEncoding"`
ContentDisposition string `json:"contentDisposition"`
Expand All @@ -79,6 +81,7 @@ func (o ObjectAttrs) MarshalJSON() ([]byte, error) {
temp := jsonObject{
BucketName: o.BucketName,
Name: o.Name,
StorageClass: o.StorageClass,
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
Expand Down Expand Up @@ -108,6 +111,7 @@ func (o *ObjectAttrs) UnmarshalJSON(data []byte) error {
}
o.BucketName = temp.BucketName
o.Name = temp.Name
o.StorageClass = temp.StorageClass
o.ContentType = temp.ContentType
o.ContentEncoding = temp.ContentEncoding
o.ContentDisposition = temp.ContentDisposition
Expand Down Expand Up @@ -394,6 +398,7 @@ func toBackendObjects(objects []StreamingObject) []backend.StreamingObject {
ObjectAttrs: backend.ObjectAttrs{
BucketName: o.BucketName,
Name: o.Name,
StorageClass: o.StorageClass,
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
Expand All @@ -420,6 +425,7 @@ func bufferedObjectsToBackendObjects(objects []Object) []backend.StreamingObject
ObjectAttrs: backend.ObjectAttrs{
BucketName: o.BucketName,
Name: o.Name,
StorageClass: o.StorageClass,
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
Expand Down Expand Up @@ -449,6 +455,7 @@ func fromBackendObjects(objects []backend.StreamingObject) []StreamingObject {
BucketName: o.BucketName,
Name: o.Name,
Size: o.Size,
StorageClass: o.StorageClass,
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
Expand Down Expand Up @@ -477,6 +484,7 @@ func fromBackendObjectsAttrs(objectAttrs []backend.ObjectAttrs) []ObjectAttrs {
BucketName: o.BucketName,
Name: o.Name,
Size: o.Size,
StorageClass: o.StorageClass,
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
Expand Down
15 changes: 15 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type objectTestCases []struct {
func getObjectTestCases() objectTestCases {
const (
bucketName = "some-bucket"
storageClass = "COLDLINE"
content = "some nice content"
contentType = "text/plain; charset=utf-8"
contentEncoding = "gzip"
Expand Down Expand Up @@ -129,6 +130,17 @@ func getObjectTestCases() objectTestCases {
},
},
},
{
"object with no contents neither dates",
Object{
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: "video/hi-res/best_video_1080p.mp4",
ContentType: "text/html; charset=utf-8",
StorageClass: "COLDLINE",
},
},
},
}
return tests
}
Expand All @@ -148,6 +160,9 @@ func checkObjectAttrs(testObj Object, attrs *storage.ObjectAttrs, t *testing.T)
if attrs.Name != testObj.Name {
t.Errorf("wrong object name\nwant %q\ngot %q", testObj.Name, attrs.Name)
}
if testObj.StorageClass != "" && attrs.StorageClass != testObj.StorageClass {
t.Errorf("wrong object storage class\nwant %q\ngot %q", testObj.StorageClass, attrs.StorageClass)
}
if !(testObj.Created.IsZero()) && !testObj.Created.Equal(attrs.Created) {
t.Errorf("wrong created date\nwant %v\ngot %v\nname %v", testObj.Created, attrs.Created, attrs.Name)
}
Expand Down
6 changes: 5 additions & 1 deletion fakestorage/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func newProjectedObjectResponse(obj ObjectAttrs, externalURL string, projection

func newObjectResponse(obj ObjectAttrs, externalURL string) objectResponse {
acl := getAccessControlsListFromObject(obj)
storageClass := obj.StorageClass
if storageClass == "" {
storageClass = "STANDARD"
}

return objectResponse{
Kind: "storage#object",
Expand All @@ -160,7 +164,7 @@ func newObjectResponse(obj ObjectAttrs, externalURL string) objectResponse {
Md5Hash: obj.Md5Hash,
Etag: obj.Etag,
ACL: acl,
StorageClass: "STANDARD",
StorageClass: storageClass,
Metadata: obj.Metadata,
TimeCreated: formatTime(obj.Created),
TimeDeleted: formatTime(obj.Deleted),
Expand Down
2 changes: 2 additions & 0 deletions fakestorage/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type multipartMetadata struct {
CacheControl string `json:"cacheControl"`
CustomTime time.Time `json:"customTime,omitempty"`
Name string `json:"name"`
StorageClass string `json:"storageClass"`
Metadata map[string]string `json:"metadata"`
}

Expand Down Expand Up @@ -378,6 +379,7 @@ func (s *Server) multipartUpload(bucketName string, r *http.Request) jsonRespons
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: objName,
StorageClass: metadata.StorageClass,
ContentType: contentType,
CacheControl: metadata.CacheControl,
ContentEncoding: metadata.ContentEncoding,
Expand Down
1 change: 1 addition & 0 deletions internal/backend/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ObjectAttrs struct {
BucketName string `json:"-"`
Name string `json:"-"`
Size int64 `json:"-"`
StorageClass string
ContentType string
ContentEncoding string
ContentDisposition string
Expand Down
1 change: 1 addition & 0 deletions internal/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (g *Server) GetObject(ctx context.Context, req *pb.GetObjectRequest) (*pb.O
return &pb.Object{
Name: obj.ObjectAttrs.Name,
Bucket: obj.ObjectAttrs.BucketName,
StorageClass: obj.ObjectAttrs.StorageClass,
Md5Hash: obj.ObjectAttrs.Md5Hash,
Generation: obj.ObjectAttrs.Generation,
ContentType: obj.ObjectAttrs.ContentType,
Expand Down