Skip to content

Commit

Permalink
fix: update how config is set
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Apr 19, 2024
1 parent e4c0250 commit 50c5775
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 42 deletions.
7 changes: 5 additions & 2 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ EOF
env,
"GOTRUE_HOOK_MFA_VERIFICATION_ATTEMPT_ENABLED=true",
"GOTRUE_HOOK_MFA_VERIFICATION_ATTEMPT_URI="+utils.Config.Auth.Hook.MFAVerificationAttempt.URI,
"GOTRUE_HOOK_MFA_VERIFICATION_ATTEMPT_SECRETS="+utils.Config.Auth.Hook.MFAVerificationAttempt.Secrets,
)
}

Expand All @@ -505,6 +506,7 @@ EOF
env,
"GOTRUE_HOOK_PASSWORD_VERIFICATION_ATTEMPT_ENABLED=true",
"GOTRUE_HOOK_PASSWORD_VERIFICATION_ATTEMPT_URI="+utils.Config.Auth.Hook.PasswordVerificationAttempt.URI,
"GOTRUE_HOOK_PASSWORD_VERIFICATION_ATTEMPT_SECRETS="+utils.Config.Auth.Hook.PasswordVerificationAttempt.Secrets,
)
}

Expand All @@ -513,6 +515,7 @@ EOF
env,
"GOTRUE_HOOK_CUSTOM_ACCESS_TOKEN_ENABLED=true",
"GOTRUE_HOOK_CUSTOM_ACCESS_TOKEN_URI="+utils.Config.Auth.Hook.CustomAccessToken.URI,
"GOTRUE_HOOK_CUSTOM_ACCESS_TOKEN_SECRETS="+utils.Config.Auth.Hook.CustomAccessToken.Secrets,
)
}

Expand All @@ -521,7 +524,7 @@ EOF
env,
"GOTRUE_HOOK_SEND_SMS_ENABLED=true",
"GOTRUE_HOOK_SEND_SMS_URI="+utils.Config.Auth.Hook.SendSMS.URI,
"GOTRUE_HOOK_SEND_SMS_SECRETS="+utils.Config.Auth.Hook.SendSMS.HTTPHookSecrets,
"GOTRUE_HOOK_SEND_SMS_SECRETS="+utils.Config.Auth.Hook.SendSMS.Secrets,
)
}

Expand All @@ -530,7 +533,7 @@ EOF
env,
"GOTRUE_HOOK_SEND_EMAIL_ENABLED=true",
"GOTRUE_HOOK_SEND_EMAIL_URI="+utils.Config.Auth.Hook.SendEmail.URI,
"GOTRUE_HOOK_SEND_EMAIL_SECRETS="+utils.Config.Auth.Hook.SendEmail.HTTPHookSecrets,
"GOTRUE_HOOK_SEND_EMAIL_SECRETS="+utils.Config.Auth.Hook.SendEmail.Secrets,
)
}

Expand Down
70 changes: 30 additions & 40 deletions internal/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ type (
}

hookConfig struct {
Enabled bool `toml:"enabled"`
URI string `toml:"uri"`
HTTPHookSecrets string `toml:"secrets"`
Enabled bool `toml:"enabled"`
URI string `toml:"uri"`
Secrets string `toml:"secrets"`
}

twilioConfig struct {
Expand Down Expand Up @@ -464,6 +464,23 @@ type (
// }
)

func (h *hookConfig) HandleHook(hookType string) error {
if !h.Enabled {
return nil // If not enabled, do nothing
}
if h.URI == "" {
return fmt.Errorf("missing required field in config: auth.hook.%s.uri", hookType)
}
if err := validateHTTPHookURI(h.URI, hookType); err != nil {
return err
}
var err error
if h.Secrets, err = maybeLoadEnv(h.Secrets); err != nil {
return fmt.Errorf("missing required field in config: auth.hook.%s.secrets", hookType)
}
return nil
}

func LoadConfigFS(fsys afero.Fs) error {
// Load default values
var buf bytes.Buffer
Expand Down Expand Up @@ -691,48 +708,21 @@ func LoadConfigFS(fsys afero.Fs) error {
return err
}
}

if Config.Auth.Hook.MFAVerificationAttempt.Enabled {
if Config.Auth.Hook.MFAVerificationAttempt.URI == "" {
return errors.New("Missing required field in config: auth.hook.mfa_verification_atempt.uri")
}
if err := Config.Auth.Hook.MFAVerificationAttempt.HandleHook("mfa_verification_attempt"); err != nil {
return err
}

if Config.Auth.Hook.PasswordVerificationAttempt.Enabled {
if Config.Auth.Hook.PasswordVerificationAttempt.URI == "" {
return errors.New("Missing required field in config: auth.hook.password_verification_attempt.uri")
}
if err := Config.Auth.Hook.PasswordVerificationAttempt.HandleHook("password_verification_attempt"); err != nil {
return err
}

if Config.Auth.Hook.CustomAccessToken.Enabled {
if Config.Auth.Hook.CustomAccessToken.URI == "" {
return errors.New("Missing required field in config: auth.hook.custom_access_token.uri")
}
if err := Config.Auth.Hook.CustomAccessToken.HandleHook("custom_access_token"); err != nil {
return err
}

if Config.Auth.Hook.SendSMS.Enabled {
if Config.Auth.Hook.SendSMS.URI == "" {
return errors.New("Missing required field in config: auth.hook.send_sms.uri")
}
if err := validateHTTPHookURI(Config.Auth.Hook.SendSMS.URI, "send_sms"); err != nil {
return err
}
if Config.Auth.Hook.SendSMS.HTTPHookSecrets, err = maybeLoadEnv(Config.Auth.Hook.SendSMS.HTTPHookSecrets); err != nil {
return errors.New("Missing required field in config: auth.hook.send_sms.secrets")
}
if err := Config.Auth.Hook.SendSMS.HandleHook("send_sms"); err != nil {
return err
}
if Config.Auth.Hook.SendEmail.Enabled {
if Config.Auth.Hook.SendEmail.URI == "" {
return errors.New("Missing required field in config: auth.hook.send_email.uri")
}
if err := validateHTTPHookURI(Config.Auth.Hook.SendEmail.URI, "send_email"); err != nil {
return err
}
if Config.Auth.Hook.SendEmail.HTTPHookSecrets, err = maybeLoadEnv(Config.Auth.Hook.SendEmail.HTTPHookSecrets); err != nil {
return errors.New("Missing required field in config: auth.hook.send_email.secrets")
}
if err := Config.Auth.Hook.SendEmail.HandleHook("send_email"); err != nil {
return err
}

// Validate oauth config
for ext, provider := range Config.Auth.External {
if !provider.Enabled {
Expand Down

0 comments on commit 50c5775

Please sign in to comment.