Skip to content

Commit 0276c25

Browse files
authored
internal: support changing passwords. (#585)
feat(user): support changing passwords.
1 parent bc0c2a9 commit 0276c25

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/sql_runner.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func CreateUserIfNotExists(sqlRunner SQLRunner, user *apiv1alpha1.MysqlUser, pas
346346

347347
queries := []Query{
348348
getCreateUserQuery(userName, pass, hosts, user.Spec.TLSOptions),
349-
// todo: getAlterUserQuery.
349+
getAlterUserQuery(userName, pass, hosts),
350350
}
351351

352352
if len(permissions) > 0 {
@@ -373,6 +373,18 @@ func getUserTLSRequire(tlsOption apiv1alpha1.TLSOptions) string {
373373
return fmt.Sprintf(" REQUIRE %s", tlsOption.Type)
374374
}
375375

376+
// Only support changing passwords.
377+
func getAlterUserQuery(user, pwd string, allowedHosts []string) Query {
378+
args := []interface{}{}
379+
q := "ALTER USER"
380+
381+
ids, idsArgs := getUsersIdentification(user, &pwd, allowedHosts)
382+
q += ids
383+
args = append(args, idsArgs...)
384+
385+
return NewQuery(q, args...)
386+
}
387+
376388
func getUsersIdentification(user string, pwd *string, allowedHosts []string) (ids string, args []interface{}) {
377389
for i, host := range allowedHosts {
378390
// Add comma if more than one allowed hosts are used.

0 commit comments

Comments
 (0)