Phase 9, part 5: file storage, a folder or an S3 bucket
internal/storage keeps files that must outlast the app's disk (exports, uploads) behind one interface: a folder (<data>/files) or an S3-compatible bucket (minio-go, path-style, for Garage). Names that would reach outside the store are refused. An S3 store is checked at start; supermarket config checks the storage and Postgres for real. The same tests run on a folder and on Garage (SUPERMARKET_TEST_S3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,7 +217,7 @@ func Load(getenv func(string) string) (*Config, error) {
|
||||
func loadStorage(get func(string, string) string, bad func(string, ...any), dataDir string) Storage {
|
||||
v := get(EnvStorage, "")
|
||||
if v == "" {
|
||||
return Storage{Dir: dataDir}
|
||||
return Storage{Dir: filepath.Join(dataDir, "files")}
|
||||
}
|
||||
if !strings.HasPrefix(v, "s3://") {
|
||||
if !filepath.IsAbs(v) {
|
||||
@@ -333,10 +333,10 @@ func (c *Config) Summary() []Item {
|
||||
default:
|
||||
items = append(items, Item{"Database", "Postgres: " + RedactURL(c.DatabaseURL), EnvDatabaseURL + "."})
|
||||
}
|
||||
files := Item{"Files", c.Storage.String(), "Backups, exports and uploads (" + EnvStorage + ")."}
|
||||
if !c.Storage.S3() && c.Storage.Dir == c.DataDir {
|
||||
files.Value = c.HostData
|
||||
files.Help = "The data folder."
|
||||
files := Item{"Files", c.Storage.String(), "Exports and uploaded files (" + EnvStorage + ")."}
|
||||
if !c.Storage.S3() && c.Storage.Dir == filepath.Join(c.DataDir, "files") {
|
||||
files.Value = filepath.Join(c.HostData, "files")
|
||||
files.Help = "Exports and uploaded files, in the data folder."
|
||||
}
|
||||
items = append(items, files)
|
||||
switch {
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestLocalDefaults(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.Edition != Local || c.DataDir != "/data" || c.Addr != ":8080" || c.PublicURL != "http://localhost:8470" ||
|
||||
c.Storage.Dir != "/data" || c.Storage.S3() || c.Mail != nil || c.SecretKey != nil || c.DatabaseURL != "" {
|
||||
c.Storage.Dir != "/data/files" || c.Storage.S3() || c.Mail != nil || c.SecretKey != nil || c.DatabaseURL != "" {
|
||||
t.Fatalf("%+v", c)
|
||||
}
|
||||
if c.CoreConf != "/data/core.conf" || c.MCPSocket != "/data/mcp.sock" || c.HostData != "/data" {
|
||||
@@ -76,7 +76,7 @@ func TestServer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.Edition != Server || len(c.SecretKey) != 32 || c.Storage.Dir != "/data" {
|
||||
if c.Edition != Server || len(c.SecretKey) != 32 || c.Storage.Dir != "/data/files" {
|
||||
t.Fatalf("%+v", c)
|
||||
}
|
||||
m := c.Mail
|
||||
|
||||
Reference in New Issue
Block a user