From 6a90beb628e6bc1a0728626d4ccbcb486bc1bad8 Mon Sep 17 00:00:00 2001 From: avallete Date: Fri, 29 Nov 2024 15:31:29 +0100 Subject: [PATCH 1/2] feat(updater): allow to skip secrets sync for branching --- internal/config/push/push.go | 2 +- pkg/config/auth.go | 54 ++++++++++++++++++++++++++++++++++++ pkg/config/updater.go | 13 ++++++--- pkg/config/updater_test.go | 27 +++++++++--------- 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/internal/config/push/push.go b/internal/config/push/push.go index a4c901473d..cc8535beba 100644 --- a/internal/config/push/push.go +++ b/internal/config/push/push.go @@ -14,7 +14,7 @@ func Run(ctx context.Context, ref string, fsys afero.Fs) error { if err := utils.LoadConfigFS(fsys); err != nil { return err } - client := config.NewConfigUpdater(*utils.GetSupabase()) + client := config.NewConfigUpdater(*utils.GetSupabase(), false) remote, err := utils.Config.GetRemoteByProjectRef(ref) if err != nil { // Use base config when no remote is declared diff --git a/pkg/config/auth.go b/pkg/config/auth.go index 572b88950d..d946bf6cb4 100644 --- a/pkg/config/auth.go +++ b/pkg/config/auth.go @@ -217,6 +217,60 @@ type ( } ) +func (a *auth) StripUpdateBodySecrets(body v1API.UpdateAuthConfigBody) v1API.UpdateAuthConfigBody { + body.SmtpPass = nil + // Only strip secrets for locally enabled providers because other envs won't be loaded + body.SmsTwilioAuthToken = nil + body.SmsTwilioVerifyAuthToken = nil + body.SmsMessagebirdAccessKey = nil + body.SmsTextlocalApiKey = nil + body.SmsVonageApiSecret = nil + body.HookMfaVerificationAttemptSecrets = nil + body.HookPasswordVerificationAttemptSecrets = nil + body.HookCustomAccessTokenSecrets = nil + body.HookSendSmsSecrets = nil + body.HookSendEmailSecrets = nil + body.ExternalAppleSecret = nil + body.ExternalAppleClientId = nil + body.ExternalAzureSecret = nil + body.ExternalAzureClientId = nil + body.ExternalBitbucketSecret = nil + body.ExternalBitbucketClientId = nil + body.ExternalDiscordSecret = nil + body.ExternalDiscordClientId = nil + body.ExternalFacebookSecret = nil + body.ExternalFacebookClientId = nil + body.ExternalFigmaSecret = nil + body.ExternalFigmaClientId = nil + body.ExternalGithubSecret = nil + body.ExternalGithubClientId = nil + body.ExternalGitlabSecret = nil + body.ExternalGitlabClientId = nil + body.ExternalGoogleSecret = nil + body.ExternalGoogleClientId = nil + body.ExternalKakaoSecret = nil + body.ExternalKakaoClientId = nil + body.ExternalKeycloakSecret = nil + body.ExternalKeycloakClientId = nil + body.ExternalLinkedinOidcSecret = nil + body.ExternalLinkedinOidcClientId = nil + body.ExternalNotionSecret = nil + body.ExternalNotionClientId = nil + body.ExternalSlackOidcSecret = nil + body.ExternalSlackOidcClientId = nil + body.ExternalSpotifySecret = nil + body.ExternalSpotifyClientId = nil + body.ExternalTwitchSecret = nil + body.ExternalTwitchClientId = nil + body.ExternalTwitterSecret = nil + body.ExternalTwitterClientId = nil + body.ExternalWorkosSecret = nil + body.ExternalWorkosClientId = nil + body.ExternalZoomSecret = nil + body.ExternalZoomClientId = nil + return body +} + func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody { body := v1API.UpdateAuthConfigBody{ SiteUrl: &a.SiteUrl, diff --git a/pkg/config/updater.go b/pkg/config/updater.go index 445000d0b8..278e7f8c3a 100644 --- a/pkg/config/updater.go +++ b/pkg/config/updater.go @@ -10,11 +10,12 @@ import ( ) type ConfigUpdater struct { - client v1API.ClientWithResponses + client v1API.ClientWithResponses + skipSecrets bool } -func NewConfigUpdater(client v1API.ClientWithResponses) ConfigUpdater { - return ConfigUpdater{client: client} +func NewConfigUpdater(client v1API.ClientWithResponses, skipSecrets bool) ConfigUpdater { + return ConfigUpdater{client: client, skipSecrets: skipSecrets} } func (u *ConfigUpdater) UpdateRemoteConfig(ctx context.Context, remote baseConfig, filter ...func(string) bool) error { @@ -123,7 +124,11 @@ func (u *ConfigUpdater) UpdateAuthConfig(ctx context.Context, projectRef string, return nil } } - if resp, err := u.client.V1UpdateAuthServiceConfigWithResponse(ctx, projectRef, c.ToUpdateAuthConfigBody()); err != nil { + var updateBody = c.ToUpdateAuthConfigBody() + if u.skipSecrets { + updateBody = c.StripUpdateBodySecrets(updateBody) + } + if resp, err := u.client.V1UpdateAuthServiceConfigWithResponse(ctx, projectRef, updateBody); err != nil { return errors.Errorf("failed to update Auth config: %w", err) } else if status := resp.StatusCode(); status < 200 || status >= 300 { return errors.Errorf("unexpected status %d: %s", status, string(resp.Body)) diff --git a/pkg/config/updater_test.go b/pkg/config/updater_test.go index 471e849637..7cb4ddb77f 100644 --- a/pkg/config/updater_test.go +++ b/pkg/config/updater_test.go @@ -18,7 +18,7 @@ func TestUpdateApi(t *testing.T) { require.NoError(t, err) t.Run("updates remote config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -46,7 +46,7 @@ func TestUpdateApi(t *testing.T) { }) t.Run("skips update if no diff", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -71,7 +71,7 @@ func TestUpdateDbConfig(t *testing.T) { require.NoError(t, err) t.Run("updates remote DB config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -96,7 +96,7 @@ func TestUpdateDbConfig(t *testing.T) { }) t.Run("skips update if no diff in DB config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -123,7 +123,7 @@ func TestUpdateExperimentalConfig(t *testing.T) { require.NoError(t, err) t.Run("enables webhooks", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -142,7 +142,7 @@ func TestUpdateExperimentalConfig(t *testing.T) { }) t.Run("skips update if webhooks not enabled", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Run test err := updater.UpdateExperimentalConfig(context.Background(), "test-project", experimental{ Webhooks: &webhooks{ @@ -154,14 +154,13 @@ func TestUpdateExperimentalConfig(t *testing.T) { assert.True(t, gock.IsDone()) }) } - func TestUpdateAuthConfig(t *testing.T) { server := "http://localhost" client, err := v1API.NewClientWithResponses(server) require.NoError(t, err) t.Run("updates remote Auth config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -181,7 +180,7 @@ func TestUpdateAuthConfig(t *testing.T) { }) t.Run("skips update if no diff in Auth config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -201,7 +200,7 @@ func TestUpdateAuthConfig(t *testing.T) { }) t.Run("skips update if disabled locally", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Run test err := updater.UpdateAuthConfig(context.Background(), "test-project", auth{}) // Check result @@ -215,7 +214,7 @@ func TestUpdateStorageConfig(t *testing.T) { require.NoError(t, err) t.Run("updates remote Storage config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -240,7 +239,7 @@ func TestUpdateStorageConfig(t *testing.T) { }) t.Run("skips update if no diff in Storage config", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() gock.New(server). @@ -255,7 +254,7 @@ func TestUpdateStorageConfig(t *testing.T) { }) t.Run("skips update if disabled locally", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Run test err := updater.UpdateStorageConfig(context.Background(), "test-project", storage{}) // Check result @@ -269,7 +268,7 @@ func TestUpdateRemoteConfig(t *testing.T) { require.NoError(t, err) t.Run("updates all configs", func(t *testing.T) { - updater := NewConfigUpdater(*client) + updater := NewConfigUpdater(*client, false) // Setup mock server defer gock.Off() // API config From 189f29481a5801ed64bc2417eee4adc54c4b2896 Mon Sep 17 00:00:00 2001 From: avallete Date: Fri, 29 Nov 2024 18:43:10 +0100 Subject: [PATCH 2/2] chore: apply pr comment --- internal/config/push/push.go | 2 +- pkg/config/updater.go | 4 ++-- pkg/config/updater_test.go | 27 ++++++++++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/internal/config/push/push.go b/internal/config/push/push.go index cc8535beba..a4c901473d 100644 --- a/internal/config/push/push.go +++ b/internal/config/push/push.go @@ -14,7 +14,7 @@ func Run(ctx context.Context, ref string, fsys afero.Fs) error { if err := utils.LoadConfigFS(fsys); err != nil { return err } - client := config.NewConfigUpdater(*utils.GetSupabase(), false) + client := config.NewConfigUpdater(*utils.GetSupabase()) remote, err := utils.Config.GetRemoteByProjectRef(ref) if err != nil { // Use base config when no remote is declared diff --git a/pkg/config/updater.go b/pkg/config/updater.go index 278e7f8c3a..81a15af093 100644 --- a/pkg/config/updater.go +++ b/pkg/config/updater.go @@ -14,8 +14,8 @@ type ConfigUpdater struct { skipSecrets bool } -func NewConfigUpdater(client v1API.ClientWithResponses, skipSecrets bool) ConfigUpdater { - return ConfigUpdater{client: client, skipSecrets: skipSecrets} +func NewConfigUpdater(client v1API.ClientWithResponses) ConfigUpdater { + return ConfigUpdater{client: client, skipSecrets: false} } func (u *ConfigUpdater) UpdateRemoteConfig(ctx context.Context, remote baseConfig, filter ...func(string) bool) error { diff --git a/pkg/config/updater_test.go b/pkg/config/updater_test.go index 7cb4ddb77f..471e849637 100644 --- a/pkg/config/updater_test.go +++ b/pkg/config/updater_test.go @@ -18,7 +18,7 @@ func TestUpdateApi(t *testing.T) { require.NoError(t, err) t.Run("updates remote config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -46,7 +46,7 @@ func TestUpdateApi(t *testing.T) { }) t.Run("skips update if no diff", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -71,7 +71,7 @@ func TestUpdateDbConfig(t *testing.T) { require.NoError(t, err) t.Run("updates remote DB config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -96,7 +96,7 @@ func TestUpdateDbConfig(t *testing.T) { }) t.Run("skips update if no diff in DB config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -123,7 +123,7 @@ func TestUpdateExperimentalConfig(t *testing.T) { require.NoError(t, err) t.Run("enables webhooks", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -142,7 +142,7 @@ func TestUpdateExperimentalConfig(t *testing.T) { }) t.Run("skips update if webhooks not enabled", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Run test err := updater.UpdateExperimentalConfig(context.Background(), "test-project", experimental{ Webhooks: &webhooks{ @@ -154,13 +154,14 @@ func TestUpdateExperimentalConfig(t *testing.T) { assert.True(t, gock.IsDone()) }) } + func TestUpdateAuthConfig(t *testing.T) { server := "http://localhost" client, err := v1API.NewClientWithResponses(server) require.NoError(t, err) t.Run("updates remote Auth config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -180,7 +181,7 @@ func TestUpdateAuthConfig(t *testing.T) { }) t.Run("skips update if no diff in Auth config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -200,7 +201,7 @@ func TestUpdateAuthConfig(t *testing.T) { }) t.Run("skips update if disabled locally", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Run test err := updater.UpdateAuthConfig(context.Background(), "test-project", auth{}) // Check result @@ -214,7 +215,7 @@ func TestUpdateStorageConfig(t *testing.T) { require.NoError(t, err) t.Run("updates remote Storage config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -239,7 +240,7 @@ func TestUpdateStorageConfig(t *testing.T) { }) t.Run("skips update if no diff in Storage config", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() gock.New(server). @@ -254,7 +255,7 @@ func TestUpdateStorageConfig(t *testing.T) { }) t.Run("skips update if disabled locally", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Run test err := updater.UpdateStorageConfig(context.Background(), "test-project", storage{}) // Check result @@ -268,7 +269,7 @@ func TestUpdateRemoteConfig(t *testing.T) { require.NoError(t, err) t.Run("updates all configs", func(t *testing.T) { - updater := NewConfigUpdater(*client, false) + updater := NewConfigUpdater(*client) // Setup mock server defer gock.Off() // API config