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

plugins/database: Allow both {{name}} and {{username}} in MySQL & Postgres #8240

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion plugins/database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (m *MySQL) CreateUser(ctx context.Context, statements dbplugin.Statements,

queryMap := map[string]string{
"name": username,
"username": username,
"password": password,
"expiration": expirationStr,
}
Expand Down Expand Up @@ -187,6 +188,7 @@ func (m *MySQL) RevokeUser(ctx context.Context, statements dbplugin.Statements,
// 1295: This command is not supported in the prepared statement protocol yet
// Reference https://mariadb.com/kb/en/mariadb/prepare-statement/
query = strings.Replace(query, "{{name}}", username, -1)
query = strings.Replace(query, "{{username}}", username, -1)
_, err = tx.ExecContext(ctx, query)
if err != nil {
return err
Expand Down Expand Up @@ -244,6 +246,7 @@ func (m *MySQL) RotateRootCredentials(ctx context.Context, statements []string)
// 1295: This command is not supported in the prepared statement protocol yet
// Reference https://mariadb.com/kb/en/mariadb/prepare-statement/
query = strings.Replace(query, "{{username}}", m.Username, -1)
query = strings.Replace(query, "{{name}}", m.Username, -1)
query = strings.Replace(query, "{{password}}", password, -1)

if _, err := tx.ExecContext(ctx, query); err != nil {
Expand Down Expand Up @@ -283,10 +286,11 @@ func (m *MySQL) SetCredentials(ctx context.Context, statements dbplugin.Statemen

queryMap := map[string]string{
"name": username,
"username": username,
"password": password,
}

if err := m.executePreparedStatmentsWithMap(ctx, statements.Rotation, queryMap); err != nil {
if err := m.executePreparedStatmentsWithMap(ctx, rotateStatements, queryMap); err != nil {
return "", "", err
}
return username, password, nil
Expand Down
Loading