Files
mtusi2026lab6/internal/config/objectstore.go
T

36 lines
1001 B
Go

package config
import (
"fmt"
"os"
)
// ObjectStore contains only the S3 adapter's connection settings.
type ObjectStore struct {
// Endpoint is host:port, without a URL scheme.
Endpoint string
// Bucket is the private application bucket.
Bucket string
// AccessKey is the restricted service identity.
AccessKey string
// SecretKey is supplied by the runtime secret provider.
SecretKey string
// Secure enables certificate-verified TLS.
Secure bool
}
// NewObjectStore validates S3 settings independently of their use.
func NewObjectStore() (*ObjectStore, error) {
cfg := &ObjectStore{
Endpoint: os.Getenv("S3_ENDPOINT"),
Bucket: os.Getenv("S3_BUCKET"),
AccessKey: os.Getenv("S3_ACCESS_KEY"),
SecretKey: os.Getenv("S3_SECRET_KEY"),
Secure: os.Getenv("S3_TLS") != "false",
}
if cfg.Endpoint == "" || cfg.Bucket == "" || cfg.AccessKey == "" || cfg.SecretKey == "" {
return nil, fmt.Errorf("S3 endpoint, bucket and scoped credentials required")
}
return cfg, nil
}