diff --git a/pkg/config/api.go b/pkg/config/api.go index f502b9281..824acaf6e 100644 --- a/pkg/config/api.go +++ b/pkg/config/api.go @@ -7,15 +7,18 @@ import ( ) type ( - api struct { - Enabled bool `toml:"enabled"` - Image string `toml:"-"` - KongImage string `toml:"-"` - Port uint16 `toml:"port"` + RemoteApi struct { Schemas []string `toml:"schemas"` ExtraSearchPath []string `toml:"extra_search_path"` MaxRows uint `toml:"max_rows"` - Tls tlsKong `toml:"tls"` + } + api struct { + RemoteApi + Enabled bool `toml:"enabled"` + Image string `toml:"-"` + KongImage string `toml:"-"` + Port uint16 `toml:"port"` + Tls tlsKong `toml:"tls"` // TODO: replace [auth|studio].api_url ExternalUrl string `toml:"external_url"` } @@ -25,7 +28,7 @@ type ( } ) -func (a *api) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody { +func (a *RemoteApi) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody { body := v1API.UpdatePostgrestConfigBody{} // Convert Schemas to a comma-separated string @@ -50,7 +53,7 @@ func (a *api) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody { return body } -func (a *api) FromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) api { +func (a *RemoteApi) fromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) RemoteApi { result := *a // Update Schemas if present in remoteConfig result.Schemas = strings.Split(remoteConfig.DbSchema, ",") @@ -64,9 +67,9 @@ func (a *api) FromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJWTSecre return result } -func (a *api) DiffWithRemote(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) []byte { +func (a *RemoteApi) DiffWithRemote(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) []byte { // Convert the config values into easily comparable remoteConfig values currentValue := ToTomlBytes(a) - remoteCompare := ToTomlBytes(a.FromRemoteApiConfig(remoteConfig)) + remoteCompare := ToTomlBytes(a.fromRemoteApiConfig(remoteConfig)) return Diff("remote[api]", remoteCompare, "local[api]", currentValue) } diff --git a/pkg/config/api_test.go b/pkg/config/api_test.go index 881cd4893..cbbb9da64 100644 --- a/pkg/config/api_test.go +++ b/pkg/config/api_test.go @@ -9,7 +9,7 @@ import ( func TestApiToUpdatePostgrestConfigBody(t *testing.T) { t.Run("converts all fields correctly", func(t *testing.T) { - api := &api{ + api := &RemoteApi{ Schemas: []string{"public", "private"}, ExtraSearchPath: []string{"extensions", "public"}, MaxRows: 1000, @@ -23,7 +23,7 @@ func TestApiToUpdatePostgrestConfigBody(t *testing.T) { }) t.Run("handles empty fields", func(t *testing.T) { - api := &api{} + api := &RemoteApi{} body := api.ToUpdatePostgrestConfigBody() @@ -35,7 +35,7 @@ func TestApiToUpdatePostgrestConfigBody(t *testing.T) { func TestApiDiffWithRemote(t *testing.T) { t.Run("detects differences", func(t *testing.T) { - api := &api{ + api := &RemoteApi{ Schemas: []string{"public", "private"}, ExtraSearchPath: []string{"extensions", "public"}, MaxRows: 1000, @@ -58,7 +58,7 @@ func TestApiDiffWithRemote(t *testing.T) { }) t.Run("handles no differences", func(t *testing.T) { - api := &api{ + api := &RemoteApi{ Schemas: []string{"public"}, ExtraSearchPath: []string{"public"}, MaxRows: 500, diff --git a/pkg/config/config.go b/pkg/config/config.go index e00fc5b8e..a59c91313 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1306,6 +1306,15 @@ func (a *auth) ResolveJWKS(ctx context.Context) (string, error) { return string(jwksEncoded), nil } +// Retrieve the final base config to use taking into account the remotes override +func (c *config) GetRemoteOverride(remotes_name string) (overrideConfig baseConfig, overrideExist bool) { + overrideConfig, exist := c.Remotes[remotes_name] + if exist { + return overrideConfig, true + } + return c.baseConfig, false +} + func ToTomlBytes(config any) []byte { var buf bytes.Buffer enc := toml.NewEncoder(&buf)