From bee6f278ba88246f1e8899e3f768533cac88870c Mon Sep 17 00:00:00 2001 From: Elliot Chen Date: Tue, 30 Jan 2024 19:07:16 +0800 Subject: [PATCH] fix: the same-storage check in the new `pre-sign` feature (#2860) * fix: error check for the same oss-storage * fix: conflict error2 variable in code refactor in s3.go * chore: rename endpointUrl to endpointURL --- plugin/storage/s3/s3.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/storage/s3/s3.go b/plugin/storage/s3/s3.go index b94efa83..0398bb6d 100644 --- a/plugin/storage/s3/s3.go +++ b/plugin/storage/s3/s3.go @@ -77,7 +77,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType ContentType: aws.String(fileType), } // Set ACL according to if url prefix is set. - if client.Config.URLPrefix == "" { + if client.Config.URLPrefix == "" && !client.Config.PreSign { putInput.ACL = types.ObjectCannedACL(*aws.String("public-read")) } uploadOutput, err := uploader.Upload(ctx, &putInput) @@ -113,7 +113,15 @@ func (client *Client) PreSignLink(ctx context.Context, sourceLink string) (strin } // if link doesn't belong to storage, then return as-is. // the empty hostname is corner-case for AWS native endpoint. - if client.Config.EndPoint != "" && !strings.Contains(client.Config.EndPoint, u.Hostname()) { + endpointURL, err := url.Parse(client.Config.EndPoint) + if err != nil { + return "", errors.Wrapf(err, "parse Endpoint URL") + } + endpointHost := endpointURL.Hostname() + if client.Config.Bucket != "" && !strings.Contains(endpointHost, client.Config.Bucket) { + endpointHost = fmt.Sprintf("%s.%s", client.Config.Bucket, endpointHost) + } + if client.Config.EndPoint != "" && !strings.Contains(endpointHost, u.Hostname()) { return sourceLink, nil }