From 65bc6d32004a3fb25fee19a246cf9231f726e45d Mon Sep 17 00:00:00 2001 From: avallete Date: Fri, 11 Oct 2024 14:29:09 +0200 Subject: [PATCH] Revert "chore: split api and remote api" This reverts commit 23173ec9830d8ae97b43d0fa12c183b1d99f7069. --- pkg/config/api.go | 23 ++++++++++------------- pkg/config/api_test.go | 8 ++++---- pkg/config/config.go | 9 --------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/pkg/config/api.go b/pkg/config/api.go index 824acaf6e..f502b9281 100644 --- a/pkg/config/api.go +++ b/pkg/config/api.go @@ -7,18 +7,15 @@ import ( ) type ( - RemoteApi struct { + 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"` - } - api struct { - RemoteApi - Enabled bool `toml:"enabled"` - Image string `toml:"-"` - KongImage string `toml:"-"` - Port uint16 `toml:"port"` - Tls tlsKong `toml:"tls"` + Tls tlsKong `toml:"tls"` // TODO: replace [auth|studio].api_url ExternalUrl string `toml:"external_url"` } @@ -28,7 +25,7 @@ type ( } ) -func (a *RemoteApi) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody { +func (a *api) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBody { body := v1API.UpdatePostgrestConfigBody{} // Convert Schemas to a comma-separated string @@ -53,7 +50,7 @@ func (a *RemoteApi) ToUpdatePostgrestConfigBody() v1API.UpdatePostgrestConfigBod return body } -func (a *RemoteApi) fromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) RemoteApi { +func (a *api) FromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) api { result := *a // Update Schemas if present in remoteConfig result.Schemas = strings.Split(remoteConfig.DbSchema, ",") @@ -67,9 +64,9 @@ func (a *RemoteApi) fromRemoteApiConfig(remoteConfig v1API.PostgrestConfigWithJW return result } -func (a *RemoteApi) DiffWithRemote(remoteConfig v1API.PostgrestConfigWithJWTSecretResponse) []byte { +func (a *api) 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 cbbb9da64..881cd4893 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 := &RemoteApi{ + api := &api{ 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 := &RemoteApi{} + api := &api{} 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 := &RemoteApi{ + api := &api{ 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 := &RemoteApi{ + api := &api{ Schemas: []string{"public"}, ExtraSearchPath: []string{"public"}, MaxRows: 500, diff --git a/pkg/config/config.go b/pkg/config/config.go index a59c91313..e00fc5b8e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1306,15 +1306,6 @@ 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)