func (r *PostgreSqlReconciler) FetchUserPasswordFromSecret(namespace string, instance *sqlv1alpha1.PostgreSql, ctx context.Context, secretList kubeApiV1.SecretList) (map[string][]byte, error) {
	secretCred := make(map[string][]byte)
	err := r.List(ctx, &secretList, client.InNamespace(namespace))
	if err != nil {
		errMsg := fmt.Sprintf("unable to list secret in namespace %v", instance.Namespace)
		r.Log.Error(err, errMsg)
		return nil, err
	}
	for i, j := range GetSecretFromCR(instance) {
		isFound := false
		for _, k := range secretList.Items {
			if strings.TrimSpace(i) != k.Name {
				continue
			}
			isFound = true
			for _, p := range j {
				if _, exists := k.Data[p]; !exists {
					r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find secret key %q", p)
					return nil, fmt.Errorf("secret key %q/%q does not exist %v", p, namespace, err)
				}
				if util.IsValidPasswordFormat(string(k.Data[p])) {
					secretCred[p] = k.Data[p]
				} else {
					r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "InvalidPassword", "secret key %q. Must respect password rules: at least 7 letters - at least 1 number - at least 1 upper case - at least 1 special character", p)
					return nil, fmt.Errorf("secret %q/%q does not respect password rules - error %v", p, namespace, err)
				}

			}

		}
		if !isFound {
			r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find secret %q", i)
			return nil, fmt.Errorf("secret %v does not exist in namespace %v - error %v", i, namespace, err)
		}
	}
	return secretCred, nil
}
//FetchUserPasswordFromSecret fetch secret from namespace based on CR
FetchUserPasswordFromSecret fetch secret from namespace based on CR
// FetchUserPasswordFromSecret fetch secret from namespace based on CR
func (r *PostgreSqlReconciler) FetchUserPasswordFromSecret(namespace string, instance *sqlv1alpha1.PostgreSql, ctx context.Context, secretList kubeApiV1.SecretList) (map[string][]byte, error) {
	secretCred := make(map[string][]byte)
	err := r.List(ctx, &secretList, client.InNamespace(namespace))
	if err != nil {
		errMsg := fmt.Sprintf("unable to list secret in namespace %v", instance.Namespace)
		r.Log.Error(err, errMsg)
		return nil, err
	}
	for i, j := range GetSecretFromCR(instance) {
		isFound := false
		for _, k := range secretList.Items {
			if strings.TrimSpace(i) != k.Name {
				continue
			}
			isFound = true
			for _, p := range j {
				if _, exists := k.Data[p]; !exists {
					r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find secret key %q", p)
					return nil, fmt.Errorf("secret key %q/%q does not exist %v", p, namespace, err)
				}
				if util.IsValidPasswordFormat(string(k.Data[p])) {
					secretCred[p] = k.Data[p]
				} else {
					r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "InvalidPassword", "secret key %q. Must respect password rules: at least 7 letters - at least 1 number - at least 1 upper case - at least 1 special character", p)
					return nil, fmt.Errorf("secret %q/%q does not respect password rules - error %v", p, namespace, err)
				}
			}
		}
		if !isFound {
			r.Recorder.Eventf(instance, kubeApiV1.EventTypeWarning, "KeyNotFound", "unable to find secret %q", i)
			return nil, fmt.Errorf("secret %v does not exist in namespace %v - error %v", i, namespace, err)
		}
	}
	return secretCred, nil
}
func ( r * PostgreSqlReconciler ) FetchUserPasswordFromSecret ( namespace string , instance * sqlv1alpha1 . PostgreSql , ctx context . Context , secretList kubeApiV1 . SecretList ) ( map [ string ] [ ] byte , error ) { secretCred := make ( map [ string ] [ ] byte ) err := r . List ( ctx , & secretList , client . InNamespace ( namespace ) ) if err != nil { errMsg := fmt . Sprintf ( " " , instance . Namespace ) r . Log . Error ( err , errMsg ) return nil , err } for i , j := range GetSecretFromCR ( instance ) { isFound := false for _ , k := range secretList . Items { if strings . TrimSpace ( i ) != k . Name { continue } isFound = true for _ , p := range j { if _ , exists := k . Data [ p ] ; ! exists { r . Recorder . Eventf ( instance , kubeApiV1 . EventTypeWarning , " " , " " , p ) return nil , fmt . Errorf ( " " , p , namespace , err ) } if util . IsValidPasswordFormat ( string ( k . Data [ p ] ) ) { secretCred [ p ] = k . Data [ p ] } else { r . Recorder . Eventf ( instance , kubeApiV1 . EventTypeWarning , " " , " " , p ) return nil , fmt . Errorf ( " " , p , namespace , err ) } } } if ! isFound { r . Recorder . Eventf ( instance , kubeApiV1 . EventTypeWarning , " " , " " , i ) return nil , fmt . Errorf ( " " , i , namespace , err ) } } return secretCred , nil }
FetchUserPasswordFromSecret fetch secret from namespace based on CR
FetchUserPasswordFromSecret fetch secret from namespace based on CR