MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / GetCredentials

Function GetCredentials

tests/utils/secrets/secrets.go:78–114  ·  view source on GitHub ↗

GetCredentials retrieve username and password from secrets and return it as per user suffix

(
	ctx context.Context,
	crudClient client.Client,
	clusterName, namespace, secretSuffix string,
)

Source from the content-addressed store, hash-verified

76
77// GetCredentials retrieve username and password from secrets and return it as per user suffix
78func GetCredentials(
79 ctx context.Context,
80 crudClient client.Client,
81 clusterName, namespace, secretSuffix string,
82) (
83 string, string, error,
84) {
85 // Get the cluster
86 cluster, err := clusterutils.Get(ctx, crudClient, namespace, clusterName)
87 if err != nil {
88 return "", "", err
89 }
90
91 var secretName string
92 switch secretSuffix {
93 case apiv1.SuperUserSecretSuffix:
94 secretName = cluster.GetSuperuserSecretName()
95 case apiv1.ApplicationUserSecretSuffix:
96 secretName = cluster.GetApplicationSecretName()
97 default:
98 return "", "", fmt.Errorf("unexpected secretSuffix %s", secretSuffix)
99 }
100
101 // Get the password as per user suffix in secret
102 secret := &corev1.Secret{}
103 secretNamespacedName := types.NamespacedName{
104 Namespace: namespace,
105 Name: secretName,
106 }
107 err = crudClient.Get(ctx, secretNamespacedName, secret)
108 if err != nil {
109 return "", "", err
110 }
111 username := string(secret.Data["username"])
112 password := string(secret.Data["password"])
113 return username, password, nil
114}
115
116// CopyOperatorPullSecretToServiceAccount copies the operator pull secret from
117// the operator namespace to the target namespace and adds it as an

Calls 4

GetFunction · 0.92
GetMethod · 0.45

Tested by 1