4 Commits

Author SHA1 Message Date
releaser a4dedab2f5 chore(release): prepare for v0.4.0 (#100)
Release / release (push) Successful in 46s
storage / test (push) Successful in 1m40s
storage / vulnerabilities (push) Successful in 1m53s
pre-commit / pre-commit (push) Successful in 7m20s
## [0.4.0] - 2026-04-17

### 🚀 Features

- Auto-enable path-style addressing when a custom endpoint is set (#99)

<!-- generated by git-cliff -->

---

**Note:** Please use **Squash Merge** when merging this PR.

Reviewed-on: #100
Co-authored-by: Unbound Releaser <releaser@unbound.se>
Co-committed-by: Unbound Releaser <releaser@unbound.se>
2026-04-17 17:31:17 +00:00
argoyle 1620565ae6 feat: auto-enable path-style addressing when a custom endpoint is set (#99)
Release / release (push) Successful in 52s
storage / test (push) Successful in 1m46s
storage / vulnerabilities (push) Successful in 1m46s
pre-commit / pre-commit (push) Successful in 6m26s
## Summary

When `AWS_ENDPOINT_URL_S3` or `AWS_ENDPOINT_URL` is set — typically because the runtime is pointing at a local MinIO / S3-compatible endpoint — auto-enable path-style addressing on the S3 client. Without this, requests fail because MinIO does not implement virtual-hosted style addressing out of the box.

Production deployments leave those env vars unset and continue talking to real AWS S3 with virtual-hosted style — no behaviour change for prod.

Both `New()` and `NewS3()` share a `s3ClientOptions` helper that applies the toggle.

## Motivation

Spinning up a MinIO-backed acctest environment for Shiny (document-service, invoice-service, accounting-service). Without this change callers would have to sidestep `storage.New` and construct an `aws.Config` by hand just to flip `UsePathStyle`.

## Test plan

- [x] New unit test `TestS3ClientOptions_PathStyleTogglesOnCustomEndpoint` covers the three relevant env-var states
- [x] `go test ./...` passes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #99
2026-04-17 17:18:53 +00:00
releaser 7539b5db24 chore(release): prepare for v0.3.0 (#98)
storage / test (push) Successful in 1m36s
Release / release (push) Successful in 1m56s
storage / vulnerabilities (push) Successful in 2m45s
pre-commit / pre-commit (push) Successful in 6m21s
## [0.3.0] - 2026-04-16

### 🚀 Features

- Add PresignInlineURL method for inline content display (#97)

<!-- generated by git-cliff -->

---

**Note:** Please use **Squash Merge** when merging this PR.

Reviewed-on: #98
Co-authored-by: Unbound Releaser <releaser@unbound.se>
Co-committed-by: Unbound Releaser <releaser@unbound.se>
2026-04-16 09:03:25 +00:00
argoyle 862ec3f7bc feat: add PresignInlineURL method for inline content display (#97)
storage / vulnerabilities (push) Successful in 1m43s
storage / test (push) Successful in 1m44s
Release / release (push) Successful in 58s
pre-commit / pre-commit (push) Successful in 6m14s
## Summary

- Add `PresignInlineURL(ctx, key, contentType)` method that generates presigned URLs with `Content-Disposition: inline` and optional `Content-Type` override
- Browsers will render content (e.g. PDFs) directly in iframes instead of triggering download dialogs
- Existing `PresignURL` remains unchanged

## Context

The document-service uses presigned S3 URLs to display PDFs in iframes. Without `Content-Disposition: inline`, the browser triggers a download dialog instead of rendering the PDF.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #97
2026-04-16 08:52:38 +00:00
4 changed files with 77 additions and 3 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
{
"version": "v0.2.0"
"version": "v0.4.0"
}
+12
View File
@@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
## [0.4.0] - 2026-04-17
### 🚀 Features
- Auto-enable path-style addressing when a custom endpoint is set (#99)
## [0.3.0] - 2026-04-16
### 🚀 Features
- Add PresignInlineURL method for inline content display (#97)
## [0.2.0] - 2026-04-16
### 🚀 Features
+35 -2
View File
@@ -3,6 +3,7 @@ package storage
import (
"context"
"io"
"os"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
@@ -12,6 +13,19 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
)
// s3ClientOptions returns the per-client overrides applied to every S3 client
// constructed by this package. When the AWS_ENDPOINT_URL_S3 (or
// AWS_ENDPOINT_URL) env var is set — typically because the runtime is
// pointing at a local MinIO/S3-compatible endpoint — path-style addressing
// is enabled so requests look like `http://host:9000/bucket/key` instead of
// `http://bucket.host:9000/key`. Production deployments leave those vars
// unset and continue talking to real S3 with virtual-hosted style.
func s3ClientOptions(o *s3.Options) {
if os.Getenv("AWS_ENDPOINT_URL_S3") != "" || os.Getenv("AWS_ENDPOINT_URL") != "" {
o.UsePathStyle = true
}
}
// Uploader is the interface for uploading objects to S3 using the transfer manager
type Uploader interface {
UploadObject(ctx context.Context, input *transfermanager.UploadObjectInput, opts ...func(*transfermanager.Options)) (*transfermanager.UploadObjectOutput, error)
@@ -105,6 +119,25 @@ func (s *S3) PresignURL(ctx context.Context, key string) (string, error) {
return req.URL, nil
}
// PresignInlineURL generates a presigned URL that tells the browser to display
// the content inline rather than triggering a download. The URL is valid for
// 15 minutes.
func (s *S3) PresignInlineURL(ctx context.Context, key string, contentType string) (string, error) {
input := &s3.GetObjectInput{
Bucket: aws.String(s.bucket),
Key: aws.String(key),
ResponseContentDisposition: aws.String("inline"),
}
if contentType != "" {
input.ResponseContentType = aws.String(contentType)
}
req, err := s.presigner.PresignGetObject(ctx, input, s3.WithPresignExpires(15*time.Minute))
if err != nil {
return "", err
}
return req.URL, nil
}
// New creates a new S3 storage instance using the upload manager
// This loads AWS config from the default locations and is suitable for most use cases
func New(bucket string) (*S3, error) {
@@ -112,7 +145,7 @@ func New(bucket string) (*S3, error) {
if err != nil {
return nil, err
}
client := s3.NewFromConfig(cfg)
client := s3.NewFromConfig(cfg, s3ClientOptions)
uploader := transfermanager.New(client, func(o *transfermanager.Options) {
o.PartSizeBytes = 5 * 1024 * 1024
})
@@ -128,7 +161,7 @@ func New(bucket string) (*S3, error) {
// NewS3 creates a new S3 storage instance using direct PutObject
// This is useful when you want more control over the AWS configuration
func NewS3(cfg aws.Config, bucket string) *S3 {
client := s3.NewFromConfig(cfg)
client := s3.NewFromConfig(cfg, s3ClientOptions)
return &S3{
bucket: bucket,
directSvc: client,
+29
View File
@@ -40,6 +40,35 @@ func (m *mockPresigner) PresignGetObject(ctx context.Context, params *s3.GetObje
return m.presignFunc(ctx, params, optFns...)
}
// Test path-style toggle
func TestS3ClientOptions_PathStyleTogglesOnCustomEndpoint(t *testing.T) {
cases := []struct {
name string
envVar string
value string
expected bool
}{
{name: "no env var → virtual-hosted", envVar: "", expected: false},
{name: "AWS_ENDPOINT_URL_S3 set → path-style", envVar: "AWS_ENDPOINT_URL_S3", value: "http://minio:9000", expected: true},
{name: "AWS_ENDPOINT_URL set → path-style", envVar: "AWS_ENDPOINT_URL", value: "http://minio:9000", expected: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("AWS_ENDPOINT_URL", "")
t.Setenv("AWS_ENDPOINT_URL_S3", "")
if tc.envVar != "" {
t.Setenv(tc.envVar, tc.value)
}
opts := s3.Options{}
s3ClientOptions(&opts)
if opts.UsePathStyle != tc.expected {
t.Fatalf("UsePathStyle = %v, want %v", opts.UsePathStyle, tc.expected)
}
})
}
}
// Test NewS3 constructor
func TestNewS3(t *testing.T) {