Skip to content

Commit 14385cc

Browse files
committed
chore: unban all ip on failure to connect
1 parent a9e7ed3 commit 14385cc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

internal/utils/flags/db_url.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,6 @@ func initLoginRole(ctx context.Context, projectRef string, config *pgconn.Config
171171
}
172172

173173
func initPoolerLogin(ctx context.Context, projectRef string, poolerConfig *pgconn.Config) error {
174-
// Prefer password prompt because temp login is unstable using pooler
175-
resetUrl := fmt.Sprintf("%s/project/%s/settings/database", utils.GetSupabaseDashboardURL(), projectRef)
176-
fmt.Fprintln(os.Stderr, "Forgot your password? Reset it from the Dashboard:", utils.Bold(resetUrl))
177-
fmt.Fprint(os.Stderr, "Enter your database password (or leave blank to use temporary login): ")
178-
if poolerConfig.Password = credentials.PromptMasked(os.Stdin); len(poolerConfig.Password) > 0 {
179-
return nil
180-
}
181174
poolerUser := poolerConfig.User
182175
if err := initLoginRole(ctx, projectRef, poolerConfig); err != nil {
183176
return err
@@ -195,10 +188,18 @@ func initPoolerLogin(ctx context.Context, projectRef string, poolerConfig *pgcon
195188
return conn.Close(ctx)
196189
}
197190
notify := utils.NewErrorCallback(func(attempt uint) error {
198-
if attempt%3 > 0 {
191+
if attempt > 2 {
192+
return nil
193+
}
194+
resp, err := utils.GetSupabase().V1ListAllNetworkBansWithResponse(ctx, projectRef)
195+
if err != nil {
196+
return errors.Errorf("failed to list network bans: %w", err)
197+
} else if resp.JSON201 == nil {
198+
return errors.Errorf("unexpected list bans status %d: %s", resp.StatusCode(), string(resp.Body))
199+
} else if len(resp.JSON201.BannedIpv4Addresses) == 0 {
199200
return nil
200201
}
201-
return UnbanIP(ctx, projectRef)
202+
return UnbanIP(ctx, projectRef, resp.JSON201.BannedIpv4Addresses...)
202203
})
203204
return backoff.RetryNotify(login, utils.NewBackoffPolicy(ctx), notify)
204205
}

0 commit comments

Comments
 (0)