feat(storage): add private file layer and isolate SeaweedFS on a storage network

This commit is contained in:
shira committed 2026-10-06 13:51:53 +03:00
1 parent f5b07e8f4d
commit 8378ad45b0
22 files changed
+1668 -40

No files matched your search

@@ -40,6 +40,12 @@ var (
)
// NewStorage creates a lazy S3 client. Deployment owns bucket provisioning.
//
// SEAWEEDFS_TIMEOUT bounds connection setup, the TLS handshake, the wait for
// response headers, and whole Delete and readiness calls. It does not bound
// object body transfer in Put and Get: the duration depends on file size and
// client speed, which only the caller knows, so the caller's context and the
// source deadline govern the stream.
func NewStorage(settings config.Config) (*Storage, func(), error) {
if err := settings.ValidateSeaweedFS(); err != nil {
return nil, nil, err
@@ -60,9 +66,9 @@ func NewStorage(settings config.Config) (*Storage, func(), error) {
BaseEndpoint: aws.String(settings.SeaweedFSEndpoint),
UsePathStyle: true,
Credentials: credentials.NewStaticCredentialsProvider(settings.SeaweedFSAccessKey, settings.SeaweedFSSecretKey, ""),
// No Client.Timeout: it would cut long object bodies; see above.
HTTPClient: &http.Client{
Transport: transport,
Timeout: settings.SeaweedFSTimeout,
CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },
},
// A non-seekable upload cannot be replayed safely.
@@ -78,8 +84,6 @@ func (storage *Storage) Put(ctx context.Context, key string, body io.Reader, siz
if key == "" || body == nil || size < 0 {
return fmt.Errorf("Storage.Put - validate input: %w", outbound.ErrInvalidObject)
}
ctx, cancel := context.WithTimeout(ctx, storage.timeout)
defer cancel()
_, err := storage.client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(storage.bucket),
Key: aws.String(key),
@@ -97,7 +101,9 @@ func (storage *Storage) Get(ctx context.Context, key string) (outbound.Object, e
if key == "" {
return outbound.Object{}, fmt.Errorf("Storage.Get - validate key: %w", outbound.ErrInvalidObject)
}
ctx, cancel := context.WithTimeout(ctx, storage.timeout)
// Close or a read error cancels the request; the transfer itself is bounded
// only by the caller's context.
ctx, cancel := context.WithCancel(ctx)
result, err := storage.client.GetObject(ctx, &s3.GetObjectInput{Bucket: aws.String(storage.bucket), Key: aws.String(key)})
if err != nil {
cancel()