Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client-database): removes the base64 deserialization of secret.D… #76

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
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
23 changes: 14 additions & 9 deletions pkg/client/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

dbv1alpha1 "github.com/zncdatadev/operator-go/pkg/apis/database/v1alpha1"
"github.com/zncdatadev/operator-go/pkg/util"
)

type DataBaseType string
Expand Down Expand Up @@ -127,10 +126,10 @@ func (d *DatabaseConfiguration) GetRefDatabaseConnection(name string) (dbv1alpha
}

func (d *DatabaseConfiguration) GetCredential(name string) (*DatabaseCredential, error) {

namespace := d.GetNamespace()
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: d.GetNamespace(),
Namespace: namespace,
Name: name,
},
}
Expand All @@ -139,14 +138,20 @@ func (d *DatabaseConfiguration) GetCredential(name string) (*DatabaseCredential,
return nil, err
}

username, err := util.Base64[[]byte]{Data: secret.Data[DbUsernameName]}.Decode()
if err != nil {
return nil, err
username, ok := secret.Data[DbUsernameName]
if !ok {
return nil, fmt.Errorf("username not found in secret. Name: %s, Namespace %s", name, namespace)
}
if username == nil {
return nil, fmt.Errorf("username is empty in secret. Name: %s, Namespace %s", name, namespace)
}

password, err := util.Base64[[]byte]{Data: secret.Data[DbPasswordName]}.Decode()
if err != nil {
return nil, err
password, ok := secret.Data[DbPasswordName]
if !ok {
return nil, fmt.Errorf("password not found in secret. Name: %s, Namespace %s", name, namespace)
}
if password == nil {
return nil, fmt.Errorf("password is empty in secret. Name: %s, Namespace %s", name, namespace)
}

return &DatabaseCredential{
Expand Down
Loading