Skip to content

Commit

Permalink
chore: address linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Oct 30, 2024
1 parent b0d69a0 commit 6ebd353
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
4 changes: 2 additions & 2 deletions internal/functions/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
|-|-|-|-|-|-|
`
for _, function := range *resp.JSON200 {
t := time.UnixMilli(int64(function.UpdatedAt))
t := time.UnixMilli(function.UpdatedAt)
table += fmt.Sprintf(
"|`%s`|`%s`|`%s`|`%s`|`%d`|`%s`|\n",
function.Id,
function.Name,
function.Slug,
function.Status,
uint64(function.Version),
function.Version,
t.UTC().Format("2006-01-02 15:04:05"),
)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ func updatePoolerConfig(config api.SupavisorConfigResponse) {
utils.Config.Db.Pooler.ConnectionString = config.ConnectionString
utils.Config.Db.Pooler.PoolMode = cliConfig.PoolMode(config.PoolMode)
if config.DefaultPoolSize != nil {
utils.Config.Db.Pooler.DefaultPoolSize = uint(*config.DefaultPoolSize)
utils.Config.Db.Pooler.DefaultPoolSize = cast.IntToUint(*config.DefaultPoolSize)
}
if config.MaxClientConn != nil {
utils.Config.Db.Pooler.MaxClientConn = uint(*config.MaxClientConn)
utils.Config.Db.Pooler.MaxClientConn = cast.IntToUint(*config.MaxClientConn)
}
}

Expand Down
62 changes: 24 additions & 38 deletions pkg/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
ExternalEmailEnabled: cast.Ptr(a.Email.EnableSignup),
ExternalPhoneEnabled: cast.Ptr(a.Sms.EnableSignup),
ExternalAnonymousUsersEnabled: cast.Ptr(a.EnableAnonymousSignIns),
MfaMaxEnrolledFactors: cast.Ptr(int(a.MFA.MaxEnrolledFactors)),
MfaMaxEnrolledFactors: cast.Ptr(cast.UintToInt((a.MFA.MaxEnrolledFactors))),
MfaTotpEnrollEnabled: cast.Ptr(a.MFA.TOTP.EnrollEnabled),
MfaTotpVerifyEnabled: cast.Ptr(a.MFA.TOTP.VerifyEnabled),
MfaPhoneEnrollEnabled: cast.Ptr(a.MFA.Phone.EnrollEnabled),
MfaPhoneVerifyEnabled: cast.Ptr(a.MFA.Phone.VerifyEnabled),
MfaPhoneOtpLength: cast.Ptr(int(a.MFA.Phone.OtpLength)),
MfaPhoneOtpLength: cast.Ptr(cast.UintToInt(a.MFA.Phone.OtpLength)),
MfaPhoneTemplate: cast.Ptr(a.MFA.Phone.Template),
MfaPhoneMaxFrequency: cast.Ptr(int(a.MFA.Phone.MaxFrequency.Seconds())),
MfaWebAuthnEnrollEnabled: cast.Ptr(a.MFA.WebAuthn.EnrollEnabled),
MfaWebAuthnVerifyEnabled: cast.Ptr(a.MFA.WebAuthn.VerifyEnabled),
RefreshTokenRotationEnabled: cast.Ptr(a.EnableRefreshTokenRotation),
SecurityRefreshTokenReuseInterval: cast.Ptr(int(a.RefreshTokenReuseInterval)),
SecurityRefreshTokenReuseInterval: cast.Ptr(cast.UintToInt(a.RefreshTokenReuseInterval)),
SecurityManualLinkingEnabled: cast.Ptr(a.EnableManualLinking),
SessionsTimebox: cast.Ptr(int(a.Sessions.Timebox.Seconds())),
SessionsInactivityTimeout: cast.Ptr(int(a.Sessions.InactivityTimeout.Seconds())),
Expand Down Expand Up @@ -867,54 +867,40 @@ func (a *auth) mapRemoteSmsProviders(remoteConfig v1API.AuthConfigResponse) {
}
}

func (original *auth) compareAndHideSensitiveFields(remote *auth) {
func (a *auth) compareAndHideSensitiveFields(remote *auth) {
// This function compares the original auth struct with a remote auth struct
// and hides sensitive fields in both structs for secure comparison
// SMTP sensitive fields
diff.CompareSensitiveField(&original.Email.Smtp.AdminEmail, &remote.Email.Smtp.AdminEmail)
diff.CompareSensitiveField(&original.Email.Smtp.Host, &remote.Email.Smtp.Host)
diff.CompareSensitiveField(&original.Email.Smtp.User, &remote.Email.Smtp.User)
diff.CompareSensitiveField(&original.Email.Smtp.SenderName, &remote.Email.Smtp.SenderName)
diff.CompareSensitiveField(&original.Email.Smtp.Pass, &remote.Email.Smtp.Pass)
diff.CompareSensitiveField(&a.Email.Smtp.Pass, &remote.Email.Smtp.Pass)

// Sms sensitives fields
diff.CompareSensitiveField(&original.Sms.Twilio.AuthToken, &remote.Sms.Twilio.AuthToken)
diff.CompareSensitiveField(&original.Sms.TwilioVerify.AuthToken, &remote.Sms.TwilioVerify.AuthToken)
diff.CompareSensitiveField(&original.Sms.Messagebird.AccessKey, &remote.Sms.Messagebird.AccessKey)
diff.CompareSensitiveField(&original.Sms.Textlocal.ApiKey, &remote.Sms.Textlocal.ApiKey)
diff.CompareSensitiveField(&original.Sms.Vonage.ApiKey, &remote.Sms.Vonage.ApiKey)
diff.CompareSensitiveField(&original.Sms.Vonage.ApiSecret, &remote.Sms.Vonage.ApiSecret)
diff.CompareSensitiveField(&original.Sms.Twilio.AccountSid, &remote.Sms.Twilio.AccountSid)
diff.CompareSensitiveField(&original.Sms.Twilio.MessageServiceSid, &remote.Sms.Twilio.MessageServiceSid)
diff.CompareSensitiveField(&original.Sms.TwilioVerify.AccountSid, &remote.Sms.TwilioVerify.AccountSid)
diff.CompareSensitiveField(&original.Sms.TwilioVerify.MessageServiceSid, &remote.Sms.TwilioVerify.MessageServiceSid)
diff.CompareSensitiveField(&a.Sms.Twilio.AuthToken, &remote.Sms.Twilio.AuthToken)
diff.CompareSensitiveField(&a.Sms.TwilioVerify.AuthToken, &remote.Sms.TwilioVerify.AuthToken)
diff.CompareSensitiveField(&a.Sms.Messagebird.AccessKey, &remote.Sms.Messagebird.AccessKey)
diff.CompareSensitiveField(&a.Sms.Textlocal.ApiKey, &remote.Sms.Textlocal.ApiKey)
diff.CompareSensitiveField(&a.Sms.Vonage.ApiKey, &remote.Sms.Vonage.ApiKey)
diff.CompareSensitiveField(&a.Sms.Vonage.ApiSecret, &remote.Sms.Vonage.ApiSecret)

// Compare external providers hide secrets and id
for provider, originalConfig := range original.External {
for provider, aConfig := range a.External {
if remoteConfig, exists := remote.External[provider]; exists {
diff.CompareSensitiveField(&originalConfig.Secret, &remoteConfig.Secret)
diff.CompareSensitiveField(&originalConfig.ClientId, &remoteConfig.ClientId)
diff.CompareSensitiveField(&originalConfig.RedirectUri, &remoteConfig.RedirectUri)
diff.CompareSensitiveField(&originalConfig.Url, &remoteConfig.Url)
diff.CompareSensitiveField(&aConfig.Secret, &remoteConfig.Secret)
remote.External[provider] = remoteConfig
original.External[provider] = originalConfig
a.External[provider] = aConfig
}
}
// Api sensitive fields
diff.CompareSensitiveField(&original.JwtSecret, &remote.JwtSecret)
diff.CompareSensitiveField(&original.AnonKey, &remote.AnonKey)
diff.CompareSensitiveField(&original.ServiceRoleKey, &remote.ServiceRoleKey)

// Third-party sensitive fields
diff.CompareSensitiveField(&original.ThirdParty.Firebase.ProjectID, &remote.ThirdParty.Firebase.ProjectID)
diff.CompareSensitiveField(&original.ThirdParty.Auth0.Tenant, &remote.ThirdParty.Auth0.Tenant)
diff.CompareSensitiveField(&original.ThirdParty.Cognito.UserPoolID, &remote.ThirdParty.Cognito.UserPoolID)
// Api sensitive fields
diff.CompareSensitiveField(&a.JwtSecret, &remote.JwtSecret)
diff.CompareSensitiveField(&a.AnonKey, &remote.AnonKey)
diff.CompareSensitiveField(&a.ServiceRoleKey, &remote.ServiceRoleKey)

// Hook secrets
diff.CompareSensitiveField(&original.Hook.MFAVerificationAttempt.Secrets, &remote.Hook.MFAVerificationAttempt.Secrets)
diff.CompareSensitiveField(&original.Hook.PasswordVerificationAttempt.Secrets, &remote.Hook.PasswordVerificationAttempt.Secrets)
diff.CompareSensitiveField(&original.Hook.CustomAccessToken.Secrets, &remote.Hook.CustomAccessToken.Secrets)
diff.CompareSensitiveField(&original.Hook.SendSMS.Secrets, &remote.Hook.SendSMS.Secrets)
diff.CompareSensitiveField(&original.Hook.SendEmail.Secrets, &remote.Hook.SendEmail.Secrets)
diff.CompareSensitiveField(&a.Hook.MFAVerificationAttempt.Secrets, &remote.Hook.MFAVerificationAttempt.Secrets)
diff.CompareSensitiveField(&a.Hook.PasswordVerificationAttempt.Secrets, &remote.Hook.PasswordVerificationAttempt.Secrets)
diff.CompareSensitiveField(&a.Hook.CustomAccessToken.Secrets, &remote.Hook.CustomAccessToken.Secrets)
diff.CompareSensitiveField(&a.Hook.SendSMS.Secrets, &remote.Hook.SendSMS.Secrets)
diff.CompareSensitiveField(&a.Hook.SendEmail.Secrets, &remote.Hook.SendEmail.Secrets)
}

func (a *auth) DiffWithRemote(remoteConfig v1API.AuthConfigResponse) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestFromRemoteAuthConfig(t *testing.T) {

assert.True(t, updatedAuth.EnableSignup)
assert.Equal(t, "https://example.com", updatedAuth.SiteUrl)
assert.Equal(t, uint(*remoteConfig.JwtExp), updatedAuth.JwtExpiry)
assert.Equal(t, 3600, updatedAuth.JwtExpiry)
assert.True(t, updatedAuth.Email.EnableConfirmations)
assert.True(t, updatedAuth.Email.SecurePasswordChange)
assert.True(t, updatedAuth.Sms.EnableConfirmations)
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestDiffWithRemote(t *testing.T) {
CustomAccessToken: hookConfig{
Enabled: true,
URI: "https://local.example.com/custom-token",
Secrets: "local_secrest",
Secrets: "local_secrets",
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ func tgs(x, y []string) []pair {
return seq
}

func CompareSensitiveField[T comparable](local *T, remote *T) {
func CompareSensitiveField(local *string, remote *string) {
if remote == nil {
return
}
if *local != *remote {
*local = any("<changed-sensitive-value-hidden>").(T)
*remote = any("<original-sensitive-value-hidden>").(T)
*local = "<changed-sensitive-value-hidden>"
*remote = "<original-sensitive-value-hidden>"
} else {
*local = any("<unchanged-sensitive-value-hidden>").(T)
*remote = any("<unchanged-sensitive-value-hidden>").(T)
*local = "<unchanged-sensitive-value-hidden>"
*remote = "<unchanged-sensitive-value-hidden>"
}
}

0 comments on commit 6ebd353

Please sign in to comment.