Skip to content

Commit c76ce14

Browse files
author
Philip Hurst
committed
refactor to remove generatePassword func
1 parent 3816bb0 commit c76ce14

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

internal/pgbouncer/postgres.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
"github.com/crunchydata/postgres-operator/internal/logging"
1414
"github.com/crunchydata/postgres-operator/internal/postgres"
15-
"github.com/crunchydata/postgres-operator/internal/postgres/password"
16-
"github.com/crunchydata/postgres-operator/internal/util"
1715
)
1816

1917
const (
@@ -203,21 +201,6 @@ REVOKE ALL PRIVILEGES
203201
return err
204202
}
205203

206-
func generatePassword() (plaintext, verifier string, err error) {
207-
// PgBouncer can login to PostgreSQL using either MD5 or SCRAM-SHA-256.
208-
// When using MD5, the (hashed) verifier can be stored in PgBouncer's
209-
// authentication file. When using SCRAM, the plaintext password must be
210-
// stored.
211-
// - https://www.pgbouncer.org/config.html#authentication-file-format
212-
// - https://github.com/pgbouncer/pgbouncer/issues/508#issuecomment-713339834
213-
214-
plaintext, err = util.GenerateASCIIPassword(32)
215-
if err == nil {
216-
verifier, err = password.NewSCRAMPassword(plaintext).Build()
217-
}
218-
return
219-
}
220-
221204
func postgresqlHBAs() []*postgres.HostBasedAuthentication {
222205
// PgBouncer must connect over TLS using a SCRAM password. Other network
223206
// connections are forbidden.

internal/pgbouncer/reconcile.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
"github.com/crunchydata/postgres-operator/internal/naming"
1818
"github.com/crunchydata/postgres-operator/internal/pki"
1919
"github.com/crunchydata/postgres-operator/internal/postgres"
20-
pwd "github.com/crunchydata/postgres-operator/internal/postgres/password"
20+
passwd "github.com/crunchydata/postgres-operator/internal/postgres/password"
21+
"github.com/crunchydata/postgres-operator/internal/util"
2122
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2223
)
2324

@@ -62,13 +63,13 @@ func Secret(ctx context.Context,
6263
// If the password is empty, generate a new one.
6364
// Ignore the verifier for now.
6465
if err == nil && len(password) == 0 {
65-
password, _, err = generatePassword()
66+
password, err = util.GenerateASCIIPassword(32)
6667
err = errors.WithStack(err)
6768
}
6869

6970
// If the verifier is empty, generate a new one.
7071
if err == nil && len(verifier) == 0 {
71-
verifier, err = pwd.NewSCRAMPassword(password).Build()
72+
verifier, err = passwd.NewSCRAMPassword(password).Build()
7273
err = errors.WithStack(err)
7374
}
7475

0 commit comments

Comments
 (0)