Skip to content

Commit

Permalink
chore: remove project ref arg from auth diff
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Jan 9, 2025
1 parent 82c2146 commit 72355b2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
1 change: 1 addition & 0 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
return err
}
fsys := afero.NewOsFs()
utils.Config.ProjectId = flags.ProjectRef
if err := utils.LoadConfigFS(fsys); err != nil {
return err
}
Expand Down
7 changes: 2 additions & 5 deletions internal/config/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import (
)

func Run(ctx context.Context, ref string, fsys afero.Fs) error {
utils.Config.ProjectId = ref
if err := utils.LoadConfigFS(fsys); err != nil {
return err
}
client := config.NewConfigUpdater(*utils.GetSupabase())
remote, err := utils.Config.GetRemoteByProjectRef(ref)
if err != nil {
// Use base config when no remote is declared
remote.ProjectId = ref
}
remote, _ := utils.Config.GetRemoteByProjectRef(ref)
fmt.Fprintln(os.Stderr, "Pushing config to project:", remote.ProjectId)
console := utils.NewConsole()
keep := func(name string) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ func (e external) fromAuthConfig(remoteConfig v1API.AuthConfigResponse) {
}
}

func (a *auth) DiffWithRemote(projectRef string, remoteConfig v1API.AuthConfigResponse) ([]byte, error) {
func (a *auth) DiffWithRemote(remoteConfig v1API.AuthConfigResponse) ([]byte, error) {
copy := a.Clone()
// Convert the config values into easily comparable remoteConfig values
currentValue, err := ToTomlBytes(copy)
Expand Down
46 changes: 23 additions & 23 deletions pkg/config/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAuthDiff(t *testing.T) {
c.MinimumPasswordLength = 6
c.PasswordRequirements = LettersDigits
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
SiteUrl: cast.Ptr("http://127.0.0.1:3000"),
UriAllowList: cast.Ptr("https://127.0.0.1:3000"),
JwtExp: cast.Ptr(3600),
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestAuthDiff(t *testing.T) {
c.MinimumPasswordLength = 6
c.PasswordRequirements = LowerUpperLettersDigitsSymbols
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
SiteUrl: cast.Ptr(""),
UriAllowList: cast.Ptr("https://127.0.0.1:3000,https://ref.supabase.co"),
JwtExp: cast.Ptr(0),
Expand All @@ -99,7 +99,7 @@ func TestAuthDiff(t *testing.T) {
c := newWithDefaults()
c.EnableSignup = false
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
SiteUrl: cast.Ptr(""),
UriAllowList: cast.Ptr(""),
JwtExp: cast.Ptr(0),
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestHookDiff(t *testing.T) {
},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
HookCustomAccessTokenEnabled: cast.Ptr(true),
HookCustomAccessTokenUri: cast.Ptr("http://example.com"),
HookCustomAccessTokenSecrets: cast.Ptr("ce62bb9bcced294fd4afe668f8ab3b50a89cf433093c526fffa3d0e46bf55252"),
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestHookDiff(t *testing.T) {
PasswordVerificationAttempt: nil,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
HookCustomAccessTokenEnabled: cast.Ptr(true),
HookCustomAccessTokenUri: cast.Ptr("http://example.com"),
HookCustomAccessTokenSecrets: cast.Ptr("ce62bb9bcced294fd4afe668f8ab3b50a89cf433093c526fffa3d0e46bf55252"),
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestHookDiff(t *testing.T) {
PasswordVerificationAttempt: nil,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
HookCustomAccessTokenEnabled: cast.Ptr(false),
HookCustomAccessTokenUri: cast.Ptr("pg-functions://postgres/public/customToken"),
HookSendSmsEnabled: cast.Ptr(false),
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestHookDiff(t *testing.T) {
PasswordVerificationAttempt: &hookConfig{Enabled: false},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
HookCustomAccessTokenEnabled: cast.Ptr(false),
HookSendSmsEnabled: cast.Ptr(false),
HookSendEmailEnabled: cast.Ptr(false),
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestMfaDiff(t *testing.T) {
MaxEnrolledFactors: 10,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
MfaMaxEnrolledFactors: cast.Ptr(10),
MfaTotpEnrollEnabled: cast.Ptr(true),
MfaTotpVerifyEnabled: cast.Ptr(true),
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestMfaDiff(t *testing.T) {
},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
MfaMaxEnrolledFactors: cast.Ptr(10),
MfaTotpEnrollEnabled: cast.Ptr(false),
MfaTotpVerifyEnabled: cast.Ptr(false),
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestMfaDiff(t *testing.T) {
},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
MfaMaxEnrolledFactors: cast.Ptr(10),
MfaTotpEnrollEnabled: cast.Ptr(false),
MfaTotpVerifyEnabled: cast.Ptr(false),
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestEmailDiff(t *testing.T) {
OtpExpiry: 3600,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalEmailEnabled: cast.Ptr(true),
MailerSecureEmailChangeEnabled: cast.Ptr(true),
MailerAutoconfirm: cast.Ptr(false),
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestEmailDiff(t *testing.T) {
OtpExpiry: 86400,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalEmailEnabled: cast.Ptr(false),
MailerSecureEmailChangeEnabled: cast.Ptr(false),
MailerAutoconfirm: cast.Ptr(true),
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestEmailDiff(t *testing.T) {
OtpExpiry: 86400,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalEmailEnabled: cast.Ptr(true),
MailerSecureEmailChangeEnabled: cast.Ptr(true),
MailerAutoconfirm: cast.Ptr(false),
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestEmailDiff(t *testing.T) {
OtpExpiry: 3600,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalEmailEnabled: cast.Ptr(false),
MailerSecureEmailChangeEnabled: cast.Ptr(false),
MailerAutoconfirm: cast.Ptr(true),
Expand Down Expand Up @@ -658,7 +658,7 @@ func TestSmsDiff(t *testing.T) {
},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(true),
SmsAutoconfirm: cast.Ptr(true),
SmsMaxFrequency: cast.Ptr(60),
Expand Down Expand Up @@ -692,7 +692,7 @@ func TestSmsDiff(t *testing.T) {
t.Run("local disabled remote enabled", func(t *testing.T) {
c := newWithDefaults()
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(true),
SmsAutoconfirm: cast.Ptr(true),
SmsMaxFrequency: cast.Ptr(60),
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestSmsDiff(t *testing.T) {
},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
SmsAutoconfirm: cast.Ptr(false),
SmsMaxFrequency: cast.Ptr(0),
Expand Down Expand Up @@ -758,7 +758,7 @@ func TestSmsDiff(t *testing.T) {
MaxFrequency: time.Minute,
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
SmsAutoconfirm: cast.Ptr(true),
SmsMaxFrequency: cast.Ptr(60),
Expand All @@ -782,7 +782,7 @@ func TestSmsDiff(t *testing.T) {
c := newWithDefaults()
c.Sms.EnableSignup = true
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
SmsProvider: cast.Ptr("twilio"),
})
Expand All @@ -795,7 +795,7 @@ func TestSmsDiff(t *testing.T) {
c := newWithDefaults()
c.Sms.Messagebird.Enabled = true
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
SmsProvider: cast.Ptr("messagebird"),
SmsMessagebirdAccessKey: cast.Ptr(""),
Expand Down Expand Up @@ -831,7 +831,7 @@ func TestExternalDiff(t *testing.T) {
"zoom": {Enabled: true},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalAppleAdditionalClientIds: cast.Ptr(""),
ExternalAppleClientId: cast.Ptr(""),
ExternalAppleEnabled: cast.Ptr(true),
Expand Down Expand Up @@ -949,7 +949,7 @@ func TestExternalDiff(t *testing.T) {
"zoom": {},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalAppleAdditionalClientIds: cast.Ptr("test-client-2"),
ExternalAppleClientId: cast.Ptr("test-client-1"),
ExternalAppleEnabled: cast.Ptr(false),
Expand Down Expand Up @@ -992,7 +992,7 @@ func TestExternalDiff(t *testing.T) {
"zoom": {},
}
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
diff, err := c.DiffWithRemote(v1API.AuthConfigResponse{
ExternalAppleEnabled: cast.Ptr(false),
ExternalAzureEnabled: cast.Ptr(false),
ExternalBitbucketEnabled: cast.Ptr(false),
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ func (c *config) newDecodeHook(fs ...mapstructure.DecodeHookFunc) mapstructure.D
mapstructure.StringToIPHookFunc(),
mapstructure.StringToSliceHookFunc(","),
mapstructure.TextUnmarshallerHookFunc(),
// TODO: assign the linked project id
DecryptSecretHookFunc(c.ProjectId),
)
return mapstructure.ComposeDecodeHookFunc(fs...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (u *ConfigUpdater) UpdateAuthConfig(ctx context.Context, projectRef string,
} else if authConfig.JSON200 == nil {
return errors.Errorf("unexpected status %d: %s", authConfig.StatusCode(), string(authConfig.Body))
}
authDiff, err := c.DiffWithRemote(projectRef, *authConfig.JSON200)
authDiff, err := c.DiffWithRemote(*authConfig.JSON200)
if err != nil {
return err
} else if len(authDiff) == 0 {
Expand Down

0 comments on commit 72355b2

Please sign in to comment.