Skip to content

fix: Fix the problem of failed MySQL permission modification#8351

Merged
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@fix_mysql_user
Apr 8, 2025
Merged

fix: Fix the problem of failed MySQL permission modification#8351
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@fix_mysql_user

Conversation

@ssongliu
Copy link
Copy Markdown
Member

@ssongliu ssongliu commented Apr 8, 2025

No description provided.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

return nil
}
if err := r.CreateUser(CreateInfo{
Name: info.Name,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code provided contains a few issues and potential improvements:

  1. Redundancy in Delete Method Call: The first branch of the conditional statement deletes the user with old permissions, while the second branch does not. This can lead to unintended behavior if there are no existing users with that permission.

  2. Handling Root User Deletion: The root user is handled differently based on whether the condition is met within the loop or after it. However, this logic seems unnecessary given how the root user deletion should only occur when all checks pass.

  3. Optimization Suggestion:

    • Remove the redundant info.Name = "*". It doesn't affect function behavior but could be removed for clarity.

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:

  • Simplified the conditional structure using a switch, making the code more concise.
  • Removed the info.Name = "*" assignment since it wasn't doing anything meaningful.
  • Added a default case to handle cases where info.Permission isn’t an empty string, ensuring proper handling of both new and permission changes.

return nil
}
if err := r.CreateUser(CreateInfo{
Name: info.Name,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

}
if len(account) != 0 {
_, _ = accountMap[account].client.Delete(path.Join(accountMap[account].backupPath, records[i].FileDir, records[i].FileName))
}
Copy link
Copy Markdown
Member

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:

  1. 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.

    for _, account := range accounts {
        if _, ok := accountMap[account]; !ok {
            continue
        }
        // Rest of the deletion logic
    }
  2. Code Readability:

    • The line if _, ok := accountMap[account]; !ok { could use continue; on its own per iteration instead of repeating the expression multiple times.
    • Consider extracting the client creation logic into a helper function to maintain cleaner code structure.

Overall, the patch looks well-maintained and optimized given the current constraints.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2025

Copy link
Copy Markdown
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Copy Markdown
Member

/approve

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot added the approved label Apr 8, 2025
@f2c-ci-robot f2c-ci-robot Bot merged commit a5629e3 into dev Apr 8, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev@fix_mysql_user branch April 8, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants