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

support changing a user's name with the new interfaces #184

Open
jacobweinstock opened this issue Jan 7, 2021 · 0 comments
Open

support changing a user's name with the new interfaces #184

jacobweinstock opened this issue Jan 7, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@jacobweinstock
Copy link
Member

with the new interfaces in ./bmc, In order to update an existing user's name, the client would need to call a combination of CreateUser and DeleteUser. I propose we add a helper function in user.go to handle this for the client.

I think the code below will cover it. I just need to do and add some tests and then I'll open a PR. Also, trying to get better at creating an issue before a PR :)

// UpdateUserNameFromInterfaces is a helper function that will update a user's name by calling delete and create
func UpdateUserNameFromInterfaces(ctx context.Context, currentUsername, newUsername, pass, role string, generic []interface{}) (ok bool, err error) {
	ok, err = CreateUserFromInterfaces(ctx, newUsername, pass, role, generic)
	if err != nil {
		return false, err
	}
	if !ok {
		return false, fmt.Errorf("updating username was NOT successful: creating user: %v, failed: reason unknown", newUsername)
	}
	ok, err = DeleteUserFromInterfaces(ctx, currentUsername, generic)
	if err != nil {
		ok, err = DeleteUserFromInterfaces(ctx, newUsername, generic)
		if err != nil {
			return false, multierror.Append(err, err)
		}
		if !ok {
			err = multierror.Append(err, fmt.Errorf("updating username was NOT successful: delete newly created user: %v, failed: reason unknown", newUsername))
		}
		return false, err
	}
	if !ok {
		return false, fmt.Errorf("updating username was NOT successful: delete user: %v, failed: reason unknown", currentUsername)
	}
	return ok, nil
}
@jacobweinstock jacobweinstock added the enhancement New feature or request label Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant