Skip to content

Commit

Permalink
Add ability to create user accounts
Browse files Browse the repository at this point in the history
This adds the ability to create basic user accounts via a method call on
the AccountService. It does not currently handle things like
ActiveDirectory or LDAP integration.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis committed Apr 18, 2024
1 parent fb2a01d commit 1e61f06
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions redfish/accountservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,35 @@ func (accountservice *AccountService) Accounts() ([]*ManagerAccount, error) {
func (accountservice *AccountService) Roles() ([]*Role, error) {
return ListReferencedRoles(accountservice.GetClient(), accountservice.roles)
}

// CreateAccount creates a new Redfish user account.
//
// `userName` is the new username to use.
//
// `password` is the initial password, must conform to configured password requirements.
//
// `roleID` is the role to assign to the user, typically one of `Administrator`, `Operator`, or `ReadOnly`.
//
// Returns the created user account that can then be updated for things like setting `passwordChangeRequried`, etc.
func (accountservice *AccountService) CreateAccount(userName, password, roleID string) (*ManagerAccount, error) {
t := struct {
UserName string
Enabled bool
Password string
RoleID string `json:"RoleId"`
}{
UserName: userName,
Enabled: true,
Password: password,
RoleID: roleID,
}
resp, err := accountservice.PostWithResponse(accountservice.accounts, t)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var result ManagerAccount
err = json.NewDecoder(resp.Body).Decode(&result)
return &result, err
}

0 comments on commit 1e61f06

Please sign in to comment.