From f5a90a8dd208596aa8ce8cfd3086bd367b84b147 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 17 Apr 2023 10:50:05 -0400 Subject: [PATCH] 19620: Remove goamz dependency in non-testing code. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/keep-web/s3.go | 52 +++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/services/keep-web/s3.go b/services/keep-web/s3.go index f98efd8fdf..38428cdab1 100644 --- a/services/keep-web/s3.go +++ b/services/keep-web/s3.go @@ -28,7 +28,6 @@ import ( "git.arvados.org/arvados.git/sdk/go/arvados" "git.arvados.org/arvados.git/sdk/go/ctxlog" - "github.com/AdRoll/goamz/s3" ) const ( @@ -42,11 +41,17 @@ type commonPrefix struct { } type listV1Resp struct { - XMLName string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult"` - s3.ListResp - // s3.ListResp marshals an empty tag when - // CommonPrefixes is nil, which confuses some clients. - // Fix by using this nested struct instead. + XMLName string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult"` + Name string + Prefix string + Delimiter string + Marker string + MaxKeys int + IsTruncated bool + Contents []s3Key + // If we use a []string here, xml marshals an empty tag when + // CommonPrefixes is nil, which confuses some clients. Fix by + // using this nested struct instead. CommonPrefixes []commonPrefix // Similarly, we need omitempty here, because an empty // tag confuses some clients (e.g., @@ -60,7 +65,7 @@ type listV1Resp struct { type listV2Resp struct { XMLName string `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult"` IsTruncated bool - Contents []s3.Key + Contents []s3Key Name string Prefix string Delimiter string @@ -73,6 +78,21 @@ type listV2Resp struct { StartAfter string `xml:",omitempty"` } +type s3Key struct { + Key string + LastModified string + Size int64 + // The following fields are not populated, but are here in + // case clients rely on the keys being present in xml + // responses. + ETag string + StorageClass string + Owner struct { + ID string + DisplayName string + } +} + func hmacstring(msg string, key []byte) []byte { h := hmac.New(sha256.New, key) io.WriteString(h, msg) @@ -859,7 +879,7 @@ func (h *handler) s3list(bucket string, w http.ResponseWriter, r *http.Request, return filepath.SkipDir } } - resp.Contents = append(resp.Contents, s3.Key{ + resp.Contents = append(resp.Contents, s3Key{ Key: path, LastModified: fi.ModTime().UTC().Format("2006-01-02T15:04:05.999") + "Z", Size: filesize, @@ -923,15 +943,13 @@ func (h *handler) s3list(bucket string, w http.ResponseWriter, r *http.Request, CommonPrefixes: resp.CommonPrefixes, NextMarker: nextMarker, KeyCount: resp.KeyCount, - ListResp: s3.ListResp{ - IsTruncated: resp.IsTruncated, - Name: bucket, - Prefix: params.prefix, - Delimiter: params.delimiter, - Marker: params.marker, - MaxKeys: params.maxKeys, - Contents: resp.Contents, - }, + IsTruncated: resp.IsTruncated, + Name: bucket, + Prefix: params.prefix, + Delimiter: params.delimiter, + Marker: params.marker, + MaxKeys: params.maxKeys, + Contents: resp.Contents, } } -- 2.30.2