-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
DBPW - Migrate MySQL db to v5 database engine #10110
Conversation
"time" | ||
|
||
stdmysql "github.com/go-sql-driver/mysql" | ||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend running goimports
on this
plugins/database/mysql/mysql.go
Outdated
} | ||
|
||
password := req.Password | ||
|
||
expirationStr := req.Expiration.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be:
expirationStr := req.Expiration.String() | |
expirationStr := req.Expiration.Format("2006-01-02 15:04:05-0700") |
otherwise the formatting will be dramatically different.
plugins/database/mysql/mysql.go
Outdated
var dispName, roleName, maxLen credsutil.UsernameOpt | ||
|
||
if m.legacy { | ||
dispName = credsutil.DisplayName(req.UsernameConfig.DisplayName, LegacyUsernameLen) | ||
roleName = credsutil.RoleName(req.UsernameConfig.RoleName, LegacyMetadataLen) | ||
maxLen = credsutil.MaxLength(LegacyUsernameLen) | ||
} else { | ||
dispName = credsutil.DisplayName(req.UsernameConfig.DisplayName, UsernameLen) | ||
roleName = credsutil.RoleName(req.UsernameConfig.RoleName, MetadataLen) | ||
maxLen = credsutil.MaxLength(UsernameLen) | ||
} | ||
|
||
username, err := credsutil.GenerateUsername(dispName, roleName, maxLen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could be simpler:
var dispName, roleName, maxLen credsutil.UsernameOpt | |
if m.legacy { | |
dispName = credsutil.DisplayName(req.UsernameConfig.DisplayName, LegacyUsernameLen) | |
roleName = credsutil.RoleName(req.UsernameConfig.RoleName, LegacyMetadataLen) | |
maxLen = credsutil.MaxLength(LegacyUsernameLen) | |
} else { | |
dispName = credsutil.DisplayName(req.UsernameConfig.DisplayName, UsernameLen) | |
roleName = credsutil.RoleName(req.UsernameConfig.RoleName, MetadataLen) | |
maxLen = credsutil.MaxLength(UsernameLen) | |
} | |
username, err := credsutil.GenerateUsername(dispName, roleName, maxLen) | |
var dispNameLen, roleNameLen, maxLen int | |
if m.legacy { | |
dispName = LegacyUsernameLen | |
roleName = LegacyMetadataLen | |
maxLen = LegacyUsernameLen | |
} else { | |
dispName = UsernameLen | |
roleName = MetadataLen | |
maxLen = UsernameLen | |
} | |
username, err := credsutil.GenerateUsername( | |
credsutil.DisplayName(req.UsernameConfig.DisplayName, dispNameLen), | |
credsutil.RoleName(req.UsernameConfig.RoleName), | |
credsutil.MaxLength(maxLen), | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, I wasn't sure which would be the better approach. Your suggestion isolates the differences more succinctly.
if err := tx.Commit(); err != nil { | ||
return nil, err | ||
} | ||
return newdbplugin.UpdateUserResponse{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put a comment saying that expiration changes are a no-op?
} | ||
|
||
db = new(false) | ||
_, err = db.Initialize(context.Background(), initReq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, you can use the sdk/database/newdbplugin/testing/ package for some of these. It has assertion functions for each of the DB functions such as AssertInitialize
which takes a *testing.T
object, a DB instance, and a request and does all of the boilerplate around running it (creating a context and asserting that the function did not error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep that in mind for the next DB I do and utilize it then. If we come back to it, I'll redo this one. Thanks for the tip though!
Overview
Converts plugin to use the Database v5 interface introduced in #9641
Design of Change
Converted each of the functions over to their equivalent in the new interface.
Init
->Initialize
CreateUser
->NewUser
RenewUser
,SetCredentials
, &RotateRootCredentials
->UpdateUser
RevokeUser
->DeleteUser
Test Output
Test Output
``` === RUN TestMySQL_Initialize --- PASS: TestMySQL_Initialize (13.38s) === RUN TestMySQL_CreateUser --- PASS: TestMySQL_CreateUser (28.95s) === RUN TestMySQL_CreateUser/missing_creation_statements --- PASS: TestMySQL_CreateUser/missing_creation_statements (0.00s) === RUN TestMySQL_CreateUser/non-legacy --- PASS: TestMySQL_CreateUser/non-legacy (12.39s) === RUN TestMySQL_CreateUser/non-legacy/prepared_statement_name --- PASS: TestMySQL_CreateUser/non-legacy/prepared_statement_name (0.02s) === RUN TestMySQL_CreateUser/non-legacy/prepared_statement_username --- PASS: TestMySQL_CreateUser/non-legacy/prepared_statement_username (0.02s) === RUN TestMySQL_CreateUser/non-legacy/create_name --- PASS: TestMySQL_CreateUser/non-legacy/create_name (0.02s) === RUN TestMySQL_CreateUser/non-legacy/create_username --- PASS: TestMySQL_CreateUser/non-legacy/create_username (0.02s) === RUN TestMySQL_CreateUser/legacy --- PASS: TestMySQL_CreateUser/legacy (16.56s) === RUN TestMySQL_CreateUser/legacy/prepared_statement_name --- PASS: TestMySQL_CreateUser/legacy/prepared_statement_name (0.02s) === RUN TestMySQL_CreateUser/legacy/prepared_statement_username --- PASS: TestMySQL_CreateUser/legacy/prepared_statement_username (0.02s) === RUN TestMySQL_CreateUser/legacy/create_name --- PASS: TestMySQL_CreateUser/legacy/create_name (0.02s) === RUN TestMySQL_CreateUser/legacy/create_username --- PASS: TestMySQL_CreateUser/legacy/create_username (0.02s) === RUN TestMySQL_RotateRootCredentials --- PASS: TestMySQL_RotateRootCredentials (37.78s) === RUN TestMySQL_RotateRootCredentials/empty_statements --- PASS: TestMySQL_RotateRootCredentials/empty_statements (12.21s) === RUN TestMySQL_RotateRootCredentials/default_username --- PASS: TestMySQL_RotateRootCredentials/default_username (13.46s) === RUN TestMySQL_RotateRootCredentials/default_name --- PASS: TestMySQL_RotateRootCredentials/default_name (12.10s) === RUN TestMySQL_DeleteUser --- PASS: TestMySQL_DeleteUser (11.97s) === RUN TestMySQL_DeleteUser/empty_statements --- PASS: TestMySQL_DeleteUser/empty_statements (0.02s) === RUN TestMySQL_DeleteUser/default_name --- PASS: TestMySQL_DeleteUser/default_name (0.02s) === RUN TestMySQL_DeleteUser/default_username --- PASS: TestMySQL_DeleteUser/default_username (0.02s) === RUN TestMySQL_UpdateUser --- PASS: TestMySQL_UpdateUser (39.02s) === RUN TestMySQL_UpdateUser/custom_statement_username --- PASS: TestMySQL_UpdateUser/custom_statement_username (12.35s) === RUN TestMySQL_UpdateUser/empty_statements --- PASS: TestMySQL_UpdateUser/empty_statements (13.81s) === RUN TestMySQL_UpdateUser/custom_statement_name --- PASS: TestMySQL_UpdateUser/custom_statement_name (12.86s) === RUN TestMySQL_Initialize_ReservedChars --- PASS: TestMySQL_Initialize_ReservedChars (13.83s) PASSProcess finished with exit code 0