in controllers/user/chain/create_user.go [108:132]
func (c *CreateUser) getSecretFromRef(ctx context.Context, refVal, secretNamespace string) (string, error) {
if !hasSecretRef(refVal) {
return "", fmt.Errorf("invalid config secret reference %s is not in format '$secretName:secretKey'", refVal)
}
ref := strings.Split(refVal[1:], ":")
if len(ref) != 2 {
return "", fmt.Errorf("invalid config secret reference %s is not in format '$secretName:secretKey'", refVal)
}
secret := &corev1.Secret{}
if err := c.client.Get(ctx, client.ObjectKey{
Namespace: secretNamespace,
Name: ref[0],
}, secret); err != nil {
return "", fmt.Errorf("failed to get secret %s: %w", ref[0], err)
}
secretVal, ok := secret.Data[ref[1]]
if !ok {
return "", fmt.Errorf("secret %s does not contain key %s", ref[0], ref[1])
}
return string(secretVal), nil
}