Skip to content

Commit

Permalink
feat: Added the standard storage class to all the available get/list …
Browse files Browse the repository at this point in the history
…actions responses in posix. (#765)
  • Loading branch information
0x180 authored Aug 27, 2024
1 parent 3ed7c18 commit d79f978
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 86 deletions.
2 changes: 1 addition & 1 deletion backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func (az *Azure) GetObjectAttributes(ctx context.Context, input *s3.GetObjectAtt
ETag: data.ETag,
LastModified: data.LastModified,
ObjectSize: data.ContentLength,
StorageClass: &data.StorageClass,
StorageClass: data.StorageClass,
VersionId: data.VersionId,
}, nil
}
Expand Down
17 changes: 13 additions & 4 deletions backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,10 @@ func (p *Posix) ListMultipartUploads(_ context.Context, mpu *s3.ListMultipartUpl
keyMarkerInd = len(uploads)
}
uploads = append(uploads, s3response.Upload{
Key: objectName,
UploadID: uploadID,
Initiated: fi.ModTime(),
Key: objectName,
UploadID: uploadID,
StorageClass: types.StorageClassStandard,
Initiated: fi.ModTime(),
})
}
}
Expand Down Expand Up @@ -1120,6 +1121,7 @@ func (p *Posix) ListParts(_ context.Context, input *s3.ListPartsInput) (s3respon
PartNumberMarker: partNumberMarker,
Parts: parts,
UploadID: uploadID,
StorageClass: types.StorageClassStandard,
}, nil
}

Expand Down Expand Up @@ -1723,6 +1725,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
Metadata: userMetaData,
TagCount: tagCount,
ContentRange: &contentRange,
StorageClass: types.StorageClassStandard,
}, nil
}

Expand Down Expand Up @@ -1766,6 +1769,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
Metadata: userMetaData,
TagCount: tagCount,
ContentRange: &contentRange,
StorageClass: types.StorageClassStandard,
Body: &backend.FileSectionReadCloser{R: rdr, F: f},
}, nil
}
Expand Down Expand Up @@ -1820,6 +1824,7 @@ func (p *Posix) HeadObject(ctx context.Context, input *s3.HeadObjectInput) (*s3.
ETag: &etag,
PartsCount: &partsCount,
ContentLength: &size,
StorageClass: types.StorageClassStandard,
}, nil
}

Expand Down Expand Up @@ -1896,6 +1901,7 @@ func (p *Posix) HeadObject(ctx context.Context, input *s3.HeadObjectInput) (*s3.
ObjectLockLegalHoldStatus: objectLockLegalHoldStatus,
ObjectLockMode: objectLockMode,
ObjectLockRetainUntilDate: objectLockRetainUntilDate,
StorageClass: types.StorageClassStandard,
}, nil
}

Expand All @@ -1909,7 +1915,7 @@ func (p *Posix) GetObjectAttributes(ctx context.Context, input *s3.GetObjectAttr
ETag: data.ETag,
LastModified: data.LastModified,
ObjectSize: data.ContentLength,
StorageClass: &data.StorageClass,
StorageClass: data.StorageClass,
VersionId: data.VersionId,
}, nil
}
Expand Down Expand Up @@ -1960,6 +1966,7 @@ func (p *Posix) GetObjectAttributes(ctx context.Context, input *s3.GetObjectAttr
NextPartNumberMarker: resp.NextPartNumberMarker,
Parts: parts,
},
StorageClass: types.StorageClassStandard,
}, nil
}

Expand Down Expand Up @@ -2162,6 +2169,7 @@ func (p *Posix) fileToObj(bucket string) backend.GetObjFunc {
Key: &path,
LastModified: &mtime,
Size: &size,
StorageClass: types.ObjectStorageClassStandard,
}, nil
}

Expand Down Expand Up @@ -2194,6 +2202,7 @@ func (p *Posix) fileToObj(bucket string) backend.GetObjFunc {
Key: &path,
LastModified: &mtime,
Size: &size,
StorageClass: types.ObjectStorageClassStandard,
}, nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions backend/s3proxy/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *S3Proxy) ListMultipartUploads(ctx context.Context, input *s3.ListMultip
ID: *u.Owner.ID,
DisplayName: *u.Owner.DisplayName,
},
StorageClass: string(u.StorageClass),
StorageClass: u.StorageClass,
Initiated: *u.Initiated,
})
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func (s *S3Proxy) ListParts(ctx context.Context, input *s3.ListPartsInput) (s3re
ID: *output.Owner.ID,
DisplayName: *output.Owner.DisplayName,
},
StorageClass: string(output.StorageClass),
StorageClass: output.StorageClass,
PartNumberMarker: pnm,
NextPartNumberMarker: npmn,
MaxParts: int(*output.MaxParts),
Expand Down Expand Up @@ -362,7 +362,7 @@ func (s *S3Proxy) GetObjectAttributes(ctx context.Context, input *s3.GetObjectAt
ETag: out.ETag,
LastModified: out.LastModified,
ObjectSize: out.ObjectSize,
StorageClass: &out.StorageClass,
StorageClass: out.StorageClass,
VersionId: out.VersionId,
ObjectParts: &parts,
}, handleError(err)
Expand Down
79 changes: 45 additions & 34 deletions s3api/controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,57 +419,66 @@ func (c S3ApiController) GetActions(ctx *fiber.Ctx) error {
})
}

utils.SetMetaHeaders(ctx, res.Metadata)
var lastmod string
if res.LastModified != nil {
lastmod = res.LastModified.Format(timefmt)
}

contentType := getstring(res.ContentType)
if contentType == "" {
contentType = defaultContentType
}
acceptRanges := getstring(res.AcceptRanges)
if acceptRanges == "" {
acceptRanges = "bytes"
}

utils.SetResponseHeaders(ctx, []utils.CustomHeader{
hdrs := []utils.CustomHeader{
{
Key: "Content-Type",
Value: contentType,
},
{
Key: "Content-Encoding",
Value: getstring(res.ContentEncoding),
},
{
Key: "ETag",
Value: getstring(res.ETag),
},
{
Key: "Last-Modified",
Value: lastmod,
},
{
Key: "x-amz-storage-class",
Value: string(res.StorageClass),
},
{
Key: "Content-Range",
Value: getstring(res.ContentRange),
},
{
Key: "accept-ranges",
Value: getstring(res.AcceptRanges),
Value: acceptRanges,
},
})
}

if getstring(res.ContentRange) != "" {
hdrs = append(hdrs, utils.CustomHeader{
Key: "Content-Range",
Value: getstring(res.ContentRange),
})
}
if res.LastModified != nil {
hdrs = append(hdrs, utils.CustomHeader{
Key: "Last-Modified",
Value: res.LastModified.Format(timefmt),
})
}
if getstring(res.ContentEncoding) != "" {
hdrs = append(hdrs, utils.CustomHeader{
Key: "Content-Encoding",
Value: getstring(res.ContentEncoding),
})
}
if res.TagCount != nil {
utils.SetResponseHeaders(ctx, []utils.CustomHeader{
{
Key: "x-amz-tagging-count",
Value: fmt.Sprint(*res.TagCount),
},
hdrs = append(hdrs, utils.CustomHeader{
Key: "x-amz-tagging-count",
Value: fmt.Sprint(*res.TagCount),
})
}
if res.StorageClass != "" {
hdrs = append(hdrs, utils.CustomHeader{
Key: "x-amz-storage-class",
Value: string(res.StorageClass),
})
}

// Set x-amz-meta-... headers
utils.SetMetaHeaders(ctx, res.Metadata)
// Set other response headers
utils.SetResponseHeaders(ctx, hdrs)

status := http.StatusOK
if acceptRange != "" {
status = http.StatusPartialContent
Expand Down Expand Up @@ -2751,10 +2760,6 @@ func (c S3ApiController) HeadObject(ctx *fiber.Ctx) error {
Key: "ETag",
Value: getstring(res.ETag),
},
{
Key: "x-amz-storage-class",
Value: string(res.StorageClass),
},
{
Key: "x-amz-restore",
Value: getstring(res.Restore),
Expand Down Expand Up @@ -2798,6 +2803,12 @@ func (c S3ApiController) HeadObject(ctx *fiber.Ctx) error {
Value: getstring(res.ContentEncoding),
})
}
if res.StorageClass != "" {
headers = append(headers, utils.CustomHeader{
Key: "x-amz-storage-class",
Value: string(res.StorageClass),
})
}

contentType := getstring(res.ContentType)
if contentType == "" {
Expand Down
2 changes: 1 addition & 1 deletion s3api/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func FilterObjectAttributes(attrs map[types.ObjectAttributes]struct{}, output s3
output.ObjectSize = nil
}
if _, ok := attrs[types.ObjectAttributesStorageClass]; !ok {
output.StorageClass = nil
output.StorageClass = ""
}

return output
Expand Down
6 changes: 3 additions & 3 deletions s3response/s3response.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ListPartsResult struct {
Owner Owner

// The class of storage used to store the object.
StorageClass string
StorageClass types.StorageClass

PartNumberMarker int
NextPartNumberMarker int
Expand All @@ -72,7 +72,7 @@ type GetObjectAttributesResult struct {
ETag *string
LastModified *time.Time
ObjectSize *int64
StorageClass *types.StorageClass
StorageClass types.StorageClass
VersionId *string
ObjectParts *ObjectParts
}
Expand Down Expand Up @@ -170,7 +170,7 @@ type Upload struct {
UploadID string `xml:"UploadId"`
Initiator Initiator
Owner Owner
StorageClass string
StorageClass types.StorageClass
Initiated time.Time
}

Expand Down
Loading

0 comments on commit d79f978

Please sign in to comment.