Skip to content

Commit 69937e0

Browse files
authored
feat: support storage s3 protocol config (#4545)
1 parent a1e6276 commit 69937e0

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

internal/start/start.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ func run(ctx context.Context, fsys afero.Fs, excludedContainers []string, dbConf
244244
}
245245

246246
var started []string
247-
var isStorageEnabled = utils.Config.Storage.Enabled && !isContainerExcluded(utils.Config.Storage.Image, excluded)
248-
var isImgProxyEnabled = utils.Config.Storage.ImageTransformation != nil &&
247+
isStorageEnabled := utils.Config.Storage.Enabled && !isContainerExcluded(utils.Config.Storage.Image, excluded)
248+
isImgProxyEnabled := utils.Config.Storage.ImageTransformation != nil &&
249249
utils.Config.Storage.ImageTransformation.Enabled && !isContainerExcluded(utils.Config.Storage.ImgProxyImage, excluded)
250+
isS3ProtocolEnabled := utils.Config.Storage.S3Protocol != nil && utils.Config.Storage.S3Protocol.Enabled
250251
fmt.Fprintln(os.Stderr, "Starting containers...")
251252

252253
// Start Logflare
@@ -997,6 +998,7 @@ EOF
997998
fmt.Sprintf("ENABLE_IMAGE_TRANSFORMATION=%t", isImgProxyEnabled),
998999
fmt.Sprintf("IMGPROXY_URL=http://%s:5001", utils.ImgProxyId),
9991000
"TUS_URL_PATH=/storage/v1/upload/resumable",
1001+
fmt.Sprintf("S3_PROTOCOL_ENABLED=%t", isS3ProtocolEnabled),
10001002
"S3_PROTOCOL_ACCESS_KEY_ID=" + utils.Config.Storage.S3Credentials.AccessKeyId,
10011003
"S3_PROTOCOL_ACCESS_KEY_SECRET=" + utils.Config.Storage.S3Credentials.SecretAccessKey,
10021004
"S3_PROTOCOL_PREFIX=/storage/v1",

internal/status/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *CustomName) toValues(exclude ...string) map[string]string {
8484
values[c.MailpitURL] = fmt.Sprintf("http://%s:%d", utils.Config.Hostname, utils.Config.Inbucket.Port)
8585
values[c.InbucketURL] = fmt.Sprintf("http://%s:%d", utils.Config.Hostname, utils.Config.Inbucket.Port)
8686
}
87-
if storageEnabled {
87+
if storageEnabled && utils.Config.Storage.S3Protocol != nil && utils.Config.Storage.S3Protocol.Enabled {
8888
values[c.StorageS3URL] = utils.GetApiUrl("/storage/v1/s3")
8989
values[c.StorageS3AccessKeyId] = utils.Config.Storage.S3Credentials.AccessKeyId
9090
values[c.StorageS3SecretAccessKey] = utils.Config.Storage.S3Credentials.SecretAccessKey

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ func (s *storage) Clone() storage {
295295
img := *s.ImageTransformation
296296
copy.ImageTransformation = &img
297297
}
298+
if s.S3Protocol != nil {
299+
s3 := *s.S3Protocol
300+
copy.S3Protocol = &s3
301+
}
298302
return copy
299303
}
300304

pkg/config/storage.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type (
1414
ImgProxyImage string `toml:"-"`
1515
FileSizeLimit sizeInBytes `toml:"file_size_limit"`
1616
ImageTransformation *imageTransformation `toml:"image_transformation"`
17+
S3Protocol *s3Protocol `toml:"s3_protocol"`
1718
S3Credentials storageS3Credentials `toml:"-"`
1819
Buckets BucketConfig `toml:"buckets"`
1920
}
@@ -22,6 +23,10 @@ type (
2223
Enabled bool `toml:"enabled"`
2324
}
2425

26+
s3Protocol struct {
27+
Enabled bool `toml:"enabled"`
28+
}
29+
2530
storageS3Credentials struct {
2631
AccessKeyId string `toml:"-"`
2732
SecretAccessKey string `toml:"-"`
@@ -41,10 +46,7 @@ type (
4146
func (s *storage) ToUpdateStorageConfigBody() v1API.UpdateStorageConfigBody {
4247
body := v1API.UpdateStorageConfigBody{
4348
FileSizeLimit: cast.Ptr(int64(s.FileSizeLimit)),
44-
}
45-
// When local config is not set, we assume platform defaults should not change
46-
if s.ImageTransformation != nil {
47-
body.Features = &struct {
49+
Features: &struct {
4850
IcebergCatalog *struct {
4951
Enabled bool `json:"enabled"`
5052
MaxCatalogs int `json:"maxCatalogs"`
@@ -62,9 +64,15 @@ func (s *storage) ToUpdateStorageConfigBody() v1API.UpdateStorageConfigBody {
6264
MaxBuckets int `json:"maxBuckets"`
6365
MaxIndexes int `json:"maxIndexes"`
6466
} `json:"vectorBuckets,omitempty"`
65-
}{}
67+
}{},
68+
}
69+
// When local config is not set, we assume platform defaults should not change
70+
if s.ImageTransformation != nil {
6671
body.Features.ImageTransformation.Enabled = s.ImageTransformation.Enabled
6772
}
73+
if s.S3Protocol != nil {
74+
body.Features.S3Protocol.Enabled = s.S3Protocol.Enabled
75+
}
6876
return body
6977
}
7078

@@ -74,14 +82,13 @@ func (s *storage) FromRemoteStorageConfig(remoteConfig v1API.StorageConfigRespon
7482
if s.ImageTransformation != nil {
7583
s.ImageTransformation.Enabled = remoteConfig.Features.ImageTransformation.Enabled
7684
}
85+
if s.S3Protocol != nil {
86+
s.S3Protocol.Enabled = remoteConfig.Features.S3Protocol.Enabled
87+
}
7788
}
7889

7990
func (s *storage) DiffWithRemote(remoteConfig v1API.StorageConfigResponse) ([]byte, error) {
8091
copy := s.Clone()
81-
if s.ImageTransformation != nil {
82-
img := *s.ImageTransformation
83-
copy.ImageTransformation = &img
84-
}
8592
// Convert the config values into easily comparable remoteConfig values
8693
currentValue, err := ToTomlBytes(copy)
8794
if err != nil {

pkg/config/templates/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ file_size_limit = "50MiB"
109109
# [storage.image_transformation]
110110
# enabled = true
111111

112+
# [storage.s3_protocol]
113+
# enabled = false
114+
112115
# Uncomment to configure local storage buckets
113116
# [storage.buckets.images]
114117
# public = false

pkg/config/testdata/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ file_size_limit = "50MiB"
109109
[storage.image_transformation]
110110
enabled = true
111111

112+
[storage.s3_protocol]
113+
enabled = true
114+
112115
# Uncomment to configure local storage buckets
113116
[storage.buckets.images]
114117
public = false

pkg/config/updater_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/h2non/gock"
99
"github.com/oapi-codegen/nullable"
10+
openapi_types "github.com/oapi-codegen/runtime/types"
1011
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213
v1API "github.com/supabase/cli/pkg/api"
@@ -243,6 +244,7 @@ func TestUpdateStorageConfig(t *testing.T) {
243244
}{},
244245
}
245246
mockStorage.Features.ImageTransformation.Enabled = true
247+
mockStorage.Features.S3Protocol.Enabled = true
246248
gock.New(server).
247249
Get("/v1/projects/test-project/config/storage").
248250
Reply(http.StatusOK).
@@ -313,11 +315,18 @@ func TestUpdateRemoteConfig(t *testing.T) {
313315
JSON(v1API.PostgresConfigResponse{
314316
MaxConnections: cast.Ptr(cast.UintToInt(100)),
315317
})
318+
// Network config
319+
gock.New(server).
320+
Get("/v1/projects/test-project/network-restrictions").
321+
Reply(http.StatusOK).
322+
JSON(v1API.V1GetNetworkRestrictionsResponse{})
316323
// Auth config
317324
gock.New(server).
318325
Get("/v1/projects/test-project/config/auth").
319326
Reply(http.StatusOK).
320-
JSON(v1API.AuthConfigResponse{})
327+
JSON(v1API.AuthConfigResponse{
328+
SmtpAdminEmail: nullable.NewNullableWithValue(openapi_types.Email("[email protected]")),
329+
})
321330
gock.New(server).
322331
Patch("/v1/projects/test-project/config/auth").
323332
Reply(http.StatusOK)
@@ -357,6 +366,9 @@ func TestUpdateRemoteConfig(t *testing.T) {
357366
ImageTransformation: &imageTransformation{
358367
Enabled: true,
359368
},
369+
S3Protocol: &s3Protocol{
370+
Enabled: true,
371+
},
360372
},
361373
Experimental: experimental{
362374
Webhooks: &webhooks{

0 commit comments

Comments
 (0)