Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/gen/bearerjwt/bearerjwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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_<base64_encoded_secret>" with a minimum length of 32 characters.`, hookType)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/decode_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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]
})
Expand Down
7 changes: 3 additions & 4 deletions pkg/fetcher/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"io"
"net/http"
"slices"

"github.com/go-errors/errors"
)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/migration/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/pgtest/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down