@@ -22,6 +22,7 @@ import (
2222 "strings"
2323
2424 "github.com/crunchydata/postgres-operator/internal/config"
25+ pgpassword "github.com/crunchydata/postgres-operator/internal/postgres/password"
2526 crv1 "github.com/crunchydata/postgres-operator/pkg/apis/crunchydata.com/v1"
2627 log "github.com/sirupsen/logrus"
2728 kerrors "k8s.io/apimachinery/pkg/api/errors"
4849 ErrDBContainerNotFound = errors .New ("\" database\" container not found in pod" )
4950 // ErrLabelInvalid indicates that a label is invalid
5051 ErrLabelInvalid = errors .New ("invalid label" )
52+ // ErrPasswordTypeInvalid is used when a string that's not included in
53+ // PasswordTypeStrings is used
54+ ErrPasswordTypeInvalid = errors .New ("invalid password type. choices are (md5, scram-sha-256)" )
5155 // ErrStandbyNotAllowed contains the error message returned when an API call is not
5256 // permitted because it involves a cluster that is in standby mode
5357 ErrStandbyNotAllowed = errors .New ("Action not permitted because standby mode is enabled" )
5862 "Operator installation" )
5963)
6064
65+ // passwordTypeStrings is a mapping of strings of password types to their
66+ // corresponding value of the structured password type
67+ var passwordTypeStrings = map [string ]pgpassword.PasswordType {
68+ "" : pgpassword .MD5 ,
69+ "md5" : pgpassword .MD5 ,
70+ "scram" : pgpassword .SCRAM ,
71+ "scram-sha-256" : pgpassword .SCRAM ,
72+ }
73+
6174func CreateRMDataTask (clusterName , replicaName , taskName string , deleteBackups , deleteData , isReplica , isBackup bool , ns , clusterPGHAScope string ) error {
6275 var err error
6376
@@ -100,6 +113,18 @@ func GetBackrestStorageTypes() []string {
100113 return backrestStorageTypes
101114}
102115
116+ // GetPasswordType returns the enumerated password type based on the string, and
117+ // an error if it cannot match one
118+ func GetPasswordType (passwordTypeStr string ) (pgpassword.PasswordType , error ) {
119+ passwordType , ok := passwordTypeStrings [passwordTypeStr ]
120+
121+ if ! ok {
122+ return passwordType , ErrPasswordTypeInvalid
123+ }
124+
125+ return passwordType , nil
126+ }
127+
103128// IsValidPVC determines if a PVC with the name provided exits
104129func IsValidPVC (pvcName , ns string ) bool {
105130 pvc , err := Clientset .CoreV1 ().PersistentVolumeClaims (ns ).Get (pvcName , metav1.GetOptions {})
0 commit comments