Skip to content

Refactor BMC superuser creation - #93

Draft
simcod wants to merge 8 commits into
masterfrom
refactor-superuser-check-creation
Draft

Refactor BMC superuser creation#93
simcod wants to merge 8 commits into
masterfrom
refactor-superuser-check-creation

Conversation

@simcod

@simcod simcod commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

Slightly refactors the code to check, if a password change for the BMC superuser is necessary.

Used AI-Tools ✨

  • None

@metal-robot metal-robot Bot added this to Development Jul 7, 2026
Comment thread internal/ipmi/ipmitool.go Outdated
if strings.Contains(output, "Failure: password incorrect") {
if strings.Contains(strings.ToLower(output), "password incorrect") {
// Note: this is also the case if the user does not exist yet but both cases are handled equally
return true, fmt.Errorf("password for user %s with id %s incorrect: %w change necessary", user.Name, user.Id, err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should we also remove the error here? At this point we know that password must be changed, so it's safe to conclude that this method must return true. The fact that the password is wrong alone is not an error, it's what the method checks.

This change can slightly simplify the code in metal-hammer

Comment thread internal/ipmi/ipmitool.go Outdated
}
}

return false, fmt.Errorf("failed to check if user exists: %w", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This error is a bit misleading - maybe something like "the requested user is not known to the BMC" will be more accurate? The current one sounds like the check itself failed, while in fact the check proved the requested user doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are absolutely right.

Comment thread internal/ipmi/ipmitool.go
Comment thread internal/ipmi/ipmitool.go Outdated
users = append(users, User{
ID: id,
Name: name,
ChannelPrivilegeLevel: strings.TrimSpace(fields[5]),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can fields[5] be empty? Probably not, but worth checking/noting in a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I understood, the result should contain some kind of string. In theory, it could be a wrong value, because it is basically just a string. We also verify the output of the strings.Split() operation. However as we do not really need it, I will remove ChannelPrivilegeLevel.

simcod and others added 6 commits July 15, 2026 20:56
Change the true branch return value to (true, nil) instead of a bit
misleading (true, <Error>). The former error is logged at Info level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants