-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): implement storage config update (#2817)
* feat(config): implement storage config update * chore: update unit tests
- Loading branch information
1 parent
4d2e5c3
commit 0109975
Showing
6 changed files
with
165 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package config | ||
|
||
import ( | ||
v1API "github.com/supabase/cli/pkg/api" | ||
"github.com/supabase/cli/pkg/cast" | ||
"github.com/supabase/cli/pkg/diff" | ||
) | ||
|
||
type ( | ||
storage struct { | ||
Enabled bool `toml:"enabled"` | ||
Image string `toml:"-"` | ||
FileSizeLimit sizeInBytes `toml:"file_size_limit"` | ||
S3Credentials storageS3Credentials `toml:"-"` | ||
ImageTransformation imageTransformation `toml:"image_transformation"` | ||
Buckets BucketConfig `toml:"buckets"` | ||
} | ||
|
||
imageTransformation struct { | ||
Enabled bool `toml:"enabled"` | ||
Image string `toml:"-"` | ||
} | ||
|
||
storageS3Credentials struct { | ||
AccessKeyId string `toml:"-"` | ||
SecretAccessKey string `toml:"-"` | ||
Region string `toml:"-"` | ||
} | ||
|
||
BucketConfig map[string]bucket | ||
|
||
bucket struct { | ||
Public *bool `toml:"public"` | ||
FileSizeLimit sizeInBytes `toml:"file_size_limit"` | ||
AllowedMimeTypes []string `toml:"allowed_mime_types"` | ||
ObjectsPath string `toml:"objects_path"` | ||
} | ||
) | ||
|
||
func (s *storage) ToUpdateStorageConfigBody() v1API.UpdateStorageConfigBody { | ||
body := v1API.UpdateStorageConfigBody{Features: &v1API.StorageFeatures{}} | ||
body.FileSizeLimit = cast.Ptr(int64(s.FileSizeLimit)) | ||
body.Features.ImageTransformation.Enabled = s.ImageTransformation.Enabled | ||
return body | ||
} | ||
|
||
func (s *storage) fromRemoteStorageConfig(remoteConfig v1API.StorageConfigResponse) storage { | ||
result := *s | ||
result.FileSizeLimit = sizeInBytes(remoteConfig.FileSizeLimit) | ||
result.ImageTransformation.Enabled = remoteConfig.Features.ImageTransformation.Enabled | ||
return result | ||
} | ||
|
||
func (s *storage) DiffWithRemote(remoteConfig v1API.StorageConfigResponse) ([]byte, error) { | ||
// Convert the config values into easily comparable remoteConfig values | ||
currentValue, err := ToTomlBytes(s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
remoteCompare, err := ToTomlBytes(s.fromRemoteStorageConfig(remoteConfig)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return diff.Diff("remote[storage]", remoteCompare, "local[storage]", currentValue), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters