Skip to content

Commit

Permalink
chore: add api settings
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Oct 9, 2024
1 parent 85ac2f9 commit 457ed70
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
52 changes: 52 additions & 0 deletions pkg/config/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package config

import (
"strings"

v1API "github.com/supabase/cli/pkg/api"
)

type (
Api struct {
Enabled bool `toml:"enabled"`
Image string `toml:"-"`
KongImage string `toml:"-"`
Port uint16 `toml:"port"`
Schemas []string `toml:"schemas"`
ExtraSearchPath []string `toml:"extra_search_path"`
MaxRows uint `toml:"max_rows"`
Tls tlsKong `toml:"tls"`
// TODO: replace [auth|studio].api_url
ExternalUrl string `toml:"external_url"`
}

tlsKong struct {
Enabled bool `toml:"enabled"`
}
)

func (a *Api) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody {
body := v1API.UpdatePostgrestConfigBody{}

// Convert Schemas to a comma-separated string
if len(a.Schemas) > 0 {
schemas := strings.Join(a.Schemas, ",")
body.DbSchema = &schemas
}

// Convert ExtraSearchPath to a comma-separated string
if len(a.ExtraSearchPath) > 0 {
extraSearchPath := strings.Join(a.ExtraSearchPath, ",")
body.DbExtraSearchPath = &extraSearchPath
}

// Convert MaxRows to int pointer
if a.MaxRows > 0 {
maxRows := int(a.MaxRows)
body.MaxRows = &maxRows
}

// Note: DbPool is not present in the Api struct, so it's not set here

return body
}
21 changes: 2 additions & 19 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type (
baseConfig struct {
ProjectId string `toml:"project_id"`
Hostname string `toml:"-"`
Api api `toml:"api"`
Api Api `toml:"api"`
Db db `toml:"db" mapstructure:"db"`
Realtime realtime `toml:"realtime"`
Studio studio `toml:"studio"`
Expand All @@ -144,23 +144,6 @@ type (
Remotes map[string]baseConfig `toml:"-"`
}

api struct {
Enabled bool `toml:"enabled"`
Image string `toml:"-"`
KongImage string `toml:"-"`
Port uint16 `toml:"port"`
Schemas []string `toml:"schemas"`
ExtraSearchPath []string `toml:"extra_search_path"`
MaxRows uint `toml:"max_rows"`
Tls tlsKong `toml:"tls"`
// TODO: replace [auth|studio].api_url
ExternalUrl string `toml:"external_url"`
}

tlsKong struct {
Enabled bool `toml:"enabled"`
}

db struct {
Image string `toml:"-"`
Port uint16 `toml:"port"`
Expand Down Expand Up @@ -307,7 +290,7 @@ func WithHostname(hostname string) ConfigEditor {
func NewConfig(editors ...ConfigEditor) config {
initial := config{baseConfig: baseConfig{
Hostname: "127.0.0.1",
Api: api{
Api: Api{
Image: postgrestImage,
KongImage: kongImage,
},
Expand Down

0 comments on commit 457ed70

Please sign in to comment.