Skip to content

Commit

Permalink
Merge branch 'develop' into chore/use-keyring-deleteall
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete authored Oct 25, 2024
2 parents 77f75f4 + 8611ace commit 418c3c4
Show file tree
Hide file tree
Showing 25 changed files with 737 additions and 86 deletions.
5 changes: 3 additions & 2 deletions cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/supabase/cli/internal/functions/serve"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/cast"
)

var (
Expand Down Expand Up @@ -106,9 +107,9 @@ var (
}

if len(inspectMode.Value) > 0 {
runtimeOption.InspectMode = utils.Ptr(serve.InspectMode(inspectMode.Value))
runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
} else if inspectBrk {
runtimeOption.InspectMode = utils.Ptr(serve.InspectModeBrk)
runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
}
if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golangci/golangci-lint v1.61.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v62 v62.0.0
github.com/google/go-querystring v1.1.0
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -169,7 +170,6 @@ require (
github.com/golangci/plugin-module-register v0.1.1 // indirect
github.com/golangci/revgrep v0.5.3 // indirect
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gordonklaus/ineffassign v0.1.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions internal/branches/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
)

func TestCreateCommand(t *testing.T) {
Expand All @@ -36,7 +37,7 @@ func TestCreateCommand(t *testing.T) {
})
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.NoError(t, err)
Expand All @@ -53,7 +54,7 @@ func TestCreateCommand(t *testing.T) {
ReplyError(net.ErrClosed)
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.ErrorIs(t, err, net.ErrClosed)
Expand All @@ -70,7 +71,7 @@ func TestCreateCommand(t *testing.T) {
Reply(http.StatusServiceUnavailable)
// Run test
err := Run(context.Background(), api.CreateBranchBody{
Region: utils.Ptr("sin"),
Region: cast.Ptr("sin"),
}, fsys)
// Check error
assert.ErrorContains(t, err, "Unexpected error creating preview branch:")
Expand Down
18 changes: 12 additions & 6 deletions internal/db/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func NewContainerConfig() container.Config {
env := []string{
"POSTGRES_PASSWORD=" + utils.Config.Db.Password,
"POSTGRES_HOST=/var/run/postgresql",
"POSTGRES_INITDB_ARGS=--lc-ctype=C.UTF-8",
"JWT_SECRET=" + utils.Config.Auth.JwtSecret,
fmt.Sprintf("JWT_EXP=%d", utils.Config.Auth.JwtExpiry),
}
Expand All @@ -81,13 +80,18 @@ func NewContainerConfig() container.Config {
Timeout: 2 * time.Second,
Retries: 3,
},
Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /etc/postgresql.schema.sql && cat <<'EOF' > /etc/postgresql-custom/pgsodium_root.key && docker-entrypoint.sh postgres -D /etc/postgresql
Entrypoint: []string{"sh", "-c", `
cat <<'EOF' > /etc/postgresql.schema.sql && \
cat <<'EOF' > /etc/postgresql-custom/pgsodium_root.key && \
cat <<'EOF' >> /etc/postgresql/postgresql.conf && \
docker-entrypoint.sh postgres -D /etc/postgresql
` + initialSchema + `
` + _supabaseSchema + `
EOF
` + utils.Config.Db.RootKey + `
EOF
`},
` + utils.Config.Db.Settings.ToPostgresConfig() + `
EOF`},
}
if utils.Config.Db.MajorVersion >= 14 {
config.Cmd = []string{"postgres",
Expand Down Expand Up @@ -124,11 +128,13 @@ func StartDatabase(ctx context.Context, fsys afero.Fs, w io.Writer, options ...f
}
if utils.Config.Db.MajorVersion <= 14 {
config.Entrypoint = []string{"sh", "-c", `
cat <<'EOF' > /docker-entrypoint-initdb.d/supabase_schema.sql
cat <<'EOF' > /docker-entrypoint-initdb.d/supabase_schema.sql && \
cat <<'EOF' >> /etc/postgresql/postgresql.conf && \
docker-entrypoint.sh postgres -D /etc/postgresql
` + _supabaseSchema + `
EOF
docker-entrypoint.sh postgres -D /etc/postgresql
`}
` + utils.Config.Db.Settings.ToPostgresConfig() + `
EOF`}
hostConfig.Tmpfs = map[string]string{"/docker-entrypoint-initdb.d": ""}
}
// Creating volume will not override existing volume, so we must inspect explicitly
Expand Down
53 changes: 53 additions & 0 deletions internal/db/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/testing/fstest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/pgtest"
)

Expand Down Expand Up @@ -308,3 +309,55 @@ func TestSetupDatabase(t *testing.T) {
assert.Empty(t, apitest.ListUnmatchedRequests())
})
}
func TestStartDatabaseWithCustomSettings(t *testing.T) {
t.Run("starts database with custom MaxConnections", func(t *testing.T) {
// Setup
utils.Config.Db.MajorVersion = 15
utils.DbId = "supabase_db_test"
utils.ConfigId = "supabase_config_test"
utils.Config.Db.Port = 5432
utils.Config.Db.Settings.MaxConnections = cast.Ptr(uint(50))

// Setup in-memory fs
fsys := afero.NewMemMapFs()

// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.DbId).
Reply(http.StatusNotFound).
JSON(volume.Volume{})
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Db.Image), utils.DbId)
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/json").
Reply(http.StatusOK).
JSON(types.ContainerJSON{ContainerJSONBase: &types.ContainerJSONBase{
State: &types.ContainerState{
Running: true,
Health: &types.Health{Status: types.Healthy},
},
}})

apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Realtime.Image), "test-realtime")
require.NoError(t, apitest.MockDockerLogs(utils.Docker, "test-realtime", ""))
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Storage.Image), "test-storage")
require.NoError(t, apitest.MockDockerLogs(utils.Docker, "test-storage", ""))
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Auth.Image), "test-auth")
require.NoError(t, apitest.MockDockerLogs(utils.Docker, "test-auth", ""))
// Setup mock postgres
conn := pgtest.NewConn()
defer conn.Close(t)

// Run test
err := StartDatabase(context.Background(), fsys, io.Discard, conn.Intercept)

// Check error
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())

// Check if the custom MaxConnections setting was applied
config := NewContainerConfig()
assert.Contains(t, config.Entrypoint[2], "max_connections = 50")
})
}
3 changes: 2 additions & 1 deletion internal/functions/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/config"
"github.com/supabase/cli/pkg/function"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func GetFunctionConfig(slugs []string, importMapPath string, noVerifyJWT *bool,
function.ImportMap = utils.FallbackImportMapPath
}
if noVerifyJWT != nil {
function.VerifyJWT = utils.Ptr(!*noVerifyJWT)
function.VerifyJWT = cast.Ptr(!*noVerifyJWT)
}
functionConfig[name] = function
}
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/config"
)

Expand Down Expand Up @@ -323,7 +324,7 @@ func TestImportMapPath(t *testing.T) {
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.FallbackImportMapPath, []byte("{}"), 0644))
// Run test
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, utils.Ptr(false), fsys)
fc, err := GetFunctionConfig([]string{slug}, utils.FallbackImportMapPath, cast.Ptr(false), fsys)
// Check error
assert.NoError(t, err)
assert.Equal(t, utils.FallbackImportMapPath, fc[slug].ImportMap)
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
)

func TestServeCommand(t *testing.T) {
Expand Down Expand Up @@ -100,7 +101,7 @@ func TestServeCommand(t *testing.T) {
Reply(http.StatusOK).
JSON(types.ContainerJSON{})
// Run test
err := Run(context.Background(), ".env", utils.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
err := Run(context.Background(), ".env", cast.Ptr(true), "import_map.json", RuntimeOption{}, fsys)
// Check error
assert.ErrorIs(t, err, os.ErrNotExist)
})
Expand Down
9 changes: 5 additions & 4 deletions internal/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/supabase/cli/internal/testing/fstest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
)

func TestInitCommand(t *testing.T) {
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(true), nil, utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(true), nil, utils.InitParams{}))
// Validate generated vscode settings
exists, err := afero.Exists(fsys, settingsPath)
assert.NoError(t, err)
Expand All @@ -84,7 +85,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, utils.Ptr(false), nil, utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, cast.Ptr(false), nil, utils.InitParams{}))
// Validate vscode settings file isn't generated
exists, err := afero.Exists(fsys, settingsPath)
assert.NoError(t, err)
Expand All @@ -98,7 +99,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(true), utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(true), utils.InitParams{}))
// Validate generated intellij deno config
exists, err := afero.Exists(fsys, denoPath)
assert.NoError(t, err)
Expand All @@ -109,7 +110,7 @@ func TestInitCommand(t *testing.T) {
// Setup in-memory fs
fsys := &afero.MemMapFs{}
// Run test
assert.NoError(t, Run(context.Background(), fsys, nil, utils.Ptr(false), utils.InitParams{}))
assert.NoError(t, Run(context.Background(), fsys, nil, cast.Ptr(false), utils.InitParams{}))
// Validate intellij deno config file isn't generated
exists, err := afero.Exists(fsys, denoPath)
assert.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/cp/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/ls/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/mv/mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
9 changes: 5 additions & 4 deletions internal/storage/rm/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/storage"
)

var mockFile = storage.ObjectResponse{
Name: "abstract.pdf",
Id: utils.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: utils.Ptr("2023-10-13T18:08:22.068Z"),
Id: cast.Ptr("9b7f9f48-17a6-4ca8-b14a-39b0205a63e9"),
UpdatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
CreatedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
LastAccessedAt: cast.Ptr("2023-10-13T18:08:22.068Z"),
Metadata: &storage.ObjectMetadata{
ETag: `"887ea9be3c68e6f2fca7fd2d7c77d8fe"`,
Size: 82702,
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/viper"
"github.com/supabase/cli/internal/utils/cloudflare"
supabase "github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/cast"
)

const (
Expand Down Expand Up @@ -60,7 +61,7 @@ func FallbackLookupIP(ctx context.Context, host string) ([]string, error) {
func ResolveCNAME(ctx context.Context, host string) (string, error) {
// Ref: https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json
cf := cloudflare.NewCloudflareAPI()
data, err := cf.DNSQuery(ctx, cloudflare.DNSParams{Name: host, Type: Ptr(cloudflare.TypeCNAME)})
data, err := cf.DNSQuery(ctx, cloudflare.DNSParams{Name: host, Type: cast.Ptr(cloudflare.TypeCNAME)})
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 418c3c4

Please sign in to comment.