Skip to content

Commit

Permalink
Revert "chore: split api and remote api"
Browse files Browse the repository at this point in the history
This reverts commit 23173ec.
  • Loading branch information
avallete committed Oct 11, 2024
1 parent 23173ec commit 65bc6d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
23 changes: 10 additions & 13 deletions pkg/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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
Expand All @@ -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, ",")
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions pkg/config/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()

Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 65bc6d3

Please sign in to comment.