Skip to content
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
23 changes: 21 additions & 2 deletions go/cli/mcap/utils/readers/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"os"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -15,8 +17,15 @@ func init() {
RegisterReader("s3", newS3Reader)
}

func forcePathStyle() bool {
value := strings.TrimSpace(strings.ToLower(os.Getenv("MCAP_S3_FORCE_PATH_STYLE")))
return value == "1" || value == "true" || value == "yes"
}

// Factory for S3 readers (called by registry).
func newS3Reader(ctx context.Context, bucket, path string) (func() error, io.ReadSeekCloser, error) {
pathStyle := forcePathStyle()

// Try anonymous first
cfg, err := config.LoadDefaultConfig(ctx,
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
Expand All @@ -25,7 +34,12 @@ func newS3Reader(ctx context.Context, bucket, path string) (func() error, io.Rea
return func() error { return nil }, nil, fmt.Errorf("failed to load AWS config: %w", err)
}

client := s3.NewFromConfig(cfg)
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
if pathStyle {
o.UsePathStyle = true
}
})

rs, err := NewS3ReadSeekCloser(ctx, client, bucket, path)
if err == nil {
return rs.Close, rs, nil
Expand All @@ -37,7 +51,12 @@ func newS3Reader(ctx context.Context, bucket, path string) (func() error, io.Rea
return func() error { return nil }, nil, fmt.Errorf("failed to load authenticated AWS config: %w", err)
}

client = s3.NewFromConfig(cfg)
client = s3.NewFromConfig(cfg, func(o *s3.Options) {
if pathStyle {
o.UsePathStyle = true
}
})

rs, err = NewS3ReadSeekCloser(ctx, client, bucket, path)
if err != nil {
return func() error { return nil }, nil, fmt.Errorf("failed to create S3 reader: %w", err)
Expand Down
17 changes: 17 additions & 0 deletions website/docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ When reading from S3 you must specify the region of the bucket:
AWS_REGION=eu-north-1 mcap info s3://my-public-bucket/demo.mcap
```

Some S3-compatible storage systems require path-style addressing instead of the default virtual-host style. To enable this behavior, set the following environment variable:

```bash
MCAP_S3_FORCE_PATH_STYLE=true
```

Example:

```bash
MCAP_S3_FORCE_PATH_STYLE=true \
AWS_REGION=eu-north-1 \
AWS_ENDPOINT_URL_S3=https://s3.example.com:9000 \
AWS_ACCESS_KEY_ID=... \
AWS_SECRET_ACCESS_KEY=... \
mcap info s3://my-bucket/demo.mcap
```

Remote reads will use the index at the end of the file to minimize latency and data transfer.

### File Diagnostics
Expand Down
Loading