-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Fix the problem of failed MySQL permission modification #8351
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,18 +188,19 @@ func (r *Local) ChangeAccess(info AccessChangeInfo) error { | |
| info.Name = "*" | ||
| info.Password = r.Password | ||
| } | ||
| if info.Permission != info.OldPermission { | ||
| if err := r.Delete(DeleteInfo{ | ||
| Version: info.Version, | ||
| Username: info.Username, | ||
| Permission: info.OldPermission, | ||
| ForceDelete: true, | ||
| Timeout: 300}); err != nil { | ||
| return err | ||
| } | ||
| if info.Username == "root" { | ||
| return nil | ||
| } | ||
| if info.Permission == info.OldPermission { | ||
| return nil | ||
| } | ||
| if err := r.Delete(DeleteInfo{ | ||
| Version: info.Version, | ||
| Username: info.Username, | ||
| Permission: info.OldPermission, | ||
| ForceDelete: true, | ||
| Timeout: 300}); err != nil { | ||
| return err | ||
| } | ||
| if info.Username == "root" { | ||
| return nil | ||
| } | ||
| if err := r.CreateUser(CreateInfo{ | ||
| Name: info.Name, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code provided contains a few issues and potential improvements:
Here's the cleaned-up version: func (r *Local) ChangeAccess(info AccessChangeInfo) error {
info.Password = r.Password
switch {
case info.Permission != "":
if err := r.Delete(DeleteInfo{
Version: info.Version,
Username: info.Username,
Permission: info.OldPermission,
ForceDelete: true,
Timeout: 300}); err != nil {
return err
}
if info.Username == "root" {
return nil
}
default:
if err := r.createUser(CreateInfo{
Name: info.Name,
// Rest of the createUser parameters
}); err != nil {
return err
}
return r.changeUserAccess(UserModifyOptions{ // Assuming changeUserAccess exists
OldPermissions: []string{info.OldPermission},
NewPermissions: []string{info.Permission},
Usernames: []string{info.Username},
Version: info.Version,
})
}
}Key Improvements Made:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,18 +199,19 @@ func (r *Remote) ChangeAccess(info AccessChangeInfo) error { | |
| info.Name = "*" | ||
| info.Password = r.Password | ||
| } | ||
| if info.Permission != info.OldPermission { | ||
| if err := r.Delete(DeleteInfo{ | ||
| Version: info.Version, | ||
| Username: info.Username, | ||
| Permission: info.OldPermission, | ||
| ForceDelete: true, | ||
| Timeout: 300}); err != nil { | ||
| return err | ||
| } | ||
| if info.Username == "root" { | ||
| return nil | ||
| } | ||
| if info.Permission == info.OldPermission { | ||
| return nil | ||
| } | ||
| if err := r.Delete(DeleteInfo{ | ||
| Version: info.Version, | ||
| Username: info.Username, | ||
| Permission: info.OldPermission, | ||
| ForceDelete: true, | ||
| Timeout: 300}); err != nil { | ||
| return err | ||
| } | ||
| if info.Username == "root" { | ||
| return nil | ||
| } | ||
| if err := r.CreateUser(CreateInfo{ | ||
| Name: info.Name, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no significant irregularity, issue, or optimization suggestion in the provided code snippet. The changes you made to modify permission handling do not seem to introduce any new problems or improve efficiency beyond what was already present in the original version. |
||
|
|
||
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.
The changes made do not have significant irregularities or issues.
However, there is room for improvement:
Comments: The comment about skipping accounts that cannot be found in the map can be moved outside of the loop if you want to reduce redundant checks within each iteration cycle.
Code Readability:
if _, ok := accountMap[account]; !ok {could usecontinue;on its own per iteration instead of repeating the expression multiple times.Overall, the patch looks well-maintained and optimized given the current constraints.