Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
code style
  • Loading branch information
yanchenko-igor committed Jul 10, 2020
commit 99a2c4359bef1a8b7057b3f69535b546bab23851
5 changes: 3 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ func NameFromMeta(meta metav1.ObjectMeta) spec.NamespacedName {
Name: meta.Name,
}
}

type Hasher func(user spec.PgUser) string
type Random func(n int) string

type Encryptor struct {
encrypt Hasher
random Random
random Random
}

func NewEncryptor(encryption string) *Encryptor {
e := Encryptor{random:RandomPassword}
e := Encryptor{random: RandomPassword}
m := map[string]Hasher{
"md5": e.PGUserPasswordMD5,
"scram-sha-256": e.PGUserPasswordScramSHA256,
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

var pgUsers = []struct {
in spec.PgUser
outmd5 string
in spec.PgUser
outmd5 string
outscramsha256 string
}{{spec.PgUser{
Name: "test",
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestPGUserPassword(t *testing.T) {
t.Errorf("PgUserPassword expected: %q, got: %q", tt.outmd5, pwd)
}
e = NewEncryptor("scram-sha-256")
e.random = func(n int) string {return "salt"}
e.random = func(n int) string { return "salt" }
pwd = e.PGUserPassword(tt.in)
if pwd != tt.outscramsha256 {
t.Errorf("PgUserPassword expected: %q, got: %q", tt.outscramsha256, pwd)
Expand Down