Skip to content
Open
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
14 changes: 14 additions & 0 deletions pkg/storage/sos/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
"github.com/dustin/go-humanize"
"github.com/hashicorp/go-multierror"
"github.com/vbauerster/mpb/v4"
Expand Down Expand Up @@ -158,6 +159,19 @@ func (c *Client) GenPresignedURL(ctx context.Context, method, bucket, key string

switch method {
case "get":
// Check if the object exists
if _, err := c.S3Client.(*s3.Client).HeadObject(ctx, &s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}); err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
if apiErr.ErrorCode() == "NotFound" {
fmt.Printf("⚠️ The object %s/%s does not exist. The Presigned URL will return 404 ⚠️\n\n", bucket, key)
Comment on lines +169 to +170
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be logged as a warning on stderr (and without the emojis 🙂), so that the user can distinguish it from stdout, but since we don't currently have a good logging setup, it's fine.

}
}
}
Comment on lines +162 to +173
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using spaces instead of tabs.

Make sure to setup gofmt in your editor.

Suggested change
// Check if the object exists
if _, err := c.S3Client.(*s3.Client).HeadObject(ctx, &s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}); err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
if apiErr.ErrorCode() == "NotFound" {
fmt.Printf("⚠️ The object %s/%s does not exist. The Presigned URL will return 404 ⚠️\n\n", bucket, key)
}
}
}
// Check if the object exists
if _, err := c.S3Client.(*s3.Client).HeadObject(ctx, &s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}); err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) {
if apiErr.ErrorCode() == "NotFound" {
fmt.Printf("⚠️ The object %s/%s does not exist. The Presigned URL will return 404 ⚠️\n\n", bucket, key)
}
}
}


psURL, err = psClient.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Expand Down