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

Implement a helper function on the S3 package to parse the S3 errors Responses #74

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

## Unreleased

### Added
- [#74](https://github.com/thanos-io/objstore/pull/74) S3: Implementing `ToErrorResponse` function to return the parsed S3 ErrorResponse.

### Fixed
- [#33](https://github.com/thanos-io/objstore/pull/33) Tracing: Add `ContextWithTracer()` to inject the tracer into the context.
- [#34](https://github.com/thanos-io/objstore/pull/34) Fix ignored options when creating shared credential Azure client.
Expand Down
34 changes: 34 additions & 0 deletions providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,37 @@ func NewTestBucketFromConfig(t testing.TB, location string, c Config, reuseBucke
func ContextWithSSEConfig(ctx context.Context, value encrypt.ServerSide) context.Context {
return context.WithValue(ctx, sseConfigKey, value)
}

/* **** SAMPLE ERROR RESPONSE ****
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<BucketName>bucketName</BucketName>
<Key>objectName</Key>
<RequestId>F19772218238A85A</RequestId>
<HostId>GuWkjyviSiGHizehqpmsD1ndz5NClSP19DOT+s2mv7gXGQ8/X1lhbDGiIJEXpGFD</HostId>
</Error>
*/

type ErrorResponse struct {
Code string
Message string
BucketName string
Key string
RequestId string
HostId string
}

// ToErrorResponse Returns parsed s3 ErrorResponse.
func ToErrorResponse(err error) ErrorResponse {
er := minio.ToErrorResponse(errors.Cause(err))
return ErrorResponse{
Code: er.Code,
Message: er.Message,
BucketName: er.BucketName,
Key: er.Key,
RequestId: er.RequestID,
HostId: er.HostID,
}
}
Loading