Skip to content

Commit

Permalink
Custom payload for user creation for HP
Browse files Browse the repository at this point in the history
  • Loading branch information
5kt committed Dec 14, 2023
1 parent f2ffeaf commit 0106fa1
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions bmc/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,25 @@ var (
userIdRegex = regexp.MustCompile(`/redfish/v1/AccountService/Accounts/([0-9]{1,2})`)
)

// TODO: add specific fields for Lenovo/Dell
type redfishUser struct {
Oem struct {
Hp struct {
LoginName string `json:"LoginName,omitempty"`
Privileges struct {
LoginPriv bool `json:"LoginPriv,omitempty"`
RemoteConsolePriv bool `json:"RemoteConsolePriv,omitempty"`
UserConfigPriv bool `json:"UserConfigPriv,omitempty"`
VirtualMediaPriv bool `json:"VirtualMediaPriv,omitempty"`
VirtualPowerAndResetPriv bool `json:"VirtualPowerAndResetPriv,omitempty"`
ILOConfigPriv bool `json:"iLOConfigPriv,omitempty"`
} `json:"Privileges,omitempty"`
} `json:"Hp,omitempty"`
} `json:"Oem,omitempty"`
UserName string `json:"UserName"`
RoleID string `json:"RoleId"`
RoleID string `json:"RoleId,omitempty"`
Password string `json:"Password"`
Enabled bool `json:"Enabled"`
Enabled bool `json:"Enabled,omitempty"`
}

func redfishConnect(ctx context.Context, host string, port int, creds Credentials) (*gofish.APIClient, error) {
Expand Down Expand Up @@ -311,7 +325,34 @@ func redfishGetFreeID(accounts []*redfish.ManagerAccount) (string, error) {
func redfishCreateUserPost(ctx context.Context, c *gofish.APIClient, creds Credentials) (string, error) {
log.Debug(ctx, "Creating user", "type", "POST", "user", creds.Username)

u := redfishUser{UserName: creds.Username, RoleID: "Administrator", Password: creds.Password, Enabled: true}
systems, err := c.Service.Systems()
if err != nil {
return "", fmt.Errorf("cannot get systems information: %w", err)
}

mnf := ""
for _, s := range systems {
mnf := s.Manufacturer
if mnf != "" {
break
}
}

u := redfishUser{UserName: creds.Username, Password: creds.Password}
// TODO: add specific code for Dell and Lenovo
if mnf == "HPE" {
u.Oem.Hp.LoginName = creds.Username
u.Oem.Hp.Privileges.LoginPriv = true
u.Oem.Hp.Privileges.RemoteConsolePriv = true
u.Oem.Hp.Privileges.UserConfigPriv = true
u.Oem.Hp.Privileges.VirtualMediaPriv = true
u.Oem.Hp.Privileges.VirtualPowerAndResetPriv = true
u.Oem.Hp.Privileges.ILOConfigPriv = true
} else {
u.RoleID = "Administrator"
u.Enabled = true
}

response, err := c.Post("/redfish/v1/AccountService/Accounts", u)
if err != nil {
return "", fmt.Errorf("cannot perform POST request: %w", err)
Expand Down

0 comments on commit 0106fa1

Please sign in to comment.