Skip to content

Commit c0291c9

Browse files
author
Philip Hurst
committed
refactored logic to clearly capture four possible events
1 parent d086472 commit c0291c9

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

internal/pgbouncer/reconcile.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,22 @@ func Secret(ctx context.Context,
6666
password := string(inSecret.Data[passwordSecretKey])
6767
verifier := string(inSecret.Data[verifierSecretKey])
6868

69-
// If the password is empty, generate a new one.
70-
// Ignore the verifier for now.
71-
if err == nil && len(password) == 0 {
69+
if len(password) == 0 && len(verifier) == 0 {
70+
// If both the password and verifier are empty, generate new password and verifier.
7271
password, err = util.GenerateASCIIPassword(32)
7372
err = errors.WithStack(err)
74-
}
75-
76-
// If the verifier is empty, generate a new one.
77-
if err == nil && len(verifier) == 0 {
73+
if err == nil {
74+
verifier, err = passwd.NewSCRAMPassword(password).Build()
75+
err = errors.WithStack(err)
76+
}
77+
} else if len(password) != 0 && len(verifier) != 0 {
78+
// If both the password and verifier are non-empty, use them.
79+
} else if len(password) == 0 && len(verifier) != 0 {
80+
// If the password is empty and the verifier is non-empty, generate a new password.
81+
password, err = util.GenerateASCIIPassword(32)
82+
err = errors.WithStack(err)
83+
} else if len(password) != 0 && len(verifier) == 0 {
84+
// If the password is non-empty and the verifier is empty, generate a new verifier.
7885
verifier, err = passwd.NewSCRAMPassword(password).Build()
7986
err = errors.WithStack(err)
8087
}

0 commit comments

Comments
 (0)