Skip to content

Commit

Permalink
Testing and bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
digiserg committed Dec 13, 2021
1 parent 5a969a3 commit 74f0798
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
14 changes: 9 additions & 5 deletions charts/vals-operator/crds/valssecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,22 @@ spec:
- passwordKey
- secretName
type: object
passwordKey:
description: Key in the secret containing the database username
type: string
port:
description: Database port number
type: integer
query:
description: Query to run for example to update a password or
create an account
userHost:
description: Used for MySQL only, the host part for the username
type: string
usernameKey:
description: Key in the secret containing the database username
type: string
required:
- driver
- hosts
- port
- query
- passwordKey
type: object
type: array
name:
Expand Down
16 changes: 13 additions & 3 deletions controllers/valssecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,25 @@ func (r *ValsSecretReconciler) updateDatabases(sDef *secretv1.ValsSecret, secret
if sDef.Spec.Databases[db].LoginCredentials.UsernameKey != "" {
loginUsername = string(dbSecret.Data[sDef.Spec.Databases[db].LoginCredentials.UsernameKey])
}

username := string(secret.Data[sDef.Spec.Databases[db].UsernameKey])
password := string(secret.Data[sDef.Spec.Databases[db].PasswordKey])

if username == "" || password == "" {
msg := fmt.Sprintf("'%s' or '%s' keys do not point to a valid username or password",
sDef.Spec.Databases[db].UsernameKey, sDef.Spec.Databases[db].PasswordKey)
r.Log.Error(err, msg)
return
}

dbQuery := dbType.DatabaseQuery{
Username: string(dbSecret.Data[sDef.Spec.Databases[db].UsernameKey]),
Password: string(dbSecret.Data[sDef.Spec.Databases[db].PasswordKey]),
Username: username,
Password: password,
UserHost: string(dbSecret.Data[sDef.Spec.Databases[db].UserHost]),
LoginUsername: loginUsername,
LoginPassword: string(dbSecret.Data[sDef.Spec.Databases[db].LoginCredentials.PasswordKey]),
Driver: sDef.Spec.Databases[db].Driver,
Hosts: sDef.Spec.Databases[db].Hosts,
SecretData: secret.Data,
Port: sDef.Spec.Databases[db].Port,
}
if err := valsDb.UpdateUserPassword(dbQuery); err != nil {
Expand Down
1 change: 0 additions & 1 deletion db/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func runPostgresQuery(dbQuery dbType.DatabaseQuery, host string) error {
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s connect_timeout=5 sslmode=disable",
host, dbQuery.Port, dbQuery.LoginUsername, dbQuery.LoginPassword, "postgres")

fmt.Println(psqlconn)
db, err := sql.Open("postgres", psqlconn)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion db/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ type DatabaseQuery struct {
LoginPassword string
Hosts []string
Port int
SecretData map[string][]byte
Driver string
}

0 comments on commit 74f0798

Please sign in to comment.