diff --git a/internal/gen/bearerjwt/bearerjwt_test.go b/internal/gen/bearerjwt/bearerjwt_test.go index 4bce6c1a9..fe329b649 100644 --- a/internal/gen/bearerjwt/bearerjwt_test.go +++ b/internal/gen/bearerjwt/bearerjwt_test.go @@ -180,6 +180,7 @@ func TestGenerateToken(t *testing.T) { claims := jwt.MapClaims{} // Setup in-memory fs fsys := afero.NewMemMapFs() + require.NoError(t, utils.WriteFile("supabase/keys.json", []byte("[]"), fsys)) require.NoError(t, utils.WriteFile("supabase/config.toml", []byte(` [auth] signing_keys_path = "./keys.json" diff --git a/pkg/config/config.go b/pkg/config/config.go index 8d76db168..531bc3dea 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -558,7 +558,7 @@ func (c *config) newDecodeHook(fs ...mapstructure.DecodeHookFunc) mapstructure.D return mapstructure.ComposeDecodeHookFunc(fs...) } -func (c *config) Load(path string, fsys fs.FS) error { +func (c *config) Load(path string, fsys fs.FS, overrides ...ConfigEditor) error { builder := NewPathBuilder(path) // Load secrets from .env file if err := loadNestedEnv(builder.SupabaseDirPath); err != nil { @@ -637,6 +637,9 @@ func (c *config) Load(path string, fsys fs.FS) error { if err := c.resolve(builder, fsys); err != nil { return err } + for _, apply := range overrides { + apply(c) + } return c.Validate(fsys) } @@ -852,9 +855,7 @@ func (c *config) Validate(fsys fs.FS) error { } } if len(c.Auth.SigningKeysPath) > 0 { - if f, err := fsys.Open(c.Auth.SigningKeysPath); errors.Is(err, os.ErrNotExist) { - // Ignore missing signing key path on CI - } else if err != nil { + if f, err := fsys.Open(c.Auth.SigningKeysPath); err != nil { return errors.Errorf("failed to read signing keys: %w", err) } else if c.Auth.SigningKeys, err = fetcher.ParseJSON[[]JWK](f); err != nil { return errors.Errorf("failed to decode signing keys: %w", err) @@ -1215,7 +1216,7 @@ func (h *hookConfig) validate(hookType string) (err error) { } else if err := assertEnvLoaded(h.Secrets.Value); err != nil { return err } - for _, secret := range strings.Split(h.Secrets.Value, "|") { + for secret := range strings.SplitSeq(h.Secrets.Value, "|") { if !hookSecretPattern.MatchString(secret) { return errors.Errorf(`Invalid hook config: auth.hook.%s.secrets must be formatted as "v1,whsec_" with a minimum length of 32 characters.`, hookType) } diff --git a/pkg/config/decode_hooks.go b/pkg/config/decode_hooks.go index b97d9ba8d..265ec872e 100644 --- a/pkg/config/decode_hooks.go +++ b/pkg/config/decode_hooks.go @@ -12,7 +12,7 @@ var envPattern = regexp.MustCompile(`^env\((.*)\)$`) // LoadEnvHook is a mapstructure decode hook that loads environment variables // from strings formatted as env(VAR_NAME). -func LoadEnvHook(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) { +func LoadEnvHook(f reflect.Kind, t reflect.Kind, data any) (any, error) { if f != reflect.String { return data, nil } @@ -35,7 +35,7 @@ Example: verify_jwt = true` // ValidateFunctionsHook is a mapstructure decode hook that validates the functions config format. -func ValidateFunctionsHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) { +func ValidateFunctionsHook(f reflect.Type, t reflect.Type, data any) (any, error) { // Only handle FunctionConfig type if t != reflect.TypeOf(FunctionConfig{}) { return data, nil diff --git a/pkg/config/secret.go b/pkg/config/secret.go index 72c075ba7..8fa7f811b 100644 --- a/pkg/config/secret.go +++ b/pkg/config/secret.go @@ -83,7 +83,7 @@ func DecryptSecretHookFunc(hashKey string) mapstructure.DecodeHookFunc { privateKeys = append(privateKeys, strToArr(kv[1])...) } } - return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) { + return func(f reflect.Type, t reflect.Type, data any) (any, error) { if f.Kind() != reflect.String { return data, nil } diff --git a/pkg/config/updater_test.go b/pkg/config/updater_test.go index ad12812e5..98d56068a 100644 --- a/pkg/config/updater_test.go +++ b/pkg/config/updater_test.go @@ -130,7 +130,7 @@ func TestUpdateExperimentalConfig(t *testing.T) { gock.New(server). Post("/v1/projects/test-project/database/webhooks/enable"). Reply(http.StatusOK). - JSON(map[string]interface{}{}) + JSON(map[string]any{}) // Run test err := updater.UpdateExperimentalConfig(context.Background(), "test-project", experimental{ Webhooks: &webhooks{ @@ -325,7 +325,7 @@ func TestUpdateRemoteConfig(t *testing.T) { gock.New(server). Post("/v1/projects/test-project/database/webhooks/enable"). Reply(http.StatusOK). - JSON(map[string]interface{}{}) + JSON(map[string]any{}) // Run test err := updater.UpdateRemoteConfig(context.Background(), baseConfig{ ProjectId: "test-project", diff --git a/pkg/diff/diff.go b/pkg/diff/diff.go index 6a40b23fc..e3a8e2d98 100644 --- a/pkg/diff/diff.go +++ b/pkg/diff/diff.go @@ -116,10 +116,7 @@ func Diff(oldName string, old []byte, newName string, new []byte) []byte { // End chunk with common lines for context. if len(ctext) > 0 { - n := end.x - start.x - if n > C { - n = C - } + n := min(end.x-start.x, C) for _, s := range x[start.x : start.x+n] { ctext = append(ctext, " "+s) count.x++ @@ -234,7 +231,7 @@ func tgs(x, y []string) []pair { for i := range T { T[i] = n + 1 } - for i := 0; i < n; i++ { + for i := range n { k := sort.Search(n, func(k int) bool { return T[k] >= J[i] }) diff --git a/pkg/fetcher/http.go b/pkg/fetcher/http.go index 49ac67839..ac3ba91b9 100644 --- a/pkg/fetcher/http.go +++ b/pkg/fetcher/http.go @@ -6,6 +6,7 @@ import ( "encoding/json" "io" "net/http" + "slices" "github.com/go-errors/errors" ) @@ -93,10 +94,8 @@ func (s *Fetcher) Send(ctx context.Context, method, path string, reqBody any, re if err != nil { return nil, errors.Errorf("failed to execute http request: %w", err) } - for _, expected := range s.status { - if resp.StatusCode == expected { - return resp, nil - } + if slices.Contains(s.status, resp.StatusCode) { + return resp, nil } // Reject unexpected status codes as error if len(s.status) > 0 || resp.StatusCode >= http.StatusBadRequest { diff --git a/pkg/migration/list_test.go b/pkg/migration/list_test.go index 80d09fd40..4654fa876 100644 --- a/pkg/migration/list_test.go +++ b/pkg/migration/list_test.go @@ -16,7 +16,7 @@ func TestRemoteMigrations(t *testing.T) { conn := pgtest.NewConn() defer conn.Close(t) conn.Query(LIST_MIGRATION_VERSION). - Reply("SELECT 1", []interface{}{"20220727064247"}) + Reply("SELECT 1", []any{"20220727064247"}) // Run test versions, err := ListRemoteMigrations(context.Background(), conn.MockClient(t)) // Check error @@ -42,7 +42,7 @@ func TestRemoteMigrations(t *testing.T) { conn := pgtest.NewConn() defer conn.Close(t) conn.Query(LIST_MIGRATION_VERSION). - Reply("SELECT 1", []interface{}{}) + Reply("SELECT 1", []any{}) // Run test _, err := ListRemoteMigrations(context.Background(), conn.MockClient(t)) // Check error diff --git a/pkg/pgtest/mock.go b/pkg/pgtest/mock.go index 0f5e9bb84..4ceb2fece 100644 --- a/pkg/pgtest/mock.go +++ b/pkg/pgtest/mock.go @@ -79,7 +79,7 @@ func (r *MockConn) Intercept(config *pgx.ConnConfig) { } // Adds a simple query or prepared statement to the mock connection. -func (r *MockConn) Query(sql string, args ...interface{}) *MockConn { +func (r *MockConn) Query(sql string, args ...any) *MockConn { var oids []uint32 var params [][]byte for _, v := range args { @@ -92,7 +92,7 @@ func (r *MockConn) Query(sql string, args ...interface{}) *MockConn { return r } -func (r *MockConn) encodeValueArg(v interface{}) (value []byte, oid uint32) { +func (r *MockConn) encodeValueArg(v any) (value []byte, oid uint32) { if v == nil { return nil, pgtype.TextArrayOID } @@ -119,7 +119,7 @@ func (r *MockConn) encodeValueArg(v interface{}) (value []byte, oid uint32) { return value, dt.OID } -func getDataTypeSize(v interface{}) int16 { +func getDataTypeSize(v any) int16 { t := reflect.TypeOf(v) k := t.Kind() if k < reflect.Int || k > reflect.Complex128 { @@ -135,12 +135,12 @@ func (r *MockConn) lastQuery() *extendedQueryStep { // Adds a server reply using binary or text protocol format. // // TODO: support prepared statements when using binary protocol -func (r *MockConn) Reply(tag string, rows ...interface{}) *MockConn { +func (r *MockConn) Reply(tag string, rows ...any) *MockConn { q := r.lastQuery() // Add field description if len(rows) > 0 { var desc pgproto3.RowDescription - if arr, ok := rows[0].([]interface{}); ok { + if arr, ok := rows[0].([]any); ok { for i, v := range arr { name := fmt.Sprintf("c_%02d", i) if fd := toFieldDescription(v); fd != nil { @@ -176,7 +176,7 @@ func (r *MockConn) Reply(tag string, rows ...interface{}) *MockConn { // Add row data for _, data := range rows { var dr pgproto3.DataRow - if arr, ok := data.([]interface{}); ok { + if arr, ok := data.([]any); ok { for _, v := range arr { if value, oid := r.encodeValueArg(v); oid > 0 { dr.Values = append(dr.Values, value) @@ -209,7 +209,7 @@ func (r *MockConn) Reply(tag string, rows ...interface{}) *MockConn { return r } -func toFieldDescription(v interface{}) *pgproto3.FieldDescription { +func toFieldDescription(v any) *pgproto3.FieldDescription { if dt, ok := ci.DataTypeForValue(v); ok { size := getDataTypeSize(v) format := ci.ParamFormatCodeForOID(dt.OID)